org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl Java Examples

The following examples show how to use org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmEntityTypeView view) {

    EntityType edmEntityType = view.getEdmEntityType();
    String jpaEntityName = view.getJPAEntityType().getName();
    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
    String edmEntityTypeName = null;
    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
      edmEntityTypeName = mappingModelAccess.mapJPAEntityType(jpaEntityName);
    }

    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    mapping.setJPAType(view.getJPAEntityType().getJavaType());

    if (edmEntityTypeName == null) {
      edmEntityTypeName = jpaEntityName;
    }
    // Setting the mapping object
    edmEntityType.setMapping(((Mapping) mapping).setInternalName(jpaEntityName));

    edmEntityType.setName(edmEntityTypeName);

  }
 
Example #2
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private JPAEdmMapping mockMappingWithType(String type) {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("Customer");
  if (type.equals("Character")) {
    mockedEdmMapping.setJPAType(Character.class);
  } else if (type.equals("char")) {
    mockedEdmMapping.setJPAType(char.class);
  } else if (type.equals("charArray")) {
    mockedEdmMapping.setJPAType(char[].class);
  } else if (type.equals("characterArray")) {
    mockedEdmMapping.setJPAType(Character[].class);
  } else if (type.equals("uuid")) {
    mockedEdmMapping.setJPAType(UUID.class);
  }
  return mockedEdmMapping;
}
 
Example #3
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 * @throws EdmException
 */
private EdmFunctionImport getLocalEdmFunctionImport() {
  EdmFunctionImport edmFunction = EasyMock.createMock(EdmFunctionImport.class);
  try {
    EasyMock.expect(edmFunction.getName()).andStubReturn(SALES_ORDER_HEADERS);
    EasyMock.expect(edmFunction.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
    EasyMock.expect(edmFunction.getReturnType()).andStubReturn(null);
    EasyMock.expect(edmFunction.getHttpMethod()).andStubReturn("GET");
    EasyMock.expect(edmFunction.getParameterNames()).andStubReturn(new ArrayList<String>());
    JPAEdmMappingImpl mockedEdmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  //  ((Mapping) mockedEdmMapping).setInternalName(SALES_ORDER_HEADERS);
    EasyMock.expect(edmFunction.getMapping()).andStubReturn(mockedEdmMapping);
    EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
    EasyMock.<Class<?>> expect(mockedEdmMapping.getJPAType()).andReturn(SalesOrderHeader.class);
    EasyMock.replay(mockedEdmMapping);
    EasyMock.replay(edmFunction);
  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  return edmFunction;
}
 
Example #4
Source File: JPAEntityParserTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private EdmProperty getEdmPropertyWithVirtualAccess() {
  EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);

  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
  EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(true);
  EasyMock.replay(edmMapping);

  EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);

  try {
    EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
    EasyMock.expect(edmType.getName()).andStubReturn("identifier");
    EasyMock.expect(edmTyped.getName()).andStubReturn("SalesOrderHeader");
    EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);

    EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
    EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);

  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  EasyMock.replay(edmType);
  EasyMock.replay(edmTyped);
  return edmTyped;
}
 
Example #5
Source File: JPAEntityParserTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private EdmProperty getEdmProperty() {
  EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);

  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
  EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(false);
  EasyMock.replay(edmMapping);

  EdmType edmType = EasyMock.createMock(EdmType.class);

  try {
    EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
    EasyMock.expect(edmType.getName()).andStubReturn("identifier");
    EasyMock.expect(edmTyped.getName()).andStubReturn("SalesOrderHeader");
    EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);

    EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
    EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);

  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  EasyMock.replay(edmType);
  EasyMock.replay(edmTyped);
  return edmTyped;
}
 
Example #6
Source File: JPQLJoinContextTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<KeyPredicate> createKeyPredicates() throws EdmException {
  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getJPAType())
  .andStubReturn(null);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
  EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
  EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
  EdmSimpleType edmType = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();
  EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
  EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);

  EasyMock.replay(edmMapping, edmProperty, keyPredicate);
  List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
  keyPredicates.add(keyPredicate);
  return keyPredicates;
}
 
Example #7
Source File: JPQLJoinSelectSingleContextTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<KeyPredicate> createKeyPredicates(final boolean toThrowException) throws EdmException {
  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getJPAType())
  .andStubReturn(null);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
  EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
  EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
  EdmSimpleType edmType = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();
  if (toThrowException) {
    EasyMock.expect(edmProperty.getType()).andStubThrow(new EdmException(null));
  } else {
    EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
  }
  EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);

  EasyMock.replay(edmMapping, edmProperty, keyPredicate);
  List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
  keyPredicates.add(keyPredicate);
  return keyPredicates;
}
 
