[OLINGO-538] Fix: MetadataDocumentXmlSerializer serializes abstract property of complex types

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Christian Holzer 2015-01-19 10:31:34 +01:00 committed by Christian Amend
parent 2591c86c82
commit af64cb1fa9
2 changed files with 45 additions and 2 deletions

View File

@ -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);

View File

@ -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("<FunctionImport Name=\"FINRTInt16\" " +
"Function=\"Alias.UFNRTInt16\" IncludeInServiceDocument=\"true\"/>"));
}
@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");
ComplexType complexType = new ComplexType();
complexType.setAbstract(true);
complexType.setName(name.getName());
complexType.setOpenType(true);
List<Property> properties = new ArrayList<Property>();
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("<ComplexType Name=\"ComplexType\" Abstract=\"true\">"
+ "<Property Name=\"prop1\" Type=\"Edm.String\"/>"
+ "<Property Name=\"prop2\" Type=\"Edm.String\"/>"
+ "</ComplexType>"));
}
private class LocalProvider extends EdmProvider {
private final static String nameSpace = "namespace";