You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/03/16 10:06:18 UTC
[29/50] [abbrv] git commit: [OLINGO-141] Adapt JPA Processor - Remove
implementation for deprecated Function Import annotation
[OLINGO-141] Adapt JPA Processor - Remove implementation for deprecated
Function Import annotation
Signed-off-by: Chandan V A <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/c664475b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/c664475b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/c664475b
Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: c664475bd305c30fd33e216004a2185ea4ac0ed5
Parents: 57557b1
Author: Chandan V A <ch...@sap.com>
Authored: Tue Feb 18 16:19:34 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Tue Feb 18 16:22:21 2014 +0530
----------------------------------------------------------------------
.../core/ODataJPAResponseBuilderDefault.java | 4 +-
.../core/model/JPAEdmFunctionImport.java | 17 +-
.../model/_JPAEdmFunctionImportBuilder.java | 237 --------
.../core/mock/model/JPACustomProcessorMock.java | 10 +
.../model/JPACustomProcessorNegativeMock.java | 70 +++
.../mock/model/_JPACustomProcessorMock.java | 77 ---
.../model/_JPACustomProcessorNegativeMock.java | 70 ---
.../core/model/JPAEdmFunctionImportTest.java | 67 ++-
.../core/model/_JPAEdmFunctionImportTest.java | 570 -------------------
.../extension/_SalesOrderHeaderProcessor.java | 127 -----
10 files changed, 139 insertions(+), 1110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
index c49d017..4277d76 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
@@ -61,6 +61,7 @@ import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAExpandCallBack;
@@ -488,7 +489,8 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
PathInfo pathInfo = context.getPathInfo();
entityFeedPropertiesBuilder =
EntityProviderWriteProperties.serviceRoot(pathInfo.getServiceRoot());
- if (odataJPAContext.getPageSize() > 0 && odataJPAContext.getPaging().getNextPage() > 0) {
+ JPAPaging paging = odataJPAContext.getPaging();
+ if (odataJPAContext.getPageSize() > 0 && paging != null && paging.getNextPage() > 0) {
String nextLink =
pathInfo.getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
nextLink = percentEncodeNextLink(nextLink);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
index d35eae0..2906121 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
@@ -76,10 +76,8 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
- @SuppressWarnings("deprecation")
- private _JPAEdmFunctionImportBuilder builderDeprecated = new _JPAEdmFunctionImportBuilder();
- @SuppressWarnings("deprecation")
+
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {
@@ -90,10 +88,6 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
jpaEdmComplexTypeView = schemaView.getJPAEdmComplexTypeView();
if (customOperations != null) {
- // Initialize deprecated Builder
- builderDeprecated.setJPAEdmComplexTypeView(jpaEdmComplexTypeView);
- builderDeprecated.setJPAEdmEntityTypeView(jpaEdmEntityTypeView);
- builderDeprecated.setSchemaView(schemaView);
for (Class<?> clazz : customOperations.keySet()) {
@@ -142,7 +136,6 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
}
}
- @SuppressWarnings("deprecation")
private FunctionImport buildFunctionImport(final Method method) throws ODataJPAModelException {
EdmFunctionImport edmAnnotationFunctionImport = method.getAnnotation(EdmFunctionImport.class);
@@ -150,14 +143,6 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
return buildEdmFunctionImport(method, edmAnnotationFunctionImport);
}
- org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation =
- method.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.FunctionImport.class);
-
- if (annotation != null) {
- FunctionImport functionImport = builderDeprecated.buildFunctionImport(method, annotation);
-
- return functionImport;
- }
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
deleted file mode 100644
index 94e7374..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.jpa.processor.core.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
-import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
-
-@Deprecated
-public final class _JPAEdmFunctionImportBuilder {
-
- private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
- private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
- private JPAEdmSchemaView schemaView;
-
- public void setJPAEdmEntityTypeView(final JPAEdmEntityTypeView jpaEdmEntityTypeView) {
- this.jpaEdmEntityTypeView = jpaEdmEntityTypeView;
- }
-
- public void setSchemaView(final JPAEdmSchemaView schemaView) {
- this.schemaView = schemaView;
- }
-
- public void setJPAEdmComplexTypeView(final JPAEdmComplexTypeView jpaEdmComplexTypeView) {
- this.jpaEdmComplexTypeView = jpaEdmComplexTypeView;
- }
-
- public FunctionImport buildFunctionImport(final Method method,
- final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
-
- if (method != null && annotation != null && annotation.returnType() != ReturnType.NONE) {
- FunctionImport functionImport = new FunctionImport();
-
- if (annotation.name().equals("")) {
- functionImport.setName(method.getName());
- } else {
- functionImport.setName(annotation.name());
- }
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(method.getName());
- mapping.setJPAType(method.getDeclaringClass());
- functionImport.setMapping((Mapping) mapping);
-
- functionImport.setHttpMethod(annotation.httpMethod().name().toString());
-
- buildReturnType(functionImport, method, annotation);
- buildParameter(functionImport, method);
- return functionImport;
- }
- return null;
-
- }
-
- private void buildParameter(final FunctionImport functionImport, final Method method)
- throws ODataJPAModelException {
-
- Annotation[][] annotations = method.getParameterAnnotations();
- Class<?>[] parameterTypes = method.getParameterTypes();
- List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
- JPAEdmMapping mapping = null;
- int j = 0;
- for (Annotation[] annotationArr : annotations) {
- Class<?> parameterType = parameterTypes[j++];
-
- for (Annotation element : annotationArr) {
- if (element instanceof Parameter) {
- Parameter annotation = (Parameter) element;
- FunctionImportParameter functionImportParameter = new FunctionImportParameter();
- if (annotation.name().equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
- .getDeclaringClass().getName(), method.getName()), null);
- } else {
- functionImportParameter.setName(annotation.name());
- }
-
- functionImportParameter.setType(JPATypeConvertor.convertToEdmSimpleType(parameterType, null));
- functionImportParameter.setMode(annotation.mode().toString());
-
- Facets facets = new Facets();
- if (annotation.facets().maxLength() > 0) {
- facets.setMaxLength(annotation.facets().maxLength());
- }
- if (annotation.facets().nullable() == false) {
- facets.setNullable(false);
- } else {
- facets.setNullable(true);
- }
-
- if (annotation.facets().precision() > 0) {
- facets.setPrecision(annotation.facets().precision());
- }
- if (annotation.facets().scale() >= 0) {
- facets.setScale(annotation.facets().scale());
- }
-
- functionImportParameter.setFacets(facets);
- mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(parameterType);
- functionImportParameter.setMapping((Mapping) mapping);
- funcImpList.add(functionImportParameter);
- }
- }
- }
- if (!funcImpList.isEmpty()) {
- functionImport.setParameters(funcImpList);
- }
- }
-
- private void buildReturnType(final FunctionImport functionImport, final Method method,
- final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
- org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType returnType = annotation.returnType();
- Multiplicity multiplicity = null;
-
- if (returnType != ReturnType.NONE) {
- org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
- new org.apache.olingo.odata2.api.edm.provider.ReturnType();
- multiplicity = annotation.multiplicity();
-
- if (multiplicity == Multiplicity.MANY) {
- functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
- } else {
- functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
- }
-
- if (returnType == ReturnType.ENTITY_TYPE) {
- String entitySet = annotation.entitySet();
- if (entitySet.equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
- }
- functionImport.setEntitySet(entitySet);
- }
-
- Class<?> methodReturnType = method.getReturnType();
- if (methodReturnType == null || methodReturnType.getName().equals("void")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
- .getDeclaringClass(), method.getName()), null);
- }
- switch (returnType) {
- case ENTITY_TYPE:
- EntityType edmEntityType = null;
- if (multiplicity == Multiplicity.ONE) {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
- } else if (multiplicity == Multiplicity.MANY) {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
- }
-
- if (edmEntityType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
- break;
- case SCALAR:
-
- EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
- functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
-
- break;
- case COMPLEX_TYPE:
- ComplexType complexType = null;
- if (multiplicity == Multiplicity.ONE) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(methodReturnType.getName());
- } else if (multiplicity == Multiplicity.MANY) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(getReturnTypeName(method));
- }
- if (complexType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
- break;
- default:
- break;
- }
- functionImport.setReturnType(functionReturnType);
- }
- }
-
- private String getReturnTypeName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getName();
- } catch (ClassCastException e) {
- return method.getReturnType().getName();
- }
- }
-
- private String getReturnTypeSimpleName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getSimpleName();
- } catch (ClassCastException e) {
- return method.getReturnType().getSimpleName();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
index 6f7d16e..349b88d 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
@@ -31,6 +31,7 @@ public class JPACustomProcessorMock {
public static final String className = "JPACustomProcessorMock";
public static final String edmName = "JPACustomProcessor";
+ public static final String nonJPAEmbeddableType = "JPACustomProcessorMock$JPANonComplexTestMock";
@EdmFunctionImport(name = "Method1", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
isCollection = true))
@@ -71,4 +72,13 @@ public class JPACustomProcessorMock {
return null;
}
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX,
+ isCollection = false))
+ public JPANonComplexTestMock method18() {
+ return null;
+ }
+
+ public static interface JPANonComplexTestMock {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorNegativeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorNegativeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorNegativeMock.java
new file mode 100644
index 0000000..b763ded
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorNegativeMock.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.mock.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type;
+
+public class JPACustomProcessorNegativeMock {
+
+ @EdmFunctionImport(name = "Method5", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
+ isCollection = false))
+ public List<JPACustomProcessorNegativeMock> method5() {
+ return null;
+ }
+
+ @EdmFunctionImport(entitySet = "MockSet", returnType = @ReturnType(type = Type.SIMPLE, isCollection = true))
+ public void method6() {
+ return;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE, isCollection = true), entitySet = "MockSet")
+ public JPACustomProcessorNegativeMock method8() {
+ return null;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
+ public JPACustomProcessorNegativeMock method11() {
+ return null;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
+ public JPACustomProcessorMock method12() {
+ return null;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
+ public int method13(@EdmFunctionImportParameter(name = "") final int y) {
+ return 0;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
+ public void method16(@EdmFunctionImportParameter(name = "") final int y) {
+ return;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
+ public void method17(@EdmFunctionImportParameter(name = "") final int y) {
+ return;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
deleted file mode 100644
index 1cdd158..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.jpa.processor.core.mock.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.Facets;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
-
-@Deprecated
-public class _JPACustomProcessorMock {
-
- public static final String className = "_JPACustomProcessorMock";
- public static final String edmName = "JPACustomProcessor";
-
- @FunctionImport(name = "Method1", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
- multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method1(@Parameter(name = "Param1", facets = @Facets(nullable = true,
- maxLength = 2), mode = Mode.IN) final String param1, final int param2, @Parameter(name = "Param3",
- facets = @Facets(precision = 10, scale = 2), mode = Mode.IN) final double param3) {
- return new ArrayList<_JPACustomProcessorMock>();
- }
-
- @FunctionImport(name = "Method2", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
- multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method2(
- @Parameter(facets = @Facets(maxLength = 2), name = "Param2") final String param2) {
- return new ArrayList<_JPACustomProcessorMock>();
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR)
- public int method3(@Parameter(name = "Param3") final String param3) {
- return 0;
- }
-
- @FunctionImport(returnType = ReturnType.NONE)
- public void method4() {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorMock method7() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorMock method9() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method10() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
deleted file mode 100644
index a727d5b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.jpa.processor.core.mock.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-
-@Deprecated
-public class _JPACustomProcessorNegativeMock {
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorNegativeMock> method5() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
- public void method6() {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
- public _JPACustomProcessorNegativeMock method8() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorNegativeMock method11() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public JPACustomProcessorMock method12() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public int method13(@Parameter(name = "") final int y) {
- return 0;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public void method16(@Parameter(name = "") final int y) {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public void method17(@Parameter(name = "") final int y) {
- return;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
index db23397..b30a504 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +36,7 @@ import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
import org.apache.olingo.odata2.api.edm.provider.Mapping;
import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
@@ -46,12 +48,12 @@ import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPACustomProcessorMock;
-import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorNegativeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPACustomProcessorNegativeMock;
import org.junit.Before;
import org.junit.Test;
public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
- private static final int METHOD_COUNT = 6;
+ private static final int METHOD_COUNT = 7;
private static int VARIANT = 0;
private JPAEdmFunctionImport jpaEdmfunctionImport;
@@ -177,7 +179,7 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
jpaEdmfunctionImport.getBuilder().build();
fail("Exception Expected");
} catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
} catch (ODataJPARuntimeException e) {
fail("Model Exception Expected");
}
@@ -240,7 +242,7 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
jpaEdmfunctionImport.getBuilder().build();
fail("Exception Expected");
} catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
} catch (ODataJPARuntimeException e) {
fail("Model Exception Expected");
}
@@ -441,6 +443,32 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
}
+ /**
+ * Test Case - Function Import test for ReturnType.COMPLEX where Complex type is non JPA Embeddable Type
+ *
+ */
+ @Test
+ public void testNonJPAReturnTypeComplex() {
+ VARIANT = 18;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method18");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + JPACustomProcessorMock.nonJPAEmbeddableType);
+
+ }
+
@Test
public void testNoFunctionImport() {
VARIANT = 99;
@@ -479,31 +507,33 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
} else if (VARIANT == 4) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method4" });
} else if (VARIANT == 5) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method5" });
} else if (VARIANT == 6) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method6" });
} else if (VARIANT == 7) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method7" });
} else if (VARIANT == 8) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method8" });
} else if (VARIANT == 9) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method9" });
} else if (VARIANT == 10) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method10" });
} else if (VARIANT == 11) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method11" });
} else if (VARIANT == 12) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method12" });
} else if (VARIANT == 13) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method13" });
} else if (VARIANT == 14) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method1" });
} else if (VARIANT == 15) {
customOperations.put(JPACustomProcessorMock.class, new String[] { "method3" });
} else if (VARIANT == 16) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method16" });
} else if (VARIANT == 17) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
+ customOperations.put(JPACustomProcessorNegativeMock.class, new String[] { "method17" });
+ } else if (VARIANT == 18) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method18" });
} else {
return null;
}
@@ -512,6 +542,19 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
}
@Override
+ public Schema getEdmSchema() {
+ Schema schema = new Schema();
+ ComplexType complexType = new ComplexType();
+ complexType.setName(JPACustomProcessorMock.nonJPAEmbeddableType);
+ List<ComplexType> list = new ArrayList<ComplexType>();
+ list.add(complexType);
+ schema.setComplexTypes(list);
+
+ return schema;
+
+ }
+
+ @Override
public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
deleted file mode 100644
index e8f3e7b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
+++ /dev/null
@@ -1,570 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.jpa.processor.core.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
-import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorMock;
-import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorNegativeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-@Deprecated
-public class _JPAEdmFunctionImportTest extends JPAEdmTestModelView {
- private static final int METHOD_COUNT = 6;
- private static int VARIANT = 0;
- private JPAEdmFunctionImport jpaEdmfunctionImport;
-
- @Before
- public void setup() {
- jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
- }
-
- /**
- * Test Case - Function Import Basic test - Positive Case
- */
- @Test
- public void testFunctionImportBasic() {
- VARIANT = 0;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
- for (FunctionImport functionImport : functionImportList) {
- assertEquals(functionImport.getName(), "Method1");
- assertNotNull(functionImport.getMapping());
- Mapping mapping = new Mapping();
- mapping.setInternalName("method1");
-
- assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
-
- List<FunctionImportParameter> funcImpList = functionImport.getParameters();
- assertEquals(2, funcImpList.size());
- assertEquals("Param1", funcImpList.get(0).getName());
- assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
- assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode());
-
- assertEquals("Param3", funcImpList.get(1).getName());
- assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
- assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode());
-
- }
-
- }
-
- /**
- * Test Case - Enable a method that does not exists
- */
- @Test
- public void testFunctionImportNoSuchMethod() {
- VARIANT = 1;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Enable all annotated methods in a class as function imports
- */
- @Test
- public void testFunctionImportAllMethods() {
- VARIANT = 2;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(METHOD_COUNT, functionImportList.size());
-
- }
-
- /**
- * Test Case - Function Import with no names. Default name is Java method
- * name.
- */
- @Test
- public void testFunctionImportNoName() {
- VARIANT = 3;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method3");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
- }
-
- /**
- * Test Case - Function Import with No return type defined - Negative case
- */
- @Test
- public void testNoReturnType() {
- VARIANT = 4;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Function Import with return type as Entity and Multiplicity
- * as Many but no Entity set defined. --> Negative Case
- */
- @Test
- public void testNoEntitySet() {
- VARIANT = 5;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import with return type as Entity Type but method
- * has returns void. --> Negative Case
- */
- @Test
- public void testNoReturnTypeButAnnotated() {
- VARIANT = 6;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type with Multiplicity
- * as ONE. -->Positive Case
- */
- @Test
- public void testFunctionImportEntityTypeSingleReturn() {
- VARIANT = 7;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method7");
- assertNotNull(functionImport.getMapping());
- JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
- assertEquals(_JPACustomProcessorMock.class, mapping.getJPAType());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type that is not found
- * in JPA Model
- */
- @Test
- public void testFunctionImportEntityTypeInvalid() {
- VARIANT = 8;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type
- */
- @Test
- public void testFunctionImportComplexType() {
- VARIANT = 9;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method9");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type with multiplicity
- * Many
- */
- @Test
- public void testFunctionImportComplexTypeMany() {
- VARIANT = 10;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method10");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns an Complex Type that is not
- * found in JPA Model
- */
- @Test
- public void testFunctionImportComplexTypeInvalid() {
- VARIANT = 11;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns an scalar Type that is not valid
- */
- @Test
- public void testFunctionImportScalarTypeInvalid() {
- VARIANT = 12;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that takes a parameter with no name
- */
- @Test
- public void testFunctionImportParamNoName() {
- VARIANT = 13;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for facets
- */
- @Test
- public void testFunctionImportParamFacets() {
- VARIANT = 14;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertEquals(2, facets.getMaxLength().intValue());
- assertEquals(true, facets.isNullable());
-
- facets = funcImpParamList.get(1).getFacets();
- assertNotNull(facets);
- assertEquals(false, facets.isNullable());
- assertEquals(10, facets.getPrecision().intValue());
- assertEquals(2, facets.getScale().intValue());
-
- }
-
- /**
- * Test Case - Function Import test for default facets
- */
- @Test
- public void testFunctionImportParamFacetsDefault() {
- VARIANT = 15;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertNull(facets.getMaxLength());
- assertEquals(false, facets.isNullable());
- assertNull(facets.getPrecision());
- assertNull(facets.getScale());
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.SCALAR but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeScalar() {
- VARIANT = 16;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.COMPLEX but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeComplex() {
- VARIANT = 17;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- @Test
- public void testNoFunctionImport() {
- VARIANT = 99;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
-
- JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
- JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public HashMap<Class<?>, String[]> getRegisteredOperations() {
-
- HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
-
- if (VARIANT == 0) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 1) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "XYX" });
- } else if (VARIANT == 2) {
- customOperations.put(_JPACustomProcessorMock.class, null);
- } else if (VARIANT == 3) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 4) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method4" });
- } else if (VARIANT == 5) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
- } else if (VARIANT == 6) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
- } else if (VARIANT == 7) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method7" });
- } else if (VARIANT == 8) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
- } else if (VARIANT == 9) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method9" });
- } else if (VARIANT == 10) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method10" });
- } else if (VARIANT == 11) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
- } else if (VARIANT == 12) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
- } else if (VARIANT == 13) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
- } else if (VARIANT == 14) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 15) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 16) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
- } else if (VARIANT == 17) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
- } else {
- return null;
- }
-
- return customOperations;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return this;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String arg0) {
- if (arg0.equals(_JPACustomProcessorMock.class.getSimpleName())) {
- return new EntityType().setName(_JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String arg0) {
- if (arg0.equals(_JPACustomProcessorMock.class.getName())) {
- return new ComplexType().setName(_JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public String getpUnitName() {
- return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
- }
-
- private void build() {
- try {
- jpaEdmfunctionImport.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c664475b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/_SalesOrderHeaderProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/_SalesOrderHeaderProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/_SalesOrderHeaderProcessor.java
deleted file mode 100644
index bfe0e89..0000000
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/_SalesOrderHeaderProcessor.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.jpa.processor.ref.extension;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
-
-import org.apache.olingo.odata2.api.annotation.edm.Facets;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
-import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod;
-import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.jpa.processor.ref.model.Address;
-import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader;
-import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderItem;
-
-@Deprecated
-public class _SalesOrderHeaderProcessor {
-
- private EntityManager em;
-
- public _SalesOrderHeaderProcessor() {
- em = Persistence.createEntityManagerFactory("salesorderprocessing")
- .createEntityManager();
- }
-
- @SuppressWarnings("unchecked")
- @FunctionImport(name = "FindAllSalesOrders", entitySet = "SalesOrders", returnType = ReturnType.ENTITY_TYPE,
- multiplicity = Multiplicity.MANY)
- public List<SalesOrderHeader> findAllSalesOrders(
- @Parameter(name = "DeliveryStatusCode", facets = @Facets(maxLength = 2)) final String status) {
-
- Query q = em
- .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.deliveryStatus = '"
- + status + "'");
- List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
- .getResultList();
- return soList;
- }
-
- @FunctionImport(name = "CheckATP", returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE,
- httpMethod = @HttpMethod(name = Name.GET))
- public boolean checkATP(
- @Parameter(name = "SoID", facets = @Facets(nullable = false), mode = Mode.IN) final Long soID,
- @Parameter(name = "LiId", facets = @Facets(nullable = false), mode = Mode.IN) final Long lineItemID) {
- if (soID == 2L) {
- return false;
- } else {
- return true;
- }
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "SalesOrders")
- public SalesOrderHeader calculateNetAmount(
- @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID)
- throws ODataException {
-
- if (soID <= 0L) {
- throw new ODataException("Invalid SoID");
- }
-
- Query q = em
- .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
- + soID + "l");
- if (q.getResultList().isEmpty()) {
- return null;
- }
- SalesOrderHeader so = (SalesOrderHeader) q.getResultList().get(0);
- double amount = 0;
- for (SalesOrderItem soi : so.getSalesOrderItem()) {
- amount = amount
- + (soi.getAmount() * soi.getDiscount() * soi.getQuantity());
- }
- so.setNetAmount(amount);
- return so;
- }
-
- @SuppressWarnings("unchecked")
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE)
- public Address getAddress(
- @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) {
- Query q = em
- .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
- + soID + "l");
- List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
- .getResultList();
- if (!soList.isEmpty()) {
- return soList.get(0).getCustomer().getAddress();
- } else {
- return null;
- }
- }
-
- /*
- * This method will not be transformed into Function Import Function Import
- * with return type as void is not supported yet.
- */
- @FunctionImport(returnType = ReturnType.NONE)
- public void process(
- @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) {
- return;
- }
-
-}