Java Code Examples for org.apache.olingo.commons.api.edm.provider.CsdlProperty#setType()

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlProperty#setType() . 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: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsComplexType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex");
  CsdlComplexType complexTypeProvider = new CsdlComplexType();
  when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(complexTypeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isCollection());
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.COMPLEX, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("complex", type.getName());
}
 
Example 2
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsEnumType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum");
  CsdlEnumType enumTypeProvider = new CsdlEnumType();
  when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(enumTypeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isCollection());
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.ENUM, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("enum", type.getName());
}
 
Example 3
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsTypeDefinition() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName typeName = new FullQualifiedName("ns", "definition");
  CsdlTypeDefinition typeProvider =
      new CsdlTypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String"));
  when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(typeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.DEFINITION, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("definition", type.getName());
}
 
Example 4
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void facets() {
  EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
  propertyProvider.setPrecision(42);
  propertyProvider.setScale(12);
  propertyProvider.setMaxLength(128);
  propertyProvider.setUnicode(true);
  propertyProvider.setNullable(false);
  propertyProvider.setDefaultValue("x");
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertTrue(property.isPrimitive());
  assertNull(property.getMapping());
  assertNull(property.getMimeType());
  assertEquals(Integer.valueOf(42), property.getPrecision());
  assertEquals(Integer.valueOf(12), property.getScale());
  assertEquals(Integer.valueOf(128), property.getMaxLength());
  assertTrue(property.isUnicode());
  assertFalse(property.isNullable());
  assertEquals("x", property.getDefaultValue());
  assertNull(property.getSrid());
}
 
Example 5
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void getTypeReturnsPrimitiveType() {
  EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(EdmPrimitiveTypeKind.Binary.getFullQualifiedName());
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertTrue(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
  assertEquals(EdmPrimitiveType.EDM_NAMESPACE, type.getNamespace());
  assertEquals(EdmPrimitiveTypeKind.Binary.toString(), type.getName());
}
 
Example 6
Source File: MetadataParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private CsdlProperty readProperty(XMLEventReader reader, StartElement element)
    throws XMLStreamException {
  CsdlProperty property = new CsdlProperty();
  property.setName(attr(element, "Name"));
  property.setType(readType(element));
  property.setCollection(isCollectionType(element));
  property.setNullable(Boolean.parseBoolean(attr(element, "Nullable") == null ? "true" : attr(
      element, "Nullable")));
  if (attr(element, "Unicode") != null) {
    property.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
  }

  String maxLength = attr(element, "MaxLength");
  if (maxLength != null) {
    property.setMaxLength(Integer.parseInt(maxLength));
  }
  String precision = attr(element, "Precision");
  if (precision != null) {
    property.setPrecision(Integer.parseInt(precision));
  }
  String scale = attr(element, "Scale");
  if (scale != null) {
    property.setScale(Integer.parseInt(scale));
  }
  String srid = attr(element, "SRID");
  if (srid != null) {
    property.setSrid(SRID.valueOf(srid));
  }
  String defaultValue = attr(element, "DefaultValue");
  if (defaultValue != null) {
    property.setDefaultValue(defaultValue);
  }
  peekAnnotations(reader, element.getName().getLocalPart(), property);
  return property;
}