Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#values()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#values() . 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: CoreUtils.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static EdmTypeInfo guessPrimitiveType(final EdmEnabledODataClient client, final Class<?> clazz) {
  EdmPrimitiveTypeKind bckCandidate = null;

  for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final Class<?> target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType();

    if (clazz.equals(target)) {
      return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build();
    } else if (target.isAssignableFrom(clazz)) {
      bckCandidate = kind;
    } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) {
      bckCandidate = kind;
    }
  }

  if (bckCandidate == null) {
    throw new IllegalArgumentException(clazz.getSimpleName() + " is not a simple type");
  } else {
    return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(bckCandidate.toString()).build();
  }
}
 
Example 2
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void compatibility() {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
    assertTrue(instance.isCompatible(instance));
    assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(
        (kind == EdmPrimitiveTypeKind.String ? EdmPrimitiveTypeKind.Binary : EdmPrimitiveTypeKind.String))));
  }
}
 
Example 3
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void validate() throws Exception {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
    assertTrue(instance.validate(null, null, null, null, null, null));
    assertTrue(instance.validate(null, true, null, null, null, null));
    assertFalse(instance.validate(null, false, null, null, null, null));
    if (kind != EdmPrimitiveTypeKind.Stream) {
      assertFalse(instance.validate("ä", null, null, null, null, false));
    }
    if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Binary
        && kind != EdmPrimitiveTypeKind.Stream) {

      assertFalse(instance.validate("", null, null, null, null, null));
    }
    if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Stream) {
      assertFalse(instance.validate("ä", null, null, null, null, null));
    }
  }

  assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).
      validate("abcd", null, 3, null, null, null));
  assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).
      validate("abcd", null, 2, null, null, null));

  assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).
      validate("1", null, null, null, null, null));
  assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).
      validate("1.2", null, null, null, 0, null));
}
 
Example 4
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void uriLiteral() throws Exception {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
    assertEquals("test", instance.fromUriLiteral(instance.toUriLiteral("test")));
    assertNull(instance.toUriLiteral(null));
    assertNull(instance.fromUriLiteral(null));
  }
}
 
Example 5
Source File: EdmNullTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkNull() throws Exception {
  for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
    assertNull(instance.valueToString(null, null, null, null, null, null));
    assertNull(instance.valueToString(null, true, null, null, null, null));

    expectNullErrorInValueToString(instance);
  }
}
 
Example 6
Source File: EdmNullTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkValueOfNull() throws Exception {
  for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
    assertNull(instance.valueOfString(null, null, null, null, null, null, instance.getDefaultType()));
    assertNull(instance.valueOfString(null, true, null, null, null, null, instance.getDefaultType()));

    expectNullErrorInValueOfString(instance);
  }
}
 
Example 7
Source File: EdmTypeDefinitionImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void compatibility() {
  assertTrue(instance.isCompatible(instance));
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    if (kind != EdmPrimitiveTypeKind.String) {
      assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind)));
    }
  }
}
 
Example 8
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void nameSpace() throws Exception {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    assertEquals(EdmPrimitiveType.EDM_NAMESPACE, EdmPrimitiveTypeFactory.getInstance(kind).getNamespace());
  }
}
 
Example 9
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void names() throws Exception {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    assertEquals(kind.name(), EdmPrimitiveTypeFactory.getInstance(kind).getName());
  }
}
 
Example 10
Source File: CommonPrimitiveTypeTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void toStringAll() throws Exception {
  for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    assertEquals(kind.getFullQualifiedName().toString(), EdmPrimitiveTypeFactory.getInstance(kind).toString());
  }
}