org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind Java Examples

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind. 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: EdmMappingTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {

  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  mappedObject = new EdmMappingTest();

  Mapping propertySimpleMapping = new Mapping().setInternalName("value").setObject(mappedObject);
  CustomizableFeedMappings propertySimpleFeedMappings = new CustomizableFeedMappings().setFcKeepInContent(true);
  SimpleProperty propertySimple =
      new SimpleProperty().setName("PropertyName").setType(EdmSimpleTypeKind.String)
          .setMimeType("mimeType").setMapping(propertySimpleMapping).setCustomizableFeedMappings(
              propertySimpleFeedMappings);
  propertySimpleProvider = new EdmSimplePropertyImplProv(edmImplProv, propertySimple);

  NavigationProperty navProperty =
      new NavigationProperty().setName("navProperty").setFromRole("fromRole").setToRole("toRole").setMapping(
          propertySimpleMapping);
  navPropertyProvider = new EdmNavigationPropertyImplProv(edmImplProv, navProperty);
}
 
Example #2
Source File: EdmSimpleTypeFacadeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void parseIncompatibleLiteral() throws Exception {
  parseIncompatibleLiteralContent("1D", EdmSimpleTypeKind.Binary);
  parseIncompatibleLiteralContent("'0'", EdmSimpleTypeKind.Boolean);
  parseIncompatibleLiteralContent("'1'", EdmSimpleTypeKind.Boolean);
  parseIncompatibleLiteralContent("2", EdmSimpleTypeKind.Boolean);
  parseIncompatibleLiteralContent("-1", EdmSimpleTypeKind.Byte);
  parseIncompatibleLiteralContent("-129", EdmSimpleTypeKind.Byte);
  parseIncompatibleLiteralContent("time'PT11H12M13S'", EdmSimpleTypeKind.DateTime);
  parseIncompatibleLiteralContent("time'PT11H12M13S'", EdmSimpleTypeKind.DateTimeOffset);
  parseIncompatibleLiteralContent("'1'", EdmSimpleTypeKind.Decimal);
  parseIncompatibleLiteralContent("1M", EdmSimpleTypeKind.Double);
  parseIncompatibleLiteralContent("1", EdmSimpleTypeKind.Guid);
  parseIncompatibleLiteralContent("32768", EdmSimpleTypeKind.Int16);
  parseIncompatibleLiteralContent("1L", EdmSimpleTypeKind.Int32);
  parseIncompatibleLiteralContent("1M", EdmSimpleTypeKind.Int64);
  parseIncompatibleLiteralContent("128", EdmSimpleTypeKind.SByte);
  parseIncompatibleLiteralContent("1D", EdmSimpleTypeKind.Single);
  parseIncompatibleLiteralContent("1", EdmSimpleTypeKind.String);
  parseIncompatibleLiteralContent("datetime'2012-10-10T11:12:13'", EdmSimpleTypeKind.Time);
}
 
Example #3
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void valueOfStringInt16() throws Exception {
  final EdmSimpleType instance = EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance();

  assertEquals(Byte.valueOf((byte) 1), instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, Byte.class));
  assertEquals(Short.valueOf((short) 2), instance.valueOfString("2", EdmLiteralKind.JSON, null, Short.class));
  assertEquals(Short.valueOf((short) -32768), instance.valueOfString("-32768",
      EdmLiteralKind.URI, null, Short.class));
  assertEquals(Short.valueOf((short) 32767), instance.valueOfString("32767", EdmLiteralKind.URI, null, Short.class));
  assertEquals(Integer.valueOf(0), instance.valueOfString("0", EdmLiteralKind.DEFAULT, null, Integer.class));
  assertEquals(Long.valueOf(-1), instance.valueOfString("-1", EdmLiteralKind.DEFAULT, null, Long.class));

  expectErrorInValueOfString(instance, "32768", EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);
  expectErrorInValueOfString(instance, "1.0", EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);

  expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT);
  expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);
  expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class);
}
 
Example #4
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void valueOfStringInt32() throws Exception {
  final EdmSimpleType instance = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();

  assertEquals(Byte.valueOf((byte) 1), instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, Byte.class));
  assertEquals(Short.valueOf((short) 2), instance.valueOfString("2", EdmLiteralKind.JSON, null, Short.class));
  assertEquals(Integer.valueOf(-10000000), instance.valueOfString("-10000000", EdmLiteralKind.URI, null,
      Integer.class));
  assertEquals(Long.valueOf(10000000), instance.valueOfString("10000000", EdmLiteralKind.URI, null, Long.class));

  expectErrorInValueOfString(instance, "-2147483649", EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);
  expectErrorInValueOfString(instance, "1.0", EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);

  expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT);
  expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);
  expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class);
  expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class);
  expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class);
}
 
