Java Code Examples for org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind#getEdmSimpleTypeInstance()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind#getEdmSimpleTypeInstance() . 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: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void checkValueOfNull() throws Exception {
  for (EdmSimpleTypeKind kind : EdmSimpleTypeKind.values()) {
    if (kind == EdmSimpleTypeKind.Null) {
      continue;
    }
    final EdmSimpleType instance = kind.getEdmSimpleTypeInstance();
    assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, null, instance.getDefaultType()));
    assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, getNullableFacets(true), instance
        .getDefaultType()));
    assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, getNullableFacets(null), instance
        .getDefaultType()));

    expectErrorInValueOfString(instance, null, EdmLiteralKind.DEFAULT, getNullableFacets(false),
        EdmSimpleTypeException.LITERAL_NULL_NOT_ALLOWED);
    expectErrorInValueOfString(instance, "", null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING);
  }
}
 
Example 2
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void validate() throws Exception {
  for (EdmSimpleTypeKind kind : EdmSimpleTypeKind.values()) {
    if (kind == EdmSimpleTypeKind.Null) {
      continue;
    }
    final EdmSimpleType instance = kind.getEdmSimpleTypeInstance();
    assertTrue(instance.validate(null, null, null));
    assertTrue(instance.validate(null, null, getNullableFacets(null)));
    assertTrue(instance.validate(null, null, getNullableFacets(true)));
    assertFalse(instance.validate(null, null, getNullableFacets(false)));
    assertFalse(instance.validate("", null, null));
    assertFalse(instance.validate("ä", EdmLiteralKind.DEFAULT, getUnicodeFacets(false)));
    assertFalse(instance.validate("ä", EdmLiteralKind.URI, null));
  }

  assertTrue(EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance().validate("abcd", EdmLiteralKind.DEFAULT,
      getMaxLengthFacets(3)));
  assertFalse(EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance().validate("abcd", EdmLiteralKind.DEFAULT,
      getMaxLengthFacets(2)));

  assertTrue(EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance().validate("1.2", EdmLiteralKind.DEFAULT,
      getPrecisionScaleFacets(null, null)));
  assertFalse(EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance().validate("1.2", EdmLiteralKind.DEFAULT,
      getPrecisionScaleFacets(null, 0)));
}
 
Example 3
Source File: EdmSimpleTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkNull() throws Exception {
  for (EdmSimpleTypeKind kind : EdmSimpleTypeKind.values()) {
    if (kind == EdmSimpleTypeKind.Null) {
      continue;
    }
    final EdmSimpleType instance = kind.getEdmSimpleTypeInstance();
    assertNull(instance.valueToString(null, EdmLiteralKind.DEFAULT, null));
    assertNull(instance.valueToString(null, EdmLiteralKind.DEFAULT, getNullableFacets(true)));
    assertNull(instance.valueToString(null, EdmLiteralKind.DEFAULT, getNullableFacets(null)));

    expectErrorInValueToString(instance, null, EdmLiteralKind.DEFAULT, getNullableFacets(false),
        EdmSimpleTypeException.VALUE_NULL_NOT_ALLOWED);
  }
}
 
Example 4
Source File: EdmSimpleTypeFacadeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static void compare(final EdmSimpleTypeKind simpleType) {
  final EdmSimpleType bin1 = simpleType.getEdmSimpleTypeInstance();
  assertNotNull(bin1);

  final EdmSimpleType bin2 = simpleType.getEdmSimpleTypeInstance();
  assertNotNull(bin2);

  assertEquals(bin1, bin2);
}