diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java index 2ab7809cf..d962d8266 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java @@ -58,6 +58,7 @@ import org.apache.olingo.server.api.serializer.ODataSerializer; public class MetadataDocumentXmlSerializer { + private static final String TRUE = "true"; private static final String XML_EXTENDS = "Extends"; private static final String XML_TARGET = "Target"; private static final String XML_PATH = "Path"; @@ -423,7 +424,11 @@ public class MetadataDocumentXmlSerializer { if (complexType.getBaseType() != null) { writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(complexType.getBaseType(), false)); } - + + if(complexType.isAbstract()) { + writer.writeAttribute(ABSTRACT, TRUE); + } + appendProperties(writer, complexType); appendNavigationProperties(writer, complexType); @@ -447,7 +452,7 @@ public class MetadataDocumentXmlSerializer { } if (entityType.isAbstract()) { - writer.writeAttribute(ABSTRACT, "true"); + writer.writeAttribute(ABSTRACT, TRUE); } appendKey(writer, entityType); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java index 55e527923..8b54fdf6a 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java @@ -34,6 +34,7 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.olingo.commons.api.ODataException; import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.FullQualifiedName; @@ -65,6 +66,7 @@ import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.core.ServiceMetadataImpl; +import org.apache.olingo.server.core.edm.provider.EdmComplexTypeImpl; import org.junit.BeforeClass; import org.junit.Test; @@ -227,7 +229,43 @@ public class MetadataDocumentXmlSerializerTest { assertTrue(metadata.contains("")); } + + @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 complexTypes = new ArrayList(); + FullQualifiedName name = new FullQualifiedName("namespace", "ComplexType"); + ComplexType complexType = new ComplexType(); + complexType.setAbstract(true); + complexType.setName(name.getName()); + complexType.setOpenType(true); + List properties = new ArrayList(); + + properties.add(new Property().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + properties.add(new Property().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + + complexType.setProperties(properties); + EdmComplexTypeImpl c1 = EdmComplexTypeImpl.getInstance(edm, name, complexType); + complexTypes.add(c1); + + when(schema.getComplexTypes()).thenReturn(complexTypes); + + + InputStream metadataStream = serializer.metadataDocument(serviceMetadata); + String metadata = IOUtils.toString(metadataStream); + + assertTrue(metadata.contains("" + + "" + + "" + + "")); + } + private class LocalProvider extends EdmProvider { private final static String nameSpace = "namespace";