Example #8
Source File: EdmMockUtil.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static EdmProperty mockEdmPropertyOfTarget() {
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);

  EdmType type = EasyMock.createMock(EdmType.class);
  EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
  EasyMock.replay(type);
  JPAEdmMappingImpl mapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(mapping.getInternalName()).andStubReturn("price");
  EasyMock.expect(((JPAEdmMappingImpl) mapping).isVirtualAccess()).andStubReturn(false);
  EasyMock.replay(mapping);
  try {
    EasyMock.expect(edmProperty.getName()).andStubReturn("price");
    EasyMock.expect(edmProperty.getType()).andStubReturn(type);
    EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  EasyMock.replay(edmProperty);
  return edmProperty;
}
 
Example #9
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmComplexType view) {

    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
    String jpaEmbeddableTypeName = view.getJPAEmbeddableType().getJavaType().getSimpleName();
    String edmComplexTypeName = null;
    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
      edmComplexTypeName = mappingModelAccess.mapJPAEmbeddableType(jpaEmbeddableTypeName);
    }

    if (edmComplexTypeName == null) {
      edmComplexTypeName = jpaEmbeddableTypeName;
    }

    view.getEdmComplexType().setName(edmComplexTypeName);
    ComplexType complexType = view.getEdmComplexType();
    complexType.setName(edmComplexTypeName);
    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    mapping.setJPAType(view.getJPAEmbeddableType().getJavaType());
    complexType.setMapping((Mapping) mapping);

  }
 
Example #10
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmComplexPropertyView complexView,
    final String parentComplexTypeName, final boolean skipDefaultNaming) {
  ComplexProperty complexProperty = complexView.getEdmComplexProperty();

  JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
  JPAEdmPropertyView propertyView = ((JPAEdmPropertyView) complexView);
  String jpaAttributeName = propertyView.getJPAAttribute().getName();
  String propertyName = null;
  if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
    propertyName = mappingModelAccess.mapJPAEmbeddableTypeAttribute(parentComplexTypeName, jpaAttributeName);
  }
  if (skipDefaultNaming == false && propertyName == null) {
    propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
  } else if (propertyName == null) {
    propertyName = jpaAttributeName;
  }

  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  ((Mapping) mapping).setInternalName(jpaAttributeName);
  mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
  complexProperty.setMapping((Mapping) mapping);
  complexProperty.setName(propertyName);

}
 
Example #11
Source File: ODataJPAResponseBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EdmProperty getEdmPropertyForSelect() {
  EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
  EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
  Facets facets = new Facets().setNullable(false);
  try {
    EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.URI, facets)).andStubReturn("2");
    EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.DEFAULT, facets)).andStubReturn("2");
  } catch (EdmSimpleTypeException e1) {
    fail("There is an exception in mocking EdmType object " + e1.getMessage());
  }
  EasyMock.replay(edmType);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
  EasyMock.expect(edmMapping.getMediaResourceMimeTypeKey()).andReturn(null);
  EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(false);
  EasyMock.replay(edmMapping);
  try {
    EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
    EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
    EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
    EasyMock.expect(edmProperty.getFacets()).andStubReturn(facets);
    EasyMock.expect(edmProperty.getCustomizableFeedMappings()).andStubReturn(null);
    EasyMock.expect(edmProperty.getMimeType()).andStubReturn(null);
    EasyMock.replay(edmProperty);

  } catch (EdmException e) {
    fail("There is an exception in mocking some object " + e.getMessage());
  }

  return edmProperty;

}
 
Example #12
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private JPAEdmMapping mockEdmMapping() {
  JPATombstoneExtensionMock tombstone = new JPATombstoneExtensionMock();
  tombstone.handleDelta(new String("delta"));
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setODataJPATombstoneEntityListener(JPAQueryExtensionMock.class);
  mockedEdmMapping.setODataJPATombstoneEntityListener(JPATombstoneExtensionMock.class);
  mockedEdmMapping.setInternalName(SALES_ORDER_HEADERS);
  return mockedEdmMapping;
}
 
Example #13
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EdmMapping getEdmMappingMockedObj(final String propertyName) {
  EdmMapping mockedEdmMapping = new JPAEdmMappingImpl();
  if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
    ((Mapping) mockedEdmMapping).setInternalName(SALES_ORDER_HEADERS);
  } else {
    ((Mapping) mockedEdmMapping).setInternalName(propertyName);
  }

  return mockedEdmMapping;
}
 
