Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#Stream

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#Stream . 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: ClientPrimitiveValueImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
  if (type == EdmPrimitiveTypeKind.Stream) {
    throw new IllegalArgumentException(String.format(
            "Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
  }
  if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
    throw new IllegalArgumentException(
            type + "is not an instantiable type. "
                    + "An entity can declare a property to be of type Geometry. "
                    + "An instance of an entity MUST NOT have a value of type Geometry. "
                    + "Each value MUST be of some subtype.");
  }

  instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
  instance.type = EdmPrimitiveTypeFactory.getInstance(instance.typeKind);

  return this;
}
 
Example 2
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));
}