Example #5
Source File: EdmTypedImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public EdmType getType() throws EdmException {
  if (edmType == null) {
    final String namespace = typeName.getNamespace();
    if (EdmSimpleType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
      edmType = EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.valueOf(typeName.getName()));
    } else {
      edmType = edm.getComplexType(namespace, typeName.getName());
    }
    if (edmType == null) {
      edmType = edm.getEntityType(namespace, typeName.getName());
    }

    if (edmType == null) {
      throw new EdmException(EdmException.TYPEPROBLEM);
    }

  }
  return edmType;
}
 
Example #6
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static EdmEntityType createEntityTypeMock(final String name, final EdmSimpleTypeKind kind,
    final String keyPropertyId) throws EdmException {
  EdmEntityType entityType = mock(EdmEntityType.class);
  when(entityType.getName()).thenReturn(name);
  when(entityType.getNamespace()).thenReturn("RefScenario");

  final EdmProperty keyProperty = createProperty(keyPropertyId, kind, entityType);
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.getMaxLength()).thenReturn(null);
  when(facets.isNullable()).thenReturn(false);
  when(keyProperty.getFacets()).thenReturn(facets);

  when(entityType.getKind()).thenReturn(EdmTypeKind.ENTITY);
  when(entityType.getPropertyNames()).thenReturn(Arrays.asList(keyPropertyId));
  when(entityType.getKeyPropertyNames()).thenReturn(Arrays.asList(keyPropertyId));
  when(entityType.getKeyProperties()).thenReturn(Arrays.asList(keyProperty));

  return entityType;
}
 
Example #7
Source File: EdmTypedImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public EdmType getType() throws EdmException {
  if (edmType == null) {
    final String namespace = typeName.getNamespace();
    if (EdmSimpleType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
      edmType = EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.valueOf(typeName.getName()));
    } else {
      edmType = edm.getComplexType(namespace, typeName.getName());
    }
    if (edmType == null) {
      edmType = edm.getEntityType(namespace, typeName.getName());
    }

    if (edmType == null) {
      throw new EdmException(EdmException.COMMON);
    }

  }
  return edmType;
}
 
Example #8
Source File: JPAEdmProperty.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private SimpleProperty buildSimpleProperty(final Attribute<?, ?> jpaAttribute, final SimpleProperty simpleProperty,
    final JoinColumn joinColumn)
    throws ODataJPAModelException, ODataJPARuntimeException {

  boolean isForeignKey = joinColumn != null;
  JPAEdmNameBuilder.build(JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming, isForeignKey);
  EdmSimpleTypeKind simpleTypeKind = JPATypeConverter
      .convertToEdmSimpleType(jpaAttribute
          .getJavaType(), jpaAttribute);
  simpleProperty.setType(simpleTypeKind);
  Facets facets = JPAEdmFacets.createAndSet(jpaAttribute, simpleProperty);
  if(isForeignKey) {
    facets.setNullable(joinColumn.nullable());
  }

  return simpleProperty;

}
 
Example #9
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 #10
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void idGuidWithoutKey() throws Exception {
  EdmEntityContainer defaultContainer = mock(EdmEntityContainer.class);
  when(defaultContainer.isDefaultEntityContainer()).thenReturn(true);
  final EdmEntitySet entitySet =
      createEntitySetMock(defaultContainer, "Employer", EdmSimpleTypeKind.Guid, "EmployerId");
 
  final EntitySerializerProperties properties =
      EntitySerializerProperties.serviceRoot(BASE_URI).isKeyAutoGenerated(true)
      .includeMetadata(true)
          .build();

  Entity localEmployeeData = new Entity();
  localEmployeeData.setWriteProperties(properties);

  AtomSerializerDeserializer ser = createAtomEntityProvider();
  ODataResponse response =
      ser.writeEntry(entitySet, localEmployeeData);
  String xmlString = verifyResponse(response);
  assertXpathExists("/a:entry/a:link[@href=\"Employer(guid'00000000-0000-0000-0000-000000000000')\"]", xmlString);
}
 