Example #14
Source File: ODataJPADefaultProcessorTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private JPAEdmMapping getEdmMappingMockedObj(final String propertyName) {
  JPAEdmMappingImpl mockedEdmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
    EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
  } else {
    EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(propertyName);
  }
  EasyMock.expect(mockedEdmMapping.getODataJPATombstoneEntityListener()).andReturn(null);
  EasyMock.<Class<?>> expect(mockedEdmMapping.getJPAType()).andReturn(SalesOrderHeader.class);
  EasyMock.replay(mockedEdmMapping);
  return mockedEdmMapping;
}
 
Example #15
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static void build(final JPAEdmComplexPropertyView complexView,
    final JPAEdmPropertyView propertyView, final boolean skipDefaultNaming) {

  ComplexProperty complexProperty = complexView.getEdmComplexProperty();

  String jpaAttributeName = propertyView.getJPAAttribute().getName();
  String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView().getJPAEntityType().getName();

  JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
  String propertyName = null;

  if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
    propertyName = mappingModelAccess.mapJPAAttribute(jpaEntityTypeName, jpaAttributeName);
  }

  if (skipDefaultNaming == false && propertyName == null) {
    propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
  } else if (propertyName == null) {
    propertyName = jpaAttributeName;
  }

  // change for navigation property issue
  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  ((Mapping) mapping).setInternalName(jpaAttributeName);
  mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
  complexProperty.setMapping((Mapping) mapping);

  complexProperty.setName(propertyName);

}
 
Example #16
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockEdmMappingForProperty() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("CustomerName");
  return mockedEdmMapping;
}
 
Example #17
Source File: EdmMockUtilV2.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
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_ENUM)) {
    mapping.setJPAType(JPATypeMock.JPATypeMockEnum.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_ENUM);
  } 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_XMLADAPTER)) {
      mapping.setJPAType(EntityWithXmlAdapterOnProperty.class);
      ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_XMLADAPTER);
  } 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.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT);
  } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MDATE)) {
    mapping.setJPAType(java.util.Date.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MDATE);
  } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MDATE1)) {
    mapping.setJPAType(java.sql.Date.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MDATE1);
  } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MTIME)) {
    mapping.setJPAType(Time.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MTIME);
  } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MTIMESTAMP)) {
    mapping.setJPAType(Timestamp.class);
    ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MTIMESTAMP);
  } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)) {
    mapping.setJPAType(Float.class);
    ((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;
}
 
Example #18
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockNormalizedValueMapping() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("'C1.Customer.Name'");
  return mockedEdmMapping;
}
 
Example #19
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockNormalizedMapping1() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("E1.SalesOrderItem");
  return mockedEdmMapping;
}
 
Example #20
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockNormalizedMapping() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("C1.Customer.Name");
  return mockedEdmMapping;
}
 
Example #21
Source File: ODataJPAFactoryImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public JPAEdmMapping getJPAEdmMappingInstance() {
  return new JPAEdmMappingImpl();
}
 
Example #22
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockMapping() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("Customer");
  return mockedEdmMapping;
}
 
Example #23
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockNavEdmMappingForProperty() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("SalesOrderHeader");
  return mockedEdmMapping;
}
 
Example #24
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockEdmMappingForProperty1() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setInternalName("SalesOrderHeader.CustomerName");
  return mockedEdmMapping;
}
 
Example #25
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMapping mockEdmMapping() {
  JPAEdmMappingImpl mockedEdmMapping = new JPAEdmMappingImpl();
  mockedEdmMapping.setODataJPATombstoneEntityListener(JPAQueryExtensionMock.class);
  return mockedEdmMapping;
}
 
Example #26
Source File: JPAFunctionContextTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPAEdmMappingImpl getMapping() {
  JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
  mapping.setJPAType(FunctionImportTestClass.class);
  ((Mapping) mapping).setInternalName(FUNCTION_NAME);
  return mapping;
}
 
Example #27
Source File: JPAFunctionContextTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EdmMapping getEdmMapping() {
  JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
  mapping.setJPAType(String.class);
  ((Mapping) mapping).setInternalName(PARAMNAME);
  return mapping;
}
 
Example #28
Source File: JPQLBuilderFactoryTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private GetEntitySetUriInfo getUriInfo() throws EdmException {
  GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(edmEntityType.getName()).andStubReturn("SOItem");
  EasyMock.replay(edmEntityType);
  OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
  EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
  EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
  EasyMock.expect(getEntitySetView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
  EasyMock.replay(startEdmEntityType, startEdmEntitySet);
  EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
  EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(null);
  EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(null);
  List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(getEntitySetView.getNavigationSegments()).andStubReturn(navigationSegments);
  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
  EdmSimpleType edmType = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
  EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
  EasyMock.expect(edmMapping.getJPAType())
  .andStubReturn(null);
  try {
    EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
    EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);

    EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);

  } catch (EdmException e2) {
    fail("this should not happen");
  }
  EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
  EasyMock.replay(edmMapping, kpProperty, keyPredicate);
  List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
  keyPredicates.add(keyPredicate);
  EasyMock.expect(getEntitySetView.getKeyPredicates()).andStubReturn(keyPredicates);
  EasyMock.replay(getEntitySetView);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.replay(edmEntitySet);
  return getEntitySetView;
}
 
