@Test
public void writeAbstractComplexType() throws Exception {

  EdmSchema schema = mock(EdmSchema.class);
  when(schema.getNamespace()).thenReturn("MyNamespace");
  Edm edm = mock(Edm.class);
  when(edm.getSchemas()).thenReturn(Arrays.asList(schema));
  ServiceMetadata serviceMetadata = mock(ServiceMetadata.class);
  when(serviceMetadata.getEdm()).thenReturn(edm);
  List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
  FullQualifiedName name = new FullQualifiedName("namespace", "ComplexType");
  EdmComplexType complexType = mock(EdmComplexType.class);
  when(complexType.isAbstract()).thenReturn(true);
  when(complexType.getFullQualifiedName()).thenReturn(name);
  when(complexType.getName()).thenReturn(name.getName());
  when(complexType.isOpenType()).thenReturn(true);
  final EdmPrimitiveType stringType = OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
  when(complexType.getPropertyNames()).thenReturn(Arrays.asList("prop1", "prop2"));
  EdmProperty prop1 = mock(EdmProperty.class);
  when(prop1.isPrimitive()).thenReturn(true);
  when(prop1.getType()).thenReturn(stringType);
  when(prop1.isNullable()).thenReturn(true);
  when(prop1.getMaxLength()).thenReturn(null);
  when(prop1.getPrecision()).thenReturn(null);
  when(prop1.getScale()).thenReturn(null);
  when(prop1.isUnicode()).thenReturn(true);
  when(complexType.getStructuralProperty("prop1")).thenReturn(prop1);
  EdmProperty prop2 = mock(EdmProperty.class);
  when(prop2.isPrimitive()).thenReturn(true);
  when(prop2.getType()).thenReturn(stringType);
  when(prop2.isNullable()).thenReturn(true);
  when(prop2.getMaxLength()).thenReturn(null);
  when(prop2.getPrecision()).thenReturn(null);
  when(prop2.getScale()).thenReturn(null);
  when(prop2.isUnicode()).thenReturn(true);
  when(complexType.getStructuralProperty("prop2")).thenReturn(prop2);
  complexTypes.add(complexType);
  EdmComplexType c1 = mock(EdmComplexType.class);
  when(c1.getFullQualifiedName()).thenReturn(new FullQualifiedName("namespace", "C1"));
  when(c1.getName()).thenReturn("C1");
  when(c1.getBaseType()).thenReturn(complexType);
  complexTypes.add(c1);
  when(schema.getComplexTypes()).thenReturn(complexTypes);
  InputStream metadataStream = serializer.metadataDocument(serviceMetadata).getContent();
  String metadata = IOUtils.toString(metadataStream);
  assertTrue(metadata.contains("<ComplexType Name=\"ComplexType\" Abstract=\"true\" OpenType=\"true\">"
      + "<Property Name=\"prop1\" Type=\"Edm.String\"></Property>"
      + "<Property Name=\"prop2\" Type=\"Edm.String\"></Property>"
      + "</ComplexType>"));
}