Example #11
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void valueToStringInt32() throws Exception {
  final EdmSimpleType instance = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();

  assertEquals("0", instance.valueToString(0, EdmLiteralKind.DEFAULT, null));
  assertEquals("0", instance.valueToString(0, EdmLiteralKind.JSON, null));
  assertEquals("0", instance.valueToString(0, EdmLiteralKind.URI, null));
  assertEquals("8", instance.valueToString((byte) 8, EdmLiteralKind.DEFAULT, null));
  assertEquals("16", instance.valueToString((short) 16, EdmLiteralKind.DEFAULT, null));
  assertEquals("32", instance.valueToString(Integer.valueOf(32), EdmLiteralKind.DEFAULT, null));
  assertEquals("255", instance.valueToString(255L, EdmLiteralKind.DEFAULT, null));

  expectErrorInValueToString(instance, 12345678901L, EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT);
  expectErrorInValueToString(instance, -2147483649L, EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT);

  expectErrorInValueToString(instance, 1.0, EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED);
  expectErrorInValueToString(instance, 1, null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING);
}
 
Example #12
Source File: CarEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
  if (NAMESPACE.equals(edmFQName.getNamespace())) {
    if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
      List<Property> properties = new ArrayList<Property>();
      properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
      return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
    }
  }

  return null;
}
 
Example #13
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected void validateBinaryOperatorTypes(final BinaryExpression binaryExpression) throws ExpressionParserException,
    ExpressionParserInternalError {
  InfoBinaryOperator binOpt = availableBinaryOperators.get(binaryExpression.getOperator().toUriLiteral());

  List<EdmType> actualParameterTypes = new ArrayList<EdmType>();
  final EdmType leftType = binaryExpression.getLeftOperand().getEdmType();
  if (leftType == null && resourceEntityType == null) {
    return;
  }
  actualParameterTypes.add(leftType);

  final EdmType rightType = binaryExpression.getRightOperand().getEdmType();
  if (rightType == null && resourceEntityType == null) {
    return;
  }
  actualParameterTypes.add(rightType);

  // special case for navigation property (non-)equality comparison with null
  if ("Equality".equals(binOpt.getCategory())
      && (leftType != null && leftType.getKind() == EdmTypeKind.ENTITY
          && rightType == EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.Null)
          || leftType == EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.Null)
          && rightType != null && rightType.getKind() == EdmTypeKind.ENTITY)) {
    binaryExpression.setEdmType(EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.Boolean));
    return;
  }

  final ParameterSet parameterSet = binOpt.validateParameterSet(actualParameterTypes);
  if (parameterSet == null) {
    BinaryExpressionImpl binaryExpressionImpl = (BinaryExpressionImpl) binaryExpression;

    // Tested with TestParserExceptions.TestPMvalidateBinaryOperator
    throw FilterParserExceptionImpl.createINVALID_TYPES_FOR_BINARY_OPERATOR(binaryExpression.getOperator(),
        binaryExpression.getLeftOperand().getEdmType(), binaryExpression.getRightOperand().getEdmType(),
        binaryExpressionImpl.getToken(), curExpression);
  }
  binaryExpression.setEdmType(parameterSet.getReturnType());
}
 
Example #14
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void readComplexPropertyWithMappings() throws Exception {
  String xml =
      "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\""
          + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" m:type=\"RefScenario.c_Location\">" +
          "<Country>Germany</Country>" +
          "<City m:type=\"RefScenario.c_City\">" +
          "  <PostalCode>69124</PostalCode>" +
          "  <CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>";
  XMLStreamReader reader = createReaderForTest(xml, true);

  EdmProperty locationComplexProperty =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");
  EdmProperty cityProperty = (EdmProperty) ((EdmComplexType) locationComplexProperty.getType()).getProperty("City");
  EdmProperty postalCodeProperty = (EdmProperty) ((EdmComplexType) cityProperty.getType()).getProperty("PostalCode");
  // Change the type of the PostalCode property to one that allows different Java types.
  when(postalCodeProperty.getType()).thenReturn(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());

  // Execute test
  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(
      createTypeMappings("Location",
          createTypeMappings("City",
              createTypeMappings("CityName", String.class, "PostalCode", Long.class))));
  Map<String, Object> resultMap =
      new XmlPropertyConsumer().readProperty(reader, locationComplexProperty, readProperties);

  // verify
  Map<String, Object> locationMap = (Map<String, Object>) resultMap.get("Location");
  assertEquals("Germany", locationMap.get("Country"));
  Map<String, Object> cityMap = (Map<String, Object>) locationMap.get("City");
  assertEquals(Long.valueOf("69124"), cityMap.get("PostalCode"));
  assertEquals("Heidelberg", cityMap.get("CityName"));
}
 
