[OLINGO-428] Fixed optional alias attribute for Schema
This commit is contained in:
parent
c9ce087e99
commit
3b9eb2fb8a
|
@ -79,6 +79,8 @@ public class MetadataDocumentXmlSerializer {
|
||||||
private static final String XML_TARGET_NAMESPACE = "TargetNamespace";
|
private static final String XML_TARGET_NAMESPACE = "TargetNamespace";
|
||||||
private static final String XML_QUALIFIER = "Qualifier";
|
private static final String XML_QUALIFIER = "Qualifier";
|
||||||
private static final String URI = "Uri";
|
private static final String URI = "Uri";
|
||||||
|
private static final String SCHEMA = "Schema";
|
||||||
|
private static final String DATA_SERVICES = "DataServices";
|
||||||
|
|
||||||
private final ServiceMetadata serviceMetadata;
|
private final ServiceMetadata serviceMetadata;
|
||||||
|
|
||||||
|
@ -88,8 +90,8 @@ public class MetadataDocumentXmlSerializer {
|
||||||
|
|
||||||
private final static String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm";
|
private final static String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm";
|
||||||
|
|
||||||
public MetadataDocumentXmlSerializer(final ServiceMetadata edm) {
|
public MetadataDocumentXmlSerializer(final ServiceMetadata serviceMetadata) {
|
||||||
this.serviceMetadata = edm;
|
this.serviceMetadata = serviceMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadataDocument(final XMLStreamWriter writer) throws XMLStreamException {
|
public void writeMetadataDocument(final XMLStreamWriter writer) throws XMLStreamException {
|
||||||
|
@ -108,7 +110,7 @@ public class MetadataDocumentXmlSerializer {
|
||||||
|
|
||||||
private void appendDataServices(final XMLStreamWriter writer) throws XMLStreamException {
|
private void appendDataServices(final XMLStreamWriter writer) throws XMLStreamException {
|
||||||
writer.setDefaultNamespace(NS_EDM);
|
writer.setDefaultNamespace(NS_EDM);
|
||||||
writer.writeStartElement(NS_EDMX, "DataServices");
|
writer.writeStartElement(NS_EDMX, DATA_SERVICES);
|
||||||
for (EdmSchema schema : serviceMetadata.getEdm().getSchemas()) {
|
for (EdmSchema schema : serviceMetadata.getEdm().getSchemas()) {
|
||||||
appendSchema(writer, schema);
|
appendSchema(writer, schema);
|
||||||
}
|
}
|
||||||
|
@ -116,10 +118,12 @@ public class MetadataDocumentXmlSerializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendSchema(final XMLStreamWriter writer, final EdmSchema schema) throws XMLStreamException {
|
private void appendSchema(final XMLStreamWriter writer, final EdmSchema schema) throws XMLStreamException {
|
||||||
writer.writeStartElement(NS_EDM, "Schema");
|
writer.writeStartElement(NS_EDM, SCHEMA);
|
||||||
writer.writeDefaultNamespace(NS_EDM);
|
writer.writeDefaultNamespace(NS_EDM);
|
||||||
writer.writeAttribute(XML_NAMESPACE, schema.getNamespace());
|
writer.writeAttribute(XML_NAMESPACE, schema.getNamespace());
|
||||||
writer.writeAttribute(XML_ALIAS, schema.getAlias());
|
if(schema.getAlias() != null) {
|
||||||
|
writer.writeAttribute(XML_ALIAS, schema.getAlias());
|
||||||
|
}
|
||||||
|
|
||||||
// EnumTypes
|
// EnumTypes
|
||||||
appendEnumTypes(writer, schema.getEnumTypes());
|
appendEnumTypes(writer, schema.getEnumTypes());
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.server.core.serializer.xml;
|
package org.apache.olingo.server.core.serializer.xml;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -257,14 +258,45 @@ public class MetadataDocumentTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>
|
* Write simplest (empty) Schema.
|
||||||
* <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml">
|
|
||||||
* <edmx:Include Namespace="Org.OData.Core.V1" Alias="Core"/>
|
|
||||||
* </edmx:Reference>
|
|
||||||
* </code>
|
|
||||||
*
|
*
|
||||||
* @return default emdx reference
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
|
public void writeMetadataWithEmptySchema() throws Exception {
|
||||||
|
ODataSerializer serializer = OData.newInstance().createSerializer(ODataFormat.XML);
|
||||||
|
List<EdmxReference> edmxReferences = Collections.emptyList();
|
||||||
|
ServiceMetadata serviceMetadata = new ServiceMetadataImpl(ODataServiceVersion.V40,
|
||||||
|
new EdmProvider() {
|
||||||
|
@Override
|
||||||
|
public List<Schema> getSchemas() throws ODataException {
|
||||||
|
return Arrays.asList(new Schema().setNamespace("MyNamespace"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
edmxReferences);
|
||||||
|
|
||||||
|
InputStream metadata = serializer.metadataDocument(serviceMetadata);
|
||||||
|
assertNotNull(metadata);
|
||||||
|
|
||||||
|
String metadataString = IOUtils.toString(metadata);
|
||||||
|
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
|
||||||
|
"<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
|
||||||
|
"<edmx:DataServices>" +
|
||||||
|
"<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNamespace\"/>" +
|
||||||
|
"</edmx:DataServices>" +
|
||||||
|
"</edmx:Edmx>",
|
||||||
|
metadataString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>
|
||||||
|
* <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml">
|
||||||
|
* <edmx:Include Namespace="Org.OData.Core.V1" Alias="Core"/>
|
||||||
|
* </edmx:Reference>
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @return default emdx reference
|
||||||
|
*/
|
||||||
private List<EdmxReference> getEdmxReferences() {
|
private List<EdmxReference> getEdmxReferences() {
|
||||||
List<EdmxReference> edmxReferences = new ArrayList<EdmxReference>();
|
List<EdmxReference> edmxReferences = new ArrayList<EdmxReference>();
|
||||||
EdmxReferenceImpl reference = new EdmxReferenceImpl(
|
EdmxReferenceImpl reference = new EdmxReferenceImpl(
|
||||||
|
|
Loading…
Reference in New Issue