Example #29
Source File: JPQLSelectSingleStatementBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPQLSelectSingleContext createSelectContext(EdmSimpleType edmType) throws ODataJPARuntimeException,
EdmException {
  // Object Instantiation

  JPQLSelectSingleContext JPQLSelectSingleContextImpl = null;// new JPQLSelectSingleContextImpl();
  GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);

  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  List<SelectItem> selectItemList = null;

  // Setting up the expected value
  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
 
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getJPAType())
  .andStubReturn(null);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
  setSpecificProperties(keyPredicate, kpProperty, edmType);
  try {
    EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
    EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);

  } catch (EdmException e2) {
    fail("this should not happen");
  }
  EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
  EasyMock.replay(edmMapping, kpProperty, keyPredicate);
  EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EasyMock.expect(getEntityView.getSelect()).andStubReturn(selectItemList);

  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.replay(edmEntitySet);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
  EasyMock.replay(edmEntityType);
  ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
  arrayList.add(keyPredicate);
  EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(arrayList);
  EasyMock.replay(getEntityView);

  JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView);
  try {
    JPQLSelectSingleContextImpl = (JPQLSelectSingleContext) contextBuilder1.build();
  } catch (ODataJPAModelException e) {
    fail("Model Exception thrown");
  }

  return JPQLSelectSingleContextImpl;
}
 
Example #30
Source File: JPALinkTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private List<NavigationSegment> mockNavigationSegments(boolean isReverse) throws EdmException, NoSuchFieldException,
    SecurityException, IllegalArgumentException, IllegalAccessException {
  Class<?> type = null;
  String entityTypeName = null;
  String keyLiteral = null;
  EdmMultiplicity multiplicity = null;
  String navPropertyName = null;
  String toRole = null;
  String associationName = null;

  if (isReverse) {
    type = SalesOrderHeader.class;
    entityTypeName = "SalesOrder";
    keyLiteral = "1";
    multiplicity = EdmMultiplicity.ONE;
    navPropertyName = "salesOrderHeader";
    toRole = "SalesOrder";
    associationName = "Note_SalesOrder";

  } else {
    type = List.class;
    entityTypeName = "Note";
    keyLiteral = "2";
    multiplicity = EdmMultiplicity.MANY;
    navPropertyName = "NotesDetails";
    toRole = "Note";
    associationName = "Note_SalesOrder";
  }

  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  mapping.setJPAType(type);

  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EasyMock.expect(keyPredicate.getProperty()).andReturn(
      edm.getEntityType("SalesOrderProcessing", entityTypeName).getKeyProperties().get(0)).anyTimes();
  EasyMock.expect(keyPredicate.getLiteral()).andReturn(keyLiteral);
  EasyMock.replay(keyPredicate);
  List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
  keyPredicates.add(keyPredicate);

  NavigationSegment navigationSegment = EasyMock.createMock(NavigationSegment.class);
  EasyMock.expect(navigationSegment.getKeyPredicates()).andReturn(keyPredicates);

  EdmNavigationProperty navProperty = EasyMock.createMock(EdmNavigationProperty.class);
  EasyMock.expect(navProperty.getMapping()).andReturn((EdmMapping) mapping).anyTimes();
  EasyMock.expect(navProperty.getMultiplicity()).andReturn(multiplicity).anyTimes();
  EasyMock.expect(navProperty.getName()).andReturn(navPropertyName).anyTimes();
  EasyMock.expect(navProperty.getToRole()).andReturn(toRole).anyTimes();
  EasyMock.expect(navProperty.getRelationship()).andReturn(
      edm.getAssociation("SalesOrderProcessing", associationName));
  EasyMock.replay(navProperty);

  EdmEntityType edmEntityType =
      edm.getAssociation("SalesOrderProcessing", associationName).getEnd(toRole).getEntityType();
  Field field = EdmEntityTypeImplProv.class.getDeclaredField("entityType");
  field.setAccessible(true);

  EntityType entityType = (EntityType) field.get(edmEntityType);
  entityType.setMapping((Mapping) mapping);

  EasyMock.expect(navigationSegment.getNavigationProperty()).andReturn(navProperty).anyTimes();
  EasyMock.replay(navigationSegment);

  List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
  navigationSegments.add(navigationSegment);

  return navigationSegments;
}