Example #15
Source File: ODataRequestHandler.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static List<ContentType> getSupportedContentTypes(final EdmProperty property) throws EdmException {
  if (property != null) {
    return property.getType() == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()
        ? Collections.singletonList(property.getMimeType() == null
          ? ContentType.WILDCARD : ContentType.create(property.getMimeType()))
          : Arrays.asList(ContentType.TEXT_PLAIN, ContentType.TEXT_PLAIN_CS_UTF_8);
  } else {
    return null;
  }
  
}
 
Example #16
Source File: Tokenizer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private boolean checkForBoolean(final int oldPosition, final String rem_expr) {
  boolean isBoolean = false;
  if ("true".equals(rem_expr) || "false".equals(rem_expr)) {
    curPosition = curPosition + rem_expr.length();
    tokens.appendEdmTypedToken(oldPosition, TokenKind.SIMPLE_TYPE, rem_expr, new EdmLiteral(EdmSimpleTypeFacadeImpl
        .getEdmSimpleType(EdmSimpleTypeKind.Boolean), rem_expr));
    isBoolean = true;
  }
  return isBoolean;
}
 
Example #17
Source File: EdmSimpleTypeFacadeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void parseWrongLiteralContent(final String literal, final MessageReference messageReference) {
  try {
    EdmSimpleTypeKind.parseUriLiteral(literal);
    fail("Expected EdmLiteralException not thrown");
  } catch (EdmLiteralException e) {
    assertNotNull(e);
    assertEquals(messageReference.getKey(), e.getMessageReference().getKey());
  }
}
 
Example #18
Source File: EdmSimpleTypeFacadeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void parseBoolean() throws Exception {
  parseLiteral("true", EdmSimpleTypeKind.Boolean, "true");
  parseLiteral("false", EdmSimpleTypeKind.Boolean, "false");
  parseLiteral("1", EdmSimpleTypeKind.Boolean, "1");
  parseLiteral("0", EdmSimpleTypeKind.Boolean, "0");
}
 
Example #19
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void testPropertyIllegalStartWithNumber() throws Exception {

  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  SimpleProperty propertySimple = new SimpleProperty().setName("1_PropertyName").setType(EdmSimpleTypeKind.String);
  new EdmSimplePropertyImplProv(edmImplProv, propertySimple);
  expectedEx.expect(RuntimeException.class);
  expectedEx.expectMessage("'Prop;ertyName' name pattern not valid.");
}
 
Example #20
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EdmFunctionImportParameter readFunctionImportParameter(final XMLStreamReader reader)
    throws EntityProviderException, XMLStreamException, EdmException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_FUNCTION_PARAMETER);
  EdmFunctionImportParameter functionParameter = new EdmFunctionImportParameter();
  EdmAnnotationsImpl annotations = new EdmAnnotationsImpl();
  List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();

  functionParameter.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  functionParameter.setMode(reader.getAttributeValue(null, XmlMetadataConstants.EDM_FUNCTION_PARAMETER_MODE));
  String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE);
  if (type == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_FUNCTION_PARAMETER));
  }
  functionParameter.setType(EdmSimpleTypeKind.valueOf(extractFQName(type).getName()));
  EdmFacets facets = readFacets(reader);
  functionParameter.setFacets(facets);
  annotations.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
          && XmlMetadataConstants.EDM_FUNCTION_PARAMETER.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    annotations.setAnnotationElements(annotationElements);
  }
  functionParameter.setAnnotations(annotations);
  return functionParameter;
}
 
Example #21
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInt16Compatibility() {
  testCompatibility(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance(),
      Bit.getInstance(),
      Uint7.getInstance(),
      EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance(),
      EdmSimpleTypeKind.SByte.getEdmSimpleTypeInstance(),
      EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance());
  assertFalse(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance().isCompatible(
      EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()));
}
 
Example #22
Source File: JPATypeConverterTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertTypeTemporalTime() {
  testCase = "time";
  try {
    EdmSimpleTypeKind edmTimeType = JPATypeConverter.convertToEdmSimpleType(Calendar.class, new JPASimpleAttribute());
    assertEquals(EdmSimpleTypeKind.Time, edmTimeType);
  } catch (ODataJPAModelException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #23
Source File: JPATypeConverterTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertTypeTemporal() {
  testCase = "datetime";
  try {
    EdmSimpleTypeKind edmDateType = JPATypeConverter.convertToEdmSimpleType(Calendar.class, new JPASimpleAttribute());
    assertEquals(EdmSimpleTypeKind.DateTime, edmDateType);
  } catch (ODataJPAModelException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #24
Source File: JPATypeConverterTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertTypeCalendar() {
  try {
    assertEquals(EdmSimpleTypeKind.DateTime, JPATypeConverter.convertToEdmSimpleType(Calendar.class, null));
    assertEquals(EdmSimpleTypeKind.Time, JPATypeConverter.convertToEdmSimpleType(Time.class, null));
    assertEquals(EdmSimpleTypeKind.DateTime, JPATypeConverter.convertToEdmSimpleType(Date.class, null));
    assertEquals(EdmSimpleTypeKind.DateTime, JPATypeConverter.convertToEdmSimpleType(Timestamp.class, null));
    assertEquals(EdmSimpleTypeKind.DateTime, JPATypeConverter.convertToEdmSimpleType(java.sql.Date.class, null));
  } catch (ODataJPAModelException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    ;
  }
}
 
Example #25
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void valueToStringBinary() throws Exception {
  final byte[] binary = new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF };
  final EdmSimpleType instance = EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance();

  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, null));
  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.JSON, null));
  assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI, null));

  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(6)));
  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.JSON, getMaxLengthFacets(6)));
  assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI, getMaxLengthFacets(6)));
  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT,
      getMaxLengthFacets(Integer.MAX_VALUE)));
  assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI,
      getMaxLengthFacets(Integer.MAX_VALUE)));
  assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(null)));

  assertEquals("qg==", instance.valueToString(new Byte[] { new Byte((byte) 170) }, EdmLiteralKind.DEFAULT, null));

  expectErrorInValueToString(instance, binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(3),
      EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED);
  expectErrorInValueToString(instance, binary, EdmLiteralKind.JSON, getMaxLengthFacets(3),
      EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED);
  expectErrorInValueToString(instance, binary, EdmLiteralKind.URI, getMaxLengthFacets(3),
      EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED);

  expectErrorInValueToString(instance, 0, EdmLiteralKind.DEFAULT, null,
      EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED);
  expectErrorInValueToString(instance, binary, null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING);
}
 
Example #26
Source File: JPATypeConverterTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertTypeBlob() {
  testCase = "lob";
  try {
    assertEquals(EdmSimpleTypeKind.Binary, JPATypeConverter.convertToEdmSimpleType(Blob.class,
        new JPASimpleAttribute()));
  } catch (ODataJPAModelException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #27
Source File: JPATypeConverterTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertTypeByteArray() {
  try {
    assertEquals(EdmSimpleTypeKind.Binary, JPATypeConverter.convertToEdmSimpleType(Byte[].class, null));
  } catch (ODataJPAModelException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #28
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyUmlaut() throws Exception {
  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  SimpleProperty propertySimple = new SimpleProperty().setName("ÄropertyName").setType(EdmSimpleTypeKind.String);
  assertEquals("ÄropertyName", new EdmSimplePropertyImplProv(edmImplProv, propertySimple).getName());
}
 
Example #29
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInt32Compatibility() {
  testCompatibility(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance(),
      Bit.getInstance(),
      Uint7.getInstance(),
      EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance(),
      EdmSimpleTypeKind.SByte.getEdmSimpleTypeInstance(),
      EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance(),
      EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());
  assertFalse(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance().isCompatible(
      EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()));
}
 
Example #30
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void toUriLiteralDateTimeOffset() throws Exception {
  assertEquals("datetimeoffset'2009-12-26T21:23:38Z'", EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
      .toUriLiteral("2009-12-26T21:23:38Z"));
  assertEquals("datetimeoffset'2002-10-10T12:00:00-05:00'", EdmSimpleTypeKind.DateTimeOffset
      .getEdmSimpleTypeInstance().toUriLiteral("2002-10-10T12:00:00-05:00"));
}