http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b155bda5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java index 095d7e1..fbe6206 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java @@ -1,403 +1,403 @@ -/******************************************************************************* - * 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.data; - -import java.sql.Blob; -import java.sql.Clob; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.UUID; - -import org.apache.olingo.odata2.api.edm.EdmAssociation; -import org.apache.olingo.odata2.api.edm.EdmAssociationEnd; -import org.apache.olingo.odata2.api.edm.EdmComplexType; -import org.apache.olingo.odata2.api.edm.EdmEntityContainer; -import org.apache.olingo.odata2.api.edm.EdmEntitySet; -import org.apache.olingo.odata2.api.edm.EdmEntityType; -import org.apache.olingo.odata2.api.edm.EdmException; -import org.apache.olingo.odata2.api.edm.EdmMapping; -import org.apache.olingo.odata2.api.edm.EdmMultiplicity; -import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; -import org.apache.olingo.odata2.api.edm.EdmProperty; -import org.apache.olingo.odata2.api.edm.EdmSimpleType; -import org.apache.olingo.odata2.api.edm.EdmTypeKind; -import org.apache.olingo.odata2.api.edm.provider.Mapping; -import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2; -import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl; -import org.easymock.EasyMock; - -public class EdmMockUtilV2 { - - public static interface JPAEdmMappingMock extends JPAEdmMapping, EdmMapping { - - } - - public static EdmEntityContainer mockEdmEntityContainer(final String entityName) throws EdmException { - EdmEntityContainer entityContainer = EasyMock.createMock(EdmEntityContainer.class); - entityContainer = EasyMock.createMock(EdmEntityContainer.class); - EasyMock.expect(entityContainer.getEntitySet(JPATypeMock.ENTITY_NAME)).andReturn( - mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false)); - EasyMock.expect(entityContainer.getFunctionImport(JPATypeMock.ENTITY_NAME)).andReturn(null); - EasyMock.expect(entityContainer.getEntitySet("JPATypeMockInvalid")).andReturn(null); - EasyMock.expect(entityContainer.getFunctionImport("JPATypeMockInvalid")).andReturn(null); - EasyMock.replay(entityContainer); - - return entityContainer; - } - - public static EdmEntityType mockEdmEntityType(final String entityName, final boolean withComplexType) - throws EdmException { - - EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class); - EasyMock.expect(entityType.getName()).andReturn(entityName).anyTimes(); - EasyMock.expect(entityType.getKeyPropertyNames()).andReturn(mockSimpleKeyPropertyNames(entityName)); - if (withComplexType == false) { - EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNames(entityName)).anyTimes(); - } else { - EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNamesWithComplexType(entityName)).anyTimes(); - } - - EasyMock.expect(entityType.getNavigationPropertyNames()).andReturn(mockNavigationPropertyNames(entityName)) - .anyTimes(); - EasyMock.expect(entityType.getKind()).andReturn(EdmTypeKind.ENTITY); - EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, null, null)); - EasyMock.expect(entityType.getKeyProperties()).andReturn(mockKeyProperties(entityName)).anyTimes(); - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MINT)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MSTRING)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MSTRING)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MDATETIME)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MDATETIME)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MBLOB)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MBLOB)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_CLOB)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_CLOB)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MC)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MC)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCARRAY)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCARRAY)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCHAR)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCHAR)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCHARARRAY)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCHARARRAY)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).andReturn( - mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn( - mockEdmNavigationProperty(JPATypeMock.NAVIGATION_PROPERTY_X, EdmMultiplicity.ONE)).anyTimes(); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MLONG)).andReturn( - mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MLONG)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).andReturn( - mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).andReturn( - mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).anyTimes(); - EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).andReturn( - mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).anyTimes(); - } - EasyMock.replay(entityType); - return entityType; - } - - public static List<EdmProperty> mockKeyProperties(final String entityName) throws EdmException { - List<EdmProperty> edmProperties = new ArrayList<EdmProperty>(); - edmProperties.add(mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)); - - return edmProperties; - } - - public static List<String> mockNavigationPropertyNames(final String entityName) { - List<String> propertyNames = new ArrayList<String>(); - propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_X); - propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_XS); - return propertyNames; - } - - public static List<String> mockSimpleKeyPropertyNames(final String entityName) { - List<String> keyPropertyNames = new ArrayList<String>(); - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - keyPropertyNames.add(JPATypeMock.PROPERTY_NAME_MINT); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - keyPropertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG); - } - - return keyPropertyNames; - } - - public static List<String> mockPropertyNames(final String entityName) { - List<String> propertyNames = new ArrayList<String>(); - - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - propertyNames.add(JPATypeMock.PROPERTY_NAME_MINT); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MDATETIME); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MSTRING); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MBLOB); - propertyNames.add(JPATypeMock.PROPERTY_NAME_CLOB); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MC); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MCARRAY); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHAR); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHARARRAY); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG); - propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTE); - propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY); - propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE); - } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { - propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT); - propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE); - } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { - propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT); - propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID); - } - - return propertyNames; - } - - public static List<String> mockPropertyNamesWithComplexType(final String entityName) { - List<String> propertyNames = mockPropertyNames(entityName); - propertyNames.add(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE); - - return propertyNames; - - } - - public static EdmAssociationEnd mockEdmAssociatioEnd(final String navigationPropertyName, final String role) - throws EdmException { - EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class); - EasyMock.expect(associationEnd.getMultiplicity()).andReturn(EdmMultiplicity.ONE); - EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class); - EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping("JPARelatedTypeMock", null, null)); - EasyMock.replay(entityType); - - EasyMock.expect(associationEnd.getEntityType()).andReturn(entityType); - EasyMock.replay(associationEnd); - return associationEnd; - } - - public static EdmAssociation mockEdmAssociation(final String navigationPropertyName) throws EdmException { - EdmAssociation edmAssociation = EasyMock.createMock(EdmAssociation.class); - EasyMock.expect(edmAssociation.getEnd("TO")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "TO")); - EasyMock.expect(edmAssociation.getEnd("FROM")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "FROM")); - EasyMock.replay(edmAssociation); - return edmAssociation; - } - - public static EdmEntitySet mockEdmEntitySet(final String entityName, final boolean withComplexType) - throws EdmException { - EdmEntitySet entitySet = null; - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - entitySet = EasyMock.createMock(EdmEntitySet.class); - EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes(); - EasyMock.expect(entitySet.getRelatedEntitySet(EasyMock.isA(EdmNavigationProperty.class))).andReturn( - mockEdmEntitySet(JPARelatedTypeMock.ENTITY_NAME, false)).anyTimes(); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - entitySet = EasyMock.createMock(EdmEntitySet.class); - EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes(); - } - - EasyMock.replay(entitySet); - return entitySet; - } - - public static EdmNavigationProperty mockEdmNavigationProperty(final String navigationPropertyName, - final EdmMultiplicity multiplicity) throws EdmException { - - EdmEntityType edmEntityType = mockEdmEntityType(JPARelatedTypeMock.ENTITY_NAME, false); - - EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class); - EasyMock.expect(navigationProperty.getType()).andReturn(edmEntityType).anyTimes(); - EasyMock.expect(navigationProperty.getMultiplicity()).andReturn(multiplicity); - EasyMock.expect(navigationProperty.getMapping()).andReturn( - (EdmMapping) mockEdmMapping(null, null, navigationPropertyName)).anyTimes(); - EasyMock.expect(navigationProperty.getToRole()).andReturn("TO"); - EasyMock.expect(navigationProperty.getRelationship()).andReturn(mockEdmAssociation(navigationPropertyName)); - if (multiplicity.equals(EdmMultiplicity.ONE)) { - EasyMock.expect(navigationProperty.getName()).andReturn(JPATypeMock.NAVIGATION_PROPERTY_X).anyTimes(); - } - - EasyMock.replay(navigationProperty); - - return navigationProperty; - } - - public static EdmProperty mockEdmProperty(final String entityName, final String propertyName) throws EdmException { - EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); - - if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_CLOB) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MC) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY) || - propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT) || - propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT) || - propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID) || - propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG) || - propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE) || - propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE) || - propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) { - - EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class); - EasyMock.expect(edmProperty.getType()).andReturn(edmType).anyTimes(); - EasyMock.expect(edmType.getKind()).andReturn(EdmTypeKind.SIMPLE).anyTimes(); - if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MC) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY)) { - EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(String.class).anyTimes(); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB)) { - EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(Blob.class).anyTimes(); - } else { - EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(Integer.class).anyTimes(); - } - - EasyMock.expect(edmType.isCompatible(EasyMock.isA(EdmSimpleType.class))).andReturn(true).anyTimes(); - EasyMock.replay(edmType); - EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes(); - EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, propertyName, null)) - .anyTimes(); - - } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE) || - propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { - EdmComplexType complexType = mockComplexType(propertyName); - - EasyMock.expect(edmProperty.getType()).andReturn(complexType).anyTimes(); - EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes(); - EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(null, propertyName, null)) - .anyTimes(); - - } - - EasyMock.replay(edmProperty); - return edmProperty; - } - - public static EdmComplexType mockComplexType(final String complexPropertyName) throws EdmException { - - String complexTypeName = null; - if (complexPropertyName.equals(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) { - complexTypeName = JPATypeEmbeddableMock2.ENTITY_NAME; - } else if (complexPropertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { - complexTypeName = JPATypeEmbeddableMock.ENTITY_NAME; - } - - EdmComplexType edmComplexType = EasyMock.createMock(EdmComplexType.class); - EasyMock.expect(edmComplexType.getKind()).andReturn(EdmTypeKind.COMPLEX); - EasyMock.expect(edmComplexType.getPropertyNames()).andReturn(mockPropertyNames(complexTypeName)).anyTimes(); - EasyMock.expect(edmComplexType.getMapping()).andReturn((EdmMapping) mockEdmMapping(complexTypeName, null, null)); - - if (complexTypeName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { - EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).andReturn( - mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).anyTimes(); - EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).andReturn( - mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).anyTimes(); - } else if (complexTypeName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { - EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).andReturn( - mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).anyTimes(); - EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).andReturn( - mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).anyTimes(); - } - - EasyMock.replay(edmComplexType); - return edmComplexType; - } - - public static JPAEdmMapping mockEdmMapping(final String entityName, final String propertyName, - final String navigationPropertyName) { - JPAEdmMapping mapping = new JPAEdmMappingImpl(); - - if (propertyName == null && entityName != null) { - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - mapping.setJPAType(JPATypeMock.class); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - mapping.setJPAType(JPARelatedTypeMock.class); - } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { - mapping.setJPAType(JPATypeEmbeddableMock.class); - } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { - mapping.setJPAType(JPATypeEmbeddableMock2.class); - } - } else if (entityName == null && navigationPropertyName != null) { - mapping.setJPAType(JPARelatedTypeMock.class); - mapping.setJPAColumnName(JPATypeMock.NAVIGATION_PROPERTY_X); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT)) { - mapping.setJPAType(int.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MINT); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING)) { - mapping.setJPAType(String.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MSTRING); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB)) { - mapping.setJPAType(Blob.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MBLOB); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_CLOB)) { - mapping.setJPAType(Clob.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_CLOB); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MC)) { - mapping.setJPAType(char.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MC); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY)) { - mapping.setJPAType(char[].class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCARRAY); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR)) { - mapping.setJPAType(Character.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCHAR); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY)) { - mapping.setJPAType(Character[].class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCHARARRAY); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME)) { - mapping.setJPAType(Calendar.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MDATETIME); - } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG)) { - mapping.setJPAType(long.class); - ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MLONG); - } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)) { - mapping.setJPAType(double.class); - ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE); - } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)) { - mapping.setJPAType(byte.class); - ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTE); - } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) { - mapping.setJPAType(byte[].class); - ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY); - } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)) { - mapping.setJPAType(Short.TYPE); - ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT); - } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)) { - mapping.setJPAType(Float.TYPE); - ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT); - } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)) { - mapping.setJPAType(UUID.class); - ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID); - } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) { - mapping.setJPAType(JPATypeEmbeddableMock2.class); - ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE); - } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { - mapping.setJPAType(JPATypeEmbeddableMock.class); - ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE); - } - return mapping; - } -} +/******************************************************************************* + * 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.data; + +import java.sql.Blob; +import java.sql.Clob; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.UUID; + +import org.apache.olingo.odata2.api.edm.EdmAssociation; +import org.apache.olingo.odata2.api.edm.EdmAssociationEnd; +import org.apache.olingo.odata2.api.edm.EdmComplexType; +import org.apache.olingo.odata2.api.edm.EdmEntityContainer; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmMapping; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleType; +import org.apache.olingo.odata2.api.edm.EdmTypeKind; +import org.apache.olingo.odata2.api.edm.provider.Mapping; +import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2; +import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl; +import org.easymock.EasyMock; + +public class EdmMockUtilV2 { + + public static interface JPAEdmMappingMock extends JPAEdmMapping, EdmMapping { + + } + + public static EdmEntityContainer mockEdmEntityContainer(final String entityName) throws EdmException { + EdmEntityContainer entityContainer = EasyMock.createMock(EdmEntityContainer.class); + entityContainer = EasyMock.createMock(EdmEntityContainer.class); + EasyMock.expect(entityContainer.getEntitySet(JPATypeMock.ENTITY_NAME)).andReturn( + mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false)); + EasyMock.expect(entityContainer.getFunctionImport(JPATypeMock.ENTITY_NAME)).andReturn(null); + EasyMock.expect(entityContainer.getEntitySet("JPATypeMockInvalid")).andReturn(null); + EasyMock.expect(entityContainer.getFunctionImport("JPATypeMockInvalid")).andReturn(null); + EasyMock.replay(entityContainer); + + return entityContainer; + } + + public static EdmEntityType mockEdmEntityType(final String entityName, final boolean withComplexType) + throws EdmException { + + EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class); + EasyMock.expect(entityType.getName()).andReturn(entityName).anyTimes(); + EasyMock.expect(entityType.getKeyPropertyNames()).andReturn(mockSimpleKeyPropertyNames(entityName)); + if (withComplexType == false) { + EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNames(entityName)).anyTimes(); + } else { + EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNamesWithComplexType(entityName)).anyTimes(); + } + + EasyMock.expect(entityType.getNavigationPropertyNames()).andReturn(mockNavigationPropertyNames(entityName)) + .anyTimes(); + EasyMock.expect(entityType.getKind()).andReturn(EdmTypeKind.ENTITY); + EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, null, null)); + EasyMock.expect(entityType.getKeyProperties()).andReturn(mockKeyProperties(entityName)).anyTimes(); + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MINT)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MSTRING)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MSTRING)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MDATETIME)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MDATETIME)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MBLOB)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MBLOB)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_CLOB)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_CLOB)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MC)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MC)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCARRAY)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCARRAY)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCHAR)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCHAR)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCHARARRAY)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCHARARRAY)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).andReturn( + mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn( + mockEdmNavigationProperty(JPATypeMock.NAVIGATION_PROPERTY_X, EdmMultiplicity.ONE)).anyTimes(); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MLONG)).andReturn( + mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MLONG)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).andReturn( + mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).andReturn( + mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).anyTimes(); + EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).andReturn( + mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).anyTimes(); + } + EasyMock.replay(entityType); + return entityType; + } + + public static List<EdmProperty> mockKeyProperties(final String entityName) throws EdmException { + List<EdmProperty> edmProperties = new ArrayList<EdmProperty>(); + edmProperties.add(mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)); + + return edmProperties; + } + + public static List<String> mockNavigationPropertyNames(final String entityName) { + List<String> propertyNames = new ArrayList<String>(); + propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_X); + propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_XS); + return propertyNames; + } + + public static List<String> mockSimpleKeyPropertyNames(final String entityName) { + List<String> keyPropertyNames = new ArrayList<String>(); + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + keyPropertyNames.add(JPATypeMock.PROPERTY_NAME_MINT); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + keyPropertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG); + } + + return keyPropertyNames; + } + + public static List<String> mockPropertyNames(final String entityName) { + List<String> propertyNames = new ArrayList<String>(); + + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + propertyNames.add(JPATypeMock.PROPERTY_NAME_MINT); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MDATETIME); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MSTRING); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MBLOB); + propertyNames.add(JPATypeMock.PROPERTY_NAME_CLOB); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MC); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MCARRAY); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHAR); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHARARRAY); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG); + propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTE); + propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY); + propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE); + } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { + propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT); + propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE); + } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { + propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT); + propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID); + } + + return propertyNames; + } + + public static List<String> mockPropertyNamesWithComplexType(final String entityName) { + List<String> propertyNames = mockPropertyNames(entityName); + propertyNames.add(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE); + + return propertyNames; + + } + + public static EdmAssociationEnd mockEdmAssociatioEnd(final String navigationPropertyName, final String role) + throws EdmException { + EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class); + EasyMock.expect(associationEnd.getMultiplicity()).andReturn(EdmMultiplicity.ONE); + EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class); + EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping("JPARelatedTypeMock", null, null)); + EasyMock.replay(entityType); + + EasyMock.expect(associationEnd.getEntityType()).andReturn(entityType); + EasyMock.replay(associationEnd); + return associationEnd; + } + + public static EdmAssociation mockEdmAssociation(final String navigationPropertyName) throws EdmException { + EdmAssociation edmAssociation = EasyMock.createMock(EdmAssociation.class); + EasyMock.expect(edmAssociation.getEnd("TO")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "TO")); + EasyMock.expect(edmAssociation.getEnd("FROM")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "FROM")); + EasyMock.replay(edmAssociation); + return edmAssociation; + } + + public static EdmEntitySet mockEdmEntitySet(final String entityName, final boolean withComplexType) + throws EdmException { + EdmEntitySet entitySet = null; + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + entitySet = EasyMock.createMock(EdmEntitySet.class); + EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes(); + EasyMock.expect(entitySet.getRelatedEntitySet(EasyMock.isA(EdmNavigationProperty.class))).andReturn( + mockEdmEntitySet(JPARelatedTypeMock.ENTITY_NAME, false)).anyTimes(); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + entitySet = EasyMock.createMock(EdmEntitySet.class); + EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes(); + } + + EasyMock.replay(entitySet); + return entitySet; + } + + public static EdmNavigationProperty mockEdmNavigationProperty(final String navigationPropertyName, + final EdmMultiplicity multiplicity) throws EdmException { + + EdmEntityType edmEntityType = mockEdmEntityType(JPARelatedTypeMock.ENTITY_NAME, false); + + EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class); + EasyMock.expect(navigationProperty.getType()).andReturn(edmEntityType).anyTimes(); + EasyMock.expect(navigationProperty.getMultiplicity()).andReturn(multiplicity); + EasyMock.expect(navigationProperty.getMapping()).andReturn( + (EdmMapping) mockEdmMapping(null, null, navigationPropertyName)).anyTimes(); + EasyMock.expect(navigationProperty.getToRole()).andReturn("TO"); + EasyMock.expect(navigationProperty.getRelationship()).andReturn(mockEdmAssociation(navigationPropertyName)); + if (multiplicity.equals(EdmMultiplicity.ONE)) { + EasyMock.expect(navigationProperty.getName()).andReturn(JPATypeMock.NAVIGATION_PROPERTY_X).anyTimes(); + } + + EasyMock.replay(navigationProperty); + + return navigationProperty; + } + + public static EdmProperty mockEdmProperty(final String entityName, final String propertyName) throws EdmException { + EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); + + if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_CLOB) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MC) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY) || + propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT) || + propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT) || + propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID) || + propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG) || + propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE) || + propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE) || + propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) { + + EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class); + EasyMock.expect(edmProperty.getType()).andReturn(edmType).anyTimes(); + EasyMock.expect(edmType.getKind()).andReturn(EdmTypeKind.SIMPLE).anyTimes(); + if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MC) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY)) { + EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(String.class).anyTimes(); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB)) { + EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(Blob.class).anyTimes(); + } else { + EasyMock.<Class<?>> expect(edmType.getDefaultType()).andReturn(Integer.class).anyTimes(); + } + + EasyMock.expect(edmType.isCompatible(EasyMock.isA(EdmSimpleType.class))).andReturn(true).anyTimes(); + EasyMock.replay(edmType); + EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes(); + EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, propertyName, null)) + .anyTimes(); + + } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE) || + propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { + EdmComplexType complexType = mockComplexType(propertyName); + + EasyMock.expect(edmProperty.getType()).andReturn(complexType).anyTimes(); + EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes(); + EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(null, propertyName, null)) + .anyTimes(); + + } + + EasyMock.replay(edmProperty); + return edmProperty; + } + + public static EdmComplexType mockComplexType(final String complexPropertyName) throws EdmException { + + String complexTypeName = null; + if (complexPropertyName.equals(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) { + complexTypeName = JPATypeEmbeddableMock2.ENTITY_NAME; + } else if (complexPropertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { + complexTypeName = JPATypeEmbeddableMock.ENTITY_NAME; + } + + EdmComplexType edmComplexType = EasyMock.createMock(EdmComplexType.class); + EasyMock.expect(edmComplexType.getKind()).andReturn(EdmTypeKind.COMPLEX); + EasyMock.expect(edmComplexType.getPropertyNames()).andReturn(mockPropertyNames(complexTypeName)).anyTimes(); + EasyMock.expect(edmComplexType.getMapping()).andReturn((EdmMapping) mockEdmMapping(complexTypeName, null, null)); + + if (complexTypeName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { + EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).andReturn( + mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).anyTimes(); + EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).andReturn( + mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).anyTimes(); + } else if (complexTypeName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { + EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).andReturn( + mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).anyTimes(); + EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).andReturn( + mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).anyTimes(); + } + + EasyMock.replay(edmComplexType); + return edmComplexType; + } + + public static JPAEdmMapping mockEdmMapping(final String entityName, final String propertyName, + final String navigationPropertyName) { + JPAEdmMapping mapping = new JPAEdmMappingImpl(); + + if (propertyName == null && entityName != null) { + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + mapping.setJPAType(JPATypeMock.class); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + mapping.setJPAType(JPARelatedTypeMock.class); + } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { + mapping.setJPAType(JPATypeEmbeddableMock.class); + } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { + mapping.setJPAType(JPATypeEmbeddableMock2.class); + } + } else if (entityName == null && navigationPropertyName != null) { + mapping.setJPAType(JPARelatedTypeMock.class); + mapping.setJPAColumnName(JPATypeMock.NAVIGATION_PROPERTY_X); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT)) { + mapping.setJPAType(int.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MINT); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING)) { + mapping.setJPAType(String.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MSTRING); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB)) { + mapping.setJPAType(Blob.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MBLOB); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_CLOB)) { + mapping.setJPAType(Clob.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_CLOB); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MC)) { + mapping.setJPAType(char.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MC); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY)) { + mapping.setJPAType(char[].class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCARRAY); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR)) { + mapping.setJPAType(Character.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCHAR); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHARARRAY)) { + mapping.setJPAType(Character[].class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCHARARRAY); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME)) { + mapping.setJPAType(Calendar.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MDATETIME); + } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG)) { + mapping.setJPAType(long.class); + ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MLONG); + } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)) { + mapping.setJPAType(double.class); + ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE); + } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)) { + mapping.setJPAType(byte.class); + ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTE); + } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) { + mapping.setJPAType(byte[].class); + ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY); + } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)) { + mapping.setJPAType(Short.TYPE); + ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT); + } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)) { + mapping.setJPAType(Float.TYPE); + ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT); + } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)) { + mapping.setJPAType(UUID.class); + ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID); + } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) { + mapping.setJPAType(JPATypeEmbeddableMock2.class); + ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE); + } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) { + mapping.setJPAType(JPATypeEmbeddableMock.class); + ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE); + } + return mapping; + } +}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b155bda5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java index dd8207b..59701fb 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java @@ -1,268 +1,268 @@ -/******************************************************************************* - * 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.data; - -import java.sql.Blob; -import java.sql.Clob; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.UUID; - -/* ========================================================================= */ -public class JPATypeMock { - - public static final String ENTITY_NAME = "JPATypeMock"; - public static final String PROPERTY_NAME_MINT = "mInt"; - public static final String PROPERTY_NAME_MSTRING = "mString"; - public static final String PROPERTY_NAME_MDATETIME = "mDateTime"; - public static final String PROPERTY_NAME_MBLOB = "mBlob"; - public static final String PROPERTY_NAME_CLOB = "mClob"; - public static final String PROPERTY_NAME_MCHAR = "mChar"; - public static final String PROPERTY_NAME_MCHARARRAY = "mCharArray"; - public static final String PROPERTY_NAME_MC = "mC"; - public static final String PROPERTY_NAME_MCARRAY = "mCArray"; - public static final String PROPERTY_NAME_MKEY = "key"; - public static final String PROPERTY_NAME_MCOMPLEXTYPE = "complexType"; - - public static final String NAVIGATION_PROPERTY_X = "mRelatedEntity"; - public static final String NAVIGATION_PROPERTY_XS = "mRelatedEntities"; - - private JPATypeEmbeddableMock key; - private JPATypeEmbeddableMock complexType; - private int mInt; - private String mString; - private Calendar mDateTime; - private Blob mBlob; - private Clob mClob; - private char mC; - private char[] mCArray; - private Character mChar; - private Character[] mCharArray; - - public Clob getMClob() { - return mClob; - } - - public void setMClob(final Clob mClob) { - this.mClob = mClob; - } - - public char getMC() { - return mC; - } - - public void setMC(final char mC) { - this.mC = mC; - } - - public char[] getMCArray() { - return mCArray; - } - - public void setMCArray(final char[] mCArray) { - this.mCArray = mCArray; - } - - public Character getMChar() { - return mChar; - } - - public void setMChar(final Character mChar) { - this.mChar = mChar; - } - - public Character[] getMCharArray() { - return mCharArray; - } - - public void setMCharArray(final Character[] mCharArray) { - this.mCharArray = mCharArray; - } - - private JPARelatedTypeMock mRelatedEntity; - private List<JPARelatedTypeMock> mRelatedEntities = new ArrayList<JPATypeMock.JPARelatedTypeMock>(); - - public String getMString() { - return mString; - } - - public void setMString(final String mString) { - this.mString = mString; - } - - public JPATypeEmbeddableMock getKey() { - return key; - } - - public void setKey(final JPATypeEmbeddableMock key) { - this.key = key; - } - - public int getMInt() { - return mInt; - } - - public void setMInt(final int mInt) { - this.mInt = mInt; - } - - public Calendar getMDateTime() { - return mDateTime; - } - - public void setMDateTime(final Calendar mDateTime) { - this.mDateTime = mDateTime; - } - - public JPARelatedTypeMock getMRelatedEntity() { - return mRelatedEntity; - } - - public void setMRelatedEntity(final JPARelatedTypeMock mRelatedEntity) { - this.mRelatedEntity = mRelatedEntity; - } - - public List<JPARelatedTypeMock> getMRelatedEntities() { - return mRelatedEntities; - } - - public void setMRelatedEntities(final List<JPARelatedTypeMock> mRelatedEntities) { - this.mRelatedEntities = mRelatedEntities; - } - - public JPATypeEmbeddableMock getComplexType() { - return complexType; - } - - public void setComplexType(final JPATypeEmbeddableMock complexType) { - this.complexType = complexType; - } - - public Blob getMBlob() { - return mBlob; - } - - public void setMBlob(final Blob mBlob) { - this.mBlob = mBlob; - } - - /* ========================================================================= */ - public static class JPATypeEmbeddableMock { - - public static final String ENTITY_NAME = "JPATypeEmbeddableMock"; - public static final String PROPERTY_NAME_MSHORT = "mShort"; - public static final String PROPERTY_NAME_MEMBEDDABLE = "mEmbeddable"; - - private short mShort; - private JPATypeEmbeddableMock2 mEmbeddable; - - public short getMShort() { - return mShort; - } - - public void setMShort(final short mShort) { - this.mShort = mShort; - } - - public JPATypeEmbeddableMock2 getMEmbeddable() { - return mEmbeddable; - } - - public void setMEmbeddable(final JPATypeEmbeddableMock2 mEmbeddable) { - this.mEmbeddable = mEmbeddable; - } - - } - - /* ========================================================================= */ - public static class JPATypeEmbeddableMock2 { - - public static final String ENTITY_NAME = "JPATypeEmbeddableMock2"; - public static final String PROPERTY_NAME_MUUID = "mUUID"; - public static final String PROPERTY_NAME_MFLOAT = "mFloat"; - - private UUID mUUID; - private float mFloat; - - public UUID getMUUID() { - return mUUID; - } - - public void setMUUID(final UUID mUUID) { - this.mUUID = mUUID; - } - - public float getMFloat() { - return mFloat; - } - - public void setMFloat(final float mFloat) { - this.mFloat = mFloat; - } - - } - - /* ========================================================================= */ - public static final class JPARelatedTypeMock { - public static final String ENTITY_NAME = "JPARelatedTypeMock"; - public static final String PROPERTY_NAME_MLONG = "mLong"; - public static final String PROPERTY_NAME_MDOUBLE = "mDouble"; - public static final String PROPERTY_NAME_MBYTE = "mByte"; - public static final String PROPERTY_NAME_MBYTEARRAY = "mByteArray"; - - private long mLong; - private double mDouble; - private byte mByte; - private byte mByteArray[]; - - public long getMLong() { - return mLong; - } - - public void setMLong(final long key) { - mLong = key; - } - - public double getMDouble() { - return mDouble; - } - - public void setMDouble(final double mDouble) { - this.mDouble = mDouble; - } - - public byte getMByte() { - return mByte; - } - - public void setMByte(final byte mByte) { - this.mByte = mByte; - } - - public byte[] getMByteArray() { - return mByteArray; - } - - public void setMByteArray(final byte mByteArray[]) { - this.mByteArray = mByteArray; - } - - } -} +/******************************************************************************* + * 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.data; + +import java.sql.Blob; +import java.sql.Clob; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.UUID; + +/* ========================================================================= */ +public class JPATypeMock { + + public static final String ENTITY_NAME = "JPATypeMock"; + public static final String PROPERTY_NAME_MINT = "mInt"; + public static final String PROPERTY_NAME_MSTRING = "mString"; + public static final String PROPERTY_NAME_MDATETIME = "mDateTime"; + public static final String PROPERTY_NAME_MBLOB = "mBlob"; + public static final String PROPERTY_NAME_CLOB = "mClob"; + public static final String PROPERTY_NAME_MCHAR = "mChar"; + public static final String PROPERTY_NAME_MCHARARRAY = "mCharArray"; + public static final String PROPERTY_NAME_MC = "mC"; + public static final String PROPERTY_NAME_MCARRAY = "mCArray"; + public static final String PROPERTY_NAME_MKEY = "key"; + public static final String PROPERTY_NAME_MCOMPLEXTYPE = "complexType"; + + public static final String NAVIGATION_PROPERTY_X = "mRelatedEntity"; + public static final String NAVIGATION_PROPERTY_XS = "mRelatedEntities"; + + private JPATypeEmbeddableMock key; + private JPATypeEmbeddableMock complexType; + private int mInt; + private String mString; + private Calendar mDateTime; + private Blob mBlob; + private Clob mClob; + private char mC; + private char[] mCArray; + private Character mChar; + private Character[] mCharArray; + + public Clob getMClob() { + return mClob; + } + + public void setMClob(final Clob mClob) { + this.mClob = mClob; + } + + public char getMC() { + return mC; + } + + public void setMC(final char mC) { + this.mC = mC; + } + + public char[] getMCArray() { + return mCArray; + } + + public void setMCArray(final char[] mCArray) { + this.mCArray = mCArray; + } + + public Character getMChar() { + return mChar; + } + + public void setMChar(final Character mChar) { + this.mChar = mChar; + } + + public Character[] getMCharArray() { + return mCharArray; + } + + public void setMCharArray(final Character[] mCharArray) { + this.mCharArray = mCharArray; + } + + private JPARelatedTypeMock mRelatedEntity; + private List<JPARelatedTypeMock> mRelatedEntities = new ArrayList<JPATypeMock.JPARelatedTypeMock>(); + + public String getMString() { + return mString; + } + + public void setMString(final String mString) { + this.mString = mString; + } + + public JPATypeEmbeddableMock getKey() { + return key; + } + + public void setKey(final JPATypeEmbeddableMock key) { + this.key = key; + } + + public int getMInt() { + return mInt; + } + + public void setMInt(final int mInt) { + this.mInt = mInt; + } + + public Calendar getMDateTime() { + return mDateTime; + } + + public void setMDateTime(final Calendar mDateTime) { + this.mDateTime = mDateTime; + } + + public JPARelatedTypeMock getMRelatedEntity() { + return mRelatedEntity; + } + + public void setMRelatedEntity(final JPARelatedTypeMock mRelatedEntity) { + this.mRelatedEntity = mRelatedEntity; + } + + public List<JPARelatedTypeMock> getMRelatedEntities() { + return mRelatedEntities; + } + + public void setMRelatedEntities(final List<JPARelatedTypeMock> mRelatedEntities) { + this.mRelatedEntities = mRelatedEntities; + } + + public JPATypeEmbeddableMock getComplexType() { + return complexType; + } + + public void setComplexType(final JPATypeEmbeddableMock complexType) { + this.complexType = complexType; + } + + public Blob getMBlob() { + return mBlob; + } + + public void setMBlob(final Blob mBlob) { + this.mBlob = mBlob; + } + + /* ========================================================================= */ + public static class JPATypeEmbeddableMock { + + public static final String ENTITY_NAME = "JPATypeEmbeddableMock"; + public static final String PROPERTY_NAME_MSHORT = "mShort"; + public static final String PROPERTY_NAME_MEMBEDDABLE = "mEmbeddable"; + + private short mShort; + private JPATypeEmbeddableMock2 mEmbeddable; + + public short getMShort() { + return mShort; + } + + public void setMShort(final short mShort) { + this.mShort = mShort; + } + + public JPATypeEmbeddableMock2 getMEmbeddable() { + return mEmbeddable; + } + + public void setMEmbeddable(final JPATypeEmbeddableMock2 mEmbeddable) { + this.mEmbeddable = mEmbeddable; + } + + } + + /* ========================================================================= */ + public static class JPATypeEmbeddableMock2 { + + public static final String ENTITY_NAME = "JPATypeEmbeddableMock2"; + public static final String PROPERTY_NAME_MUUID = "mUUID"; + public static final String PROPERTY_NAME_MFLOAT = "mFloat"; + + private UUID mUUID; + private float mFloat; + + public UUID getMUUID() { + return mUUID; + } + + public void setMUUID(final UUID mUUID) { + this.mUUID = mUUID; + } + + public float getMFloat() { + return mFloat; + } + + public void setMFloat(final float mFloat) { + this.mFloat = mFloat; + } + + } + + /* ========================================================================= */ + public static final class JPARelatedTypeMock { + public static final String ENTITY_NAME = "JPARelatedTypeMock"; + public static final String PROPERTY_NAME_MLONG = "mLong"; + public static final String PROPERTY_NAME_MDOUBLE = "mDouble"; + public static final String PROPERTY_NAME_MBYTE = "mByte"; + public static final String PROPERTY_NAME_MBYTEARRAY = "mByteArray"; + + private long mLong; + private double mDouble; + private byte mByte; + private byte mByteArray[]; + + public long getMLong() { + return mLong; + } + + public void setMLong(final long key) { + mLong = key; + } + + public double getMDouble() { + return mDouble; + } + + public void setMDouble(final double mDouble) { + this.mDouble = mDouble; + } + + public byte getMByte() { + return mByte; + } + + public void setMByte(final byte mByte) { + this.mByte = mByte; + } + + public byte[] getMByteArray() { + return mByteArray; + } + + public void setMByteArray(final byte mByteArray[]) { + this.mByteArray = mByteArray; + } + + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b155bda5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java index 13e1f05..4f95a0e 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java @@ -1,164 +1,164 @@ -/******************************************************************************* - * 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.data; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; -import java.util.UUID; - -import org.apache.olingo.odata2.api.ep.entry.EntryMetadata; -import org.apache.olingo.odata2.api.ep.entry.ODataEntry; -import org.apache.olingo.odata2.api.ep.feed.ODataFeed; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock; -import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2; -import org.easymock.EasyMock; - -public class ODataEntryMockUtil { - - public static final int VALUE_MINT = 20; - public static Calendar VALUE_DATE_TIME = null; - public static byte[] VALUE_BLOB = null; - public static final String VALUE_CLOB = "ABC"; - public static final String VALUE_C = "D"; - public static final String VALUE_CARRAY = "EFG"; - public static final String VALUE_CHAR = "I"; - public static final String VALUE_CHARARRAY = "LMN"; - public static final String VALUE_MSTRING = "Mock"; - public static final long VALUE_MLONG = 1234567890L; - public static final double VALUE_MDOUBLE = 20.12; - public static final byte VALUE_MBYTE = 0XA; - public static final byte[] VALUE_MBYTEARRAY = new byte[] { 0XA, 0XB }; - public static final float VALUE_MFLOAT = 2.00F; - public static final UUID VALUE_UUID = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d"); - public static final short VALUE_SHORT = 2; - - public static ODataEntry mockODataEntry(final String entityName) { - ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); - EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryProperties(entityName)).anyTimes(); - - enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); - EasyMock.replay(oDataEntry); - return oDataEntry; - } - - public static ODataEntry mockODataEntryWithComplexType(final String entityName) { - ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); - EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithComplexType(entityName)) - .anyTimes(); - - enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); - EasyMock.replay(oDataEntry); - return oDataEntry; - } - - public static Map<String, Object> mockODataEntryProperties(final String entityName) { - Map<String, Object> propertyMap = new HashMap<String, Object>(); - - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - propertyMap.put(JPATypeMock.PROPERTY_NAME_MINT, VALUE_MINT); - - VALUE_DATE_TIME = Calendar.getInstance(TimeZone.getDefault()); - VALUE_DATE_TIME.set(2013, 1, 1, 1, 1, 1); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MDATETIME, VALUE_DATE_TIME); - - VALUE_BLOB = VALUE_MBYTEARRAY; - propertyMap.put(JPATypeMock.PROPERTY_NAME_MBLOB, VALUE_BLOB); - - propertyMap.put(JPATypeMock.PROPERTY_NAME_CLOB, VALUE_CLOB); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MC, VALUE_C); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MCARRAY, VALUE_CARRAY); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MCHAR, VALUE_CHAR); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MCHARARRAY, VALUE_CHARARRAY); - propertyMap.put(JPATypeMock.PROPERTY_NAME_MSTRING, VALUE_MSTRING); - } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { - propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MLONG, VALUE_MLONG); - propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE, VALUE_MDOUBLE); - propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTE, VALUE_MBYTE); - propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY, VALUE_MBYTEARRAY); - } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { - propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT, VALUE_SHORT); - propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE, - mockODataEntryProperties(JPATypeEmbeddableMock2.ENTITY_NAME)); - } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { - propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT, VALUE_MFLOAT); - propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID, VALUE_UUID); - } - - return propertyMap; - } - - public static Map<String, Object> mockODataEntryPropertiesWithComplexType(final String entityName) { - Map<String, Object> propertyMap = mockODataEntryProperties(entityName); - propertyMap - .put(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE, mockODataEntryProperties(JPATypeEmbeddableMock.ENTITY_NAME)); - return propertyMap; - } - - public static Map<String, Object> mockODataEntryPropertiesWithInline(final String entityName) { - Map<String, Object> propertyMap = mockODataEntryProperties(entityName); - List<ODataEntry> relatedEntries = new ArrayList<ODataEntry>(); - relatedEntries.add(mockODataEntry(JPARelatedTypeMock.ENTITY_NAME)); - ODataFeed feed = EasyMock.createMock(ODataFeed.class); - EasyMock.expect(feed.getEntries()).andReturn(relatedEntries); - EasyMock.replay(feed); - propertyMap.put(JPATypeMock.NAVIGATION_PROPERTY_X, feed); - - return propertyMap; - - } - - public static ODataEntry mockODataEntryWithInline(final String entityName) { - ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); - EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithInline(entityName)).anyTimes(); - if (entityName.equals(JPATypeMock.ENTITY_NAME)) { - List<String> links = new ArrayList<String>(); - links.add(JPATypeMock.ENTITY_NAME + "(" + ODataEntryMockUtil.VALUE_MINT + ")/" - + JPATypeMock.NAVIGATION_PROPERTY_X); - enhanceMockODataEntry(oDataEntry, true, links); - } else { - enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); - } - EasyMock.replay(oDataEntry); - return oDataEntry; - } - - private static void - enhanceMockODataEntry(final ODataEntry oDataEntry, final boolean hasInline, final List<String> associationURIs) { - EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(hasInline).anyTimes(); - EntryMetadata entryMetadata = EasyMock.createMock(EntryMetadata.class); - if (hasInline) { - EasyMock.expect(entryMetadata.getAssociationUris(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn(associationURIs) - .anyTimes(); - EasyMock.expect(entryMetadata.getAssociationUris(JPATypeMock.NAVIGATION_PROPERTY_XS)).andReturn( - new ArrayList<String>()) - .anyTimes(); - } else { - EasyMock.expect(entryMetadata.getAssociationUris(EasyMock.isA(String.class))).andReturn(associationURIs) - .anyTimes(); - } - - EasyMock.replay(entryMetadata); - EasyMock.expect(oDataEntry.getMetadata()).andReturn(entryMetadata).anyTimes(); - } -} +/******************************************************************************* + * 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.data; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; +import java.util.UUID; + +import org.apache.olingo.odata2.api.ep.entry.EntryMetadata; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock; +import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2; +import org.easymock.EasyMock; + +public class ODataEntryMockUtil { + + public static final int VALUE_MINT = 20; + public static Calendar VALUE_DATE_TIME = null; + public static byte[] VALUE_BLOB = null; + public static final String VALUE_CLOB = "ABC"; + public static final String VALUE_C = "D"; + public static final String VALUE_CARRAY = "EFG"; + public static final String VALUE_CHAR = "I"; + public static final String VALUE_CHARARRAY = "LMN"; + public static final String VALUE_MSTRING = "Mock"; + public static final long VALUE_MLONG = 1234567890L; + public static final double VALUE_MDOUBLE = 20.12; + public static final byte VALUE_MBYTE = 0XA; + public static final byte[] VALUE_MBYTEARRAY = new byte[] { 0XA, 0XB }; + public static final float VALUE_MFLOAT = 2.00F; + public static final UUID VALUE_UUID = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d"); + public static final short VALUE_SHORT = 2; + + public static ODataEntry mockODataEntry(final String entityName) { + ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); + EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryProperties(entityName)).anyTimes(); + + enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); + EasyMock.replay(oDataEntry); + return oDataEntry; + } + + public static ODataEntry mockODataEntryWithComplexType(final String entityName) { + ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); + EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithComplexType(entityName)) + .anyTimes(); + + enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); + EasyMock.replay(oDataEntry); + return oDataEntry; + } + + public static Map<String, Object> mockODataEntryProperties(final String entityName) { + Map<String, Object> propertyMap = new HashMap<String, Object>(); + + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + propertyMap.put(JPATypeMock.PROPERTY_NAME_MINT, VALUE_MINT); + + VALUE_DATE_TIME = Calendar.getInstance(TimeZone.getDefault()); + VALUE_DATE_TIME.set(2013, 1, 1, 1, 1, 1); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MDATETIME, VALUE_DATE_TIME); + + VALUE_BLOB = VALUE_MBYTEARRAY; + propertyMap.put(JPATypeMock.PROPERTY_NAME_MBLOB, VALUE_BLOB); + + propertyMap.put(JPATypeMock.PROPERTY_NAME_CLOB, VALUE_CLOB); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MC, VALUE_C); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MCARRAY, VALUE_CARRAY); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MCHAR, VALUE_CHAR); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MCHARARRAY, VALUE_CHARARRAY); + propertyMap.put(JPATypeMock.PROPERTY_NAME_MSTRING, VALUE_MSTRING); + } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) { + propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MLONG, VALUE_MLONG); + propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE, VALUE_MDOUBLE); + propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTE, VALUE_MBYTE); + propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY, VALUE_MBYTEARRAY); + } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) { + propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT, VALUE_SHORT); + propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE, + mockODataEntryProperties(JPATypeEmbeddableMock2.ENTITY_NAME)); + } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) { + propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT, VALUE_MFLOAT); + propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID, VALUE_UUID); + } + + return propertyMap; + } + + public static Map<String, Object> mockODataEntryPropertiesWithComplexType(final String entityName) { + Map<String, Object> propertyMap = mockODataEntryProperties(entityName); + propertyMap + .put(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE, mockODataEntryProperties(JPATypeEmbeddableMock.ENTITY_NAME)); + return propertyMap; + } + + public static Map<String, Object> mockODataEntryPropertiesWithInline(final String entityName) { + Map<String, Object> propertyMap = mockODataEntryProperties(entityName); + List<ODataEntry> relatedEntries = new ArrayList<ODataEntry>(); + relatedEntries.add(mockODataEntry(JPARelatedTypeMock.ENTITY_NAME)); + ODataFeed feed = EasyMock.createMock(ODataFeed.class); + EasyMock.expect(feed.getEntries()).andReturn(relatedEntries); + EasyMock.replay(feed); + propertyMap.put(JPATypeMock.NAVIGATION_PROPERTY_X, feed); + + return propertyMap; + + } + + public static ODataEntry mockODataEntryWithInline(final String entityName) { + ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class); + EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithInline(entityName)).anyTimes(); + if (entityName.equals(JPATypeMock.ENTITY_NAME)) { + List<String> links = new ArrayList<String>(); + links.add(JPATypeMock.ENTITY_NAME + "(" + ODataEntryMockUtil.VALUE_MINT + ")/" + + JPATypeMock.NAVIGATION_PROPERTY_X); + enhanceMockODataEntry(oDataEntry, true, links); + } else { + enhanceMockODataEntry(oDataEntry, false, new ArrayList<String>()); + } + EasyMock.replay(oDataEntry); + return oDataEntry; + } + + private static void + enhanceMockODataEntry(final ODataEntry oDataEntry, final boolean hasInline, final List<String> associationURIs) { + EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(hasInline).anyTimes(); + EntryMetadata entryMetadata = EasyMock.createMock(EntryMetadata.class); + if (hasInline) { + EasyMock.expect(entryMetadata.getAssociationUris(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn(associationURIs) + .anyTimes(); + EasyMock.expect(entryMetadata.getAssociationUris(JPATypeMock.NAVIGATION_PROPERTY_XS)).andReturn( + new ArrayList<String>()) + .anyTimes(); + } else { + EasyMock.expect(entryMetadata.getAssociationUris(EasyMock.isA(String.class))).andReturn(associationURIs) + .anyTimes(); + } + + EasyMock.replay(entryMetadata); + EasyMock.expect(oDataEntry.getMetadata()).andReturn(entryMetadata).anyTimes(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b155bda5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java index 23e7330..dd88da7 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java @@ -1,95 +1,95 @@ -/******************************************************************************* - * 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.lang.reflect.Member; -import java.util.ArrayList; - -import javax.persistence.metamodel.ManagedType; -import javax.persistence.metamodel.PluralAttribute; -import javax.persistence.metamodel.Type; - -public class JPAPluralAttributeMock implements PluralAttribute<Object, ArrayList<String>, String> { - - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public ManagedType<Object> getDeclaringType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Class<ArrayList<String>> getJavaType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Member getJavaMember() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isAssociation() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isCollection() { - return false; - } - - @Override - public javax.persistence.metamodel.Bindable.BindableType getBindableType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Class<String> getBindableJavaType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public javax.persistence.metamodel.PluralAttribute.CollectionType getCollectionType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Type<String> getElementType() { - // TODO Auto-generated method stub - return null; - } - +/******************************************************************************* + * 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.lang.reflect.Member; +import java.util.ArrayList; + +import javax.persistence.metamodel.ManagedType; +import javax.persistence.metamodel.PluralAttribute; +import javax.persistence.metamodel.Type; + +public class JPAPluralAttributeMock implements PluralAttribute<Object, ArrayList<String>, String> { + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ManagedType<Object> getDeclaringType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Class<ArrayList<String>> getJavaType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Member getJavaMember() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isAssociation() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isCollection() { + return false; + } + + @Override + public javax.persistence.metamodel.Bindable.BindableType getBindableType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Class<String> getBindableJavaType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public javax.persistence.metamodel.PluralAttribute.CollectionType getCollectionType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Type<String> getElementType() { + // TODO Auto-generated method stub + return null; + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b155bda5/odata2-jpa-processor/jpa-ref/.gitignore ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-ref/.gitignore b/odata2-jpa-processor/jpa-ref/.gitignore index fe5d89b..a7ffe90 100644 --- a/odata2-jpa-processor/jpa-ref/.gitignore +++ b/odata2-jpa-processor/jpa-ref/.gitignore @@ -1,8 +1,8 @@ -.project -.classpath -.settings -target -bin -*.bak -classes +.project +.classpath +.settings +target +bin +*.bak +classes .DS_Store \ No newline at end of file
