Merge branch 'master' into olingo786

Conflicts:
	lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
	lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
	lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
	lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
	lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
	lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
This commit is contained in:
Christian Amend 2015-10-13 10:35:50 +02:00
commit b1d03d6ba9
37 changed files with 1430 additions and 925 deletions

View File

@ -936,7 +936,7 @@ public abstract class AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
@QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
@QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken,
@ -1038,7 +1038,7 @@ public abstract class AbstractServices {
* @param accept Accept header.
* @param name entity set or function name.
* @param format format query option.
* @param count inlinecount query option.
* @param count count query option.
* @param filter filter query option.
* @param orderby orderby query option.
* @param skiptoken skiptoken query option.
@ -1053,7 +1053,7 @@ public abstract class AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
@QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
@QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken) {

View File

@ -383,7 +383,7 @@ public class Services extends AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
@QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$search") @DefaultValue(StringUtils.EMPTY) final String search,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,

View File

@ -19,8 +19,6 @@
package org.apache.olingo.fit;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -30,39 +28,26 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.LifecycleException;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.domain.ClientEntity;
import org.apache.olingo.client.api.domain.ClientProperty;
import org.apache.olingo.client.api.domain.ClientValue;
import org.apache.olingo.client.api.serialization.ODataSerializerException;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.fit.server.TomcatTestServer;
import org.apache.olingo.server.tecsvc.TechnicalServlet;
import org.apache.olingo.server.tecsvc.async.TechnicalStatusMonitorServlet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractBaseTestITCase {
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
protected abstract ODataClient getClient();
private static TomcatTestServer server;
@BeforeClass
public static void init()
throws LifecycleException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
server = TomcatTestServer.init(9080)
.addServlet(TechnicalServlet.class, "/odata-server-tecsvc/odata.svc/*")
.addServlet(TechnicalStatusMonitorServlet.class, "/odata-server-tecsvc/status/*")
.addServlet(StaticContent.create("org-odata-core-v1.xml"),
"/odata-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
.addServlet(TechnicalServlet.class, "/odata-server-tecsvc/odata.svc/*")
.addServlet(TechnicalStatusMonitorServlet.class, "/odata-server-tecsvc/status/*")
.addServlet(StaticContent.create("org-odata-core-v1.xml"),
"/odata-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
.addWebApp(false)
.start();
}
@ -72,75 +57,6 @@ public abstract class AbstractBaseTestITCase {
server.invalidateAllSessions();
}
protected void debugEntity(final Entity entity, final String message) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
try {
getClient().getSerializer(ContentType.JSON).write(writer, entity);
} catch (final ODataSerializerException e) {
// Debug
}
writer.flush();
LOG.debug(message + "\n{}", writer.toString());
}
}
protected void debugEntitySet(final EntityCollection entitySet, final String message) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
try {
getClient().getSerializer(ContentType.JSON).write(writer, entitySet);
} catch (final ODataSerializerException e) {
// Debug
}
writer.flush();
LOG.debug(message + "\n{}", writer.toString());
}
}
protected void debugODataProperty(final ClientProperty property, final String message) {
LOG.debug(message + "\n{}", property.toString());
}
protected void debugODataValue(final ClientValue value, final String message) {
LOG.debug(message + "\n{}", value.toString());
}
protected void debugODataEntity(final ClientEntity entity, final String message) {
if (LOG.isDebugEnabled()) {
StringWriter writer = new StringWriter();
try {
getClient().getSerializer(ContentType.APPLICATION_ATOM_XML).write(writer, getClient().getBinder()
.getEntity(entity));
} catch (final ODataSerializerException e) {
// Debug
}
writer.flush();
LOG.debug(message + " (Atom)\n{}", writer.toString());
writer = new StringWriter();
try {
getClient().getSerializer(ContentType.JSON).write(writer, getClient().getBinder().getEntity(entity));
} catch (final ODataSerializerException e) {
// Debug
}
writer.flush();
LOG.debug(message + " (JSON)\n{}", writer.toString());
}
}
protected void debugInputStream(final InputStream input, final String message) {
if (LOG.isDebugEnabled()) {
try {
LOG.debug(message + "\n{}", IOUtils.toString(input));
} catch (IOException e) {
LOG.error("Error writing stream", e);
} finally {
IOUtils.closeQuietly(input);
}
}
}
public static class StaticContent extends HttpServlet {
private static final long serialVersionUID = -6663569573355398997L;
private final String resourceName;

View File

@ -185,7 +185,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
}
/**
* Test <tt>$inlinecount</tt>.
* Test <tt>$count</tt>.
*/
@Test
public void count() {

View File

@ -59,10 +59,9 @@ import org.junit.Test;
public class BatchClientITCase extends AbstractParamTecSvcITCase {
private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
private static final String ES_NOT_AVAILABLE_NAME = "ESNotAvailable";
private static final FullQualifiedName ES_NOT_AVAILABLE = new FullQualifiedName(SERVICE_NAMESPACE,
ES_NOT_AVAILABLE_NAME);
private static final FullQualifiedName ES_NOT_AVAILABLE =
new FullQualifiedName(SERVICE_NAMESPACE, ES_NOT_AVAILABLE_NAME);
private static final String PROPERTY_STRING = "PropertyString";
@Before

View File

@ -30,9 +30,13 @@ import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PingITCase extends AbstractBaseTestITCase {
private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class);
private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
private static final String REDIRECT_URI = TecSvcConst.BASE_URI;

View File

@ -72,9 +72,8 @@ public enum QueryOption {
*/
SKIP,
/**
* This query option applies only to the OData 2.0 protocol to the AtomPub protocol. The value of a $skiptoken query
* option is an opaque token which identifies an index into the collection of entities identified by the URI
* containing the $skiptoken parameter.
* The value of a $skiptoken query option is an opaque token which identifies an index into the collection
* of entities identified by the URI containing the $skiptoken parameter.
*/
SKIPTOKEN,
/**
@ -82,13 +81,6 @@ public enum QueryOption {
* section of the URI.
*/
FILTER,
/**
* For a value of "allpages", this option indicates that the response to the request MUST include the count of the
* number of entities in the EntitySet, identified by the resource path section of the URI after all $filter system
* query options have been applied. For a value of "none", this option indicates that the response to the request MUST
* NOT include the count value.
*/
INLINECOUNT,
/**
* Search expressions are used within the $search system query option to request entities matching the specified
* expression.

View File

@ -33,7 +33,7 @@ public abstract class AbstractClientEntitySet extends AbstractClientPayload impl
/**
* Number of ODataEntities contained in this entity set.
* <br/>
* If <tt>$inlinecount</tt> was requested, this value comes from there.
* If <tt>$count</tt> was requested, this value comes from there.
*/
private Integer count;

View File

@ -21,10 +21,9 @@ package org.apache.olingo.commons.core.edm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEnumType;
@ -42,21 +41,12 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private static final Set<EdmPrimitiveTypeKind> VALID_UNDERLYING_TYPES = new HashSet<EdmPrimitiveTypeKind>();
static {
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Byte);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.SByte);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int16);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int32);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int64);
}
private final EdmPrimitiveType underlyingType;
private final CsdlEnumType enumType;
private final String uriPrefix;
private final String uriSuffix;
private List<String> memberNames;
private LinkedHashMap<String, EdmMember> membersMap;
private Map<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final CsdlEnumType enumType) {
super(edm, enumName, EdmTypeKind.ENUM, enumType);
@ -64,12 +54,16 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
if (enumType.getUnderlyingType() == null) {
underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
} else {
EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
if (!VALID_UNDERLYING_TYPES.contains(underlyingTypeKind)) {
final EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
if (underlyingTypeKind == EdmPrimitiveTypeKind.Byte
|| underlyingTypeKind == EdmPrimitiveTypeKind.SByte
|| underlyingTypeKind == EdmPrimitiveTypeKind.Int16
|| underlyingTypeKind == EdmPrimitiveTypeKind.Int32
|| underlyingTypeKind == EdmPrimitiveTypeKind.Int64) {
underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
} else {
throw new EdmException("Not allowed as underlying type: " + underlyingTypeKind);
}
underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
}
this.enumType = enumType;
@ -99,7 +93,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
}
private void createEdmMembers() {
final LinkedHashMap<String, EdmMember> membersMapLocal = new LinkedHashMap<String, EdmMember>();
final Map<String, EdmMember> membersMapLocal = new LinkedHashMap<String, EdmMember>();
final List<String> memberNamesLocal = new ArrayList<String>();
if (enumType.getMembers() != null) {
for (final CsdlEnumMember member : enumType.getMembers()) {
@ -154,7 +148,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException {
throws EdmPrimitiveTypeException {
if (value == null) {
if (isNullable != null && !isNullable) {
@ -173,10 +167,9 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
}
}
private String constructEnumValue(final long value)
throws EdmPrimitiveTypeException {
private String constructEnumValue(final long value) throws EdmPrimitiveTypeException {
long remaining = value;
final StringBuilder result = new StringBuilder();
StringBuilder result = new StringBuilder();
final boolean flags = isFlags();
for (final EdmMember member : getMembers()) {
@ -228,16 +221,13 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public String toUriLiteral(final String literal) {
return literal == null ? null
: uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
return literal == null ? null : uriPrefix + literal + uriSuffix;
}
@Override
public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
if (literal == null) {
return null;
} else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
return literal;
} else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
&& literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
@ -250,29 +240,17 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public boolean isFlags() {
return enumType.isFlags();
}
@Override
public int hashCode() {
return this.getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
return getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
}
@Override
public boolean equals(Object obj){
if(obj == null){
return false;
}
if(obj == this){
return true;
}
if(obj instanceof EdmEnumType){
EdmEnumType other = (EdmEnumType) obj;
if(this.getFullQualifiedName().equals(other.getFullQualifiedName())){
return true;
}
}
return false;
public boolean equals(final Object obj) {
return obj != null
&& (obj == this
|| obj instanceof EdmEnumType
&& getFullQualifiedName().equals(((EdmEnumType) obj).getFullQualifiedName()));
}
}

View File

@ -30,41 +30,24 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDefinition {
public class EdmTypeDefinitionImpl extends EdmTypeImpl implements EdmTypeDefinition {
private CsdlTypeDefinition typeDefinition;
private FullQualifiedName typeDefinitionName;
private EdmPrimitiveType edmPrimitiveTypeInstance;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final CsdlTypeDefinition typeDefinition) {
super(edm, typeDefinitionName.getName(), typeDefinition);
this.typeDefinitionName = typeDefinitionName;
super(edm, typeDefinitionName, EdmTypeKind.DEFINITION, typeDefinition);
this.typeDefinition = typeDefinition;
}
@Override
public FullQualifiedName getFullQualifiedName() {
return typeDefinitionName;
}
@Override
public String getNamespace() {
return typeDefinitionName.getNamespace();
}
@Override
public EdmTypeKind getKind() {
return EdmTypeKind.DEFINITION;
}
@Override
public EdmPrimitiveType getUnderlyingType() {
if (edmPrimitiveTypeInstance == null) {
try {
if (typeDefinition.getUnderlyingType() == null) {
throw new EdmException("Underlying Type for type definition: "
+ typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
+ typeName.getFullQualifiedNameAsString() + " must not be null.");
}
edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
@ -102,7 +85,7 @@ public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDe
@Override
public boolean isCompatible(final EdmPrimitiveType primitiveType) {
return getUnderlyingType().isCompatible(primitiveType);
return this == primitiveType || getUnderlyingType().isCompatible(primitiveType);
}
@Override
@ -112,27 +95,34 @@ public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDe
@Override
public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale,
final Boolean isUnicode) {
return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode);
final Integer precision, final Integer scale, final Boolean isUnicode) {
return getUnderlyingType().validate(value, isNullable,
maxLength == null ? getMaxLength() : maxLength,
precision == null ? getPrecision() : precision,
scale == null ? getScale() : scale,
isUnicode == null ? isUnicode() : isUnicode);
}
@Override
public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale,
final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
return getUnderlyingType().
valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException {
return getUnderlyingType().valueOfString(value, isNullable,
maxLength == null ? getMaxLength() : maxLength,
precision == null ? getPrecision() : precision,
scale == null ? getScale() : scale,
isUnicode == null ? isUnicode() : isUnicode,
returnType);
}
@Override
public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale,
final Boolean isUnicode) throws EdmPrimitiveTypeException {
return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
return getUnderlyingType().valueToString(value, isNullable,
maxLength == null ? getMaxLength() : maxLength,
precision == null ? getPrecision() : precision,
scale == null ? getScale() : scale,
isUnicode == null ? isUnicode() : isUnicode);
}
@Override

View File

@ -0,0 +1,354 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.edm;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.List;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.junit.Test;
public class EdmEnumTest {
private final EdmEnumType instance;
private final EdmEnumType otherInstance;
private final EdmEnumType nonFlagsInstance;
private final EdmEnumType int16EnumType;
private final EdmEnumType int32EnumType;
private final EdmEnumType int32FlagType;
public EdmEnumTest() {
final List<CsdlEnumMember> memberList = Arrays.asList(
new CsdlEnumMember().setName("first").setValue("1"),
new CsdlEnumMember().setName("second").setValue("64"));
final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
instance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
otherInstance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
nonFlagsInstance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
int16EnumType = new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType().setName("MyEnum")
.setFlags(false)
.setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
.setMembers(Arrays.asList(
new CsdlEnumMember().setName("A").setValue("0"),
new CsdlEnumMember().setName("B").setValue("1"),
new CsdlEnumMember().setName("C").setValue("2"))));
int32EnumType = new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType().setName("MyEnum")
.setFlags(false)
.setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
.setMembers(Arrays.asList(
new CsdlEnumMember().setName("A").setValue("0"),
new CsdlEnumMember().setName("B").setValue("1"),
new CsdlEnumMember().setName("C").setValue("2"))));
int32FlagType = new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType().setName("MyEnum")
.setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
.setMembers(Arrays.asList(
new CsdlEnumMember().setName("A").setValue("2"),
new CsdlEnumMember().setName("B").setValue("4"),
new CsdlEnumMember().setName("C").setValue("8"))));
}
@Test
public void nameSpace() throws Exception {
assertEquals("namespace", instance.getNamespace());
}
@Test
public void name() throws Exception {
assertEquals("name", instance.getName());
}
@Test
public void kind() throws Exception {
assertEquals(EdmTypeKind.ENUM, instance.getKind());
}
@Test
public void compatibility() {
assertTrue(instance.isCompatible(instance));
assertTrue(instance.isCompatible(otherInstance));
assertFalse(instance.isCompatible(instance.getUnderlyingType()));
}
@Test
public void defaultType() throws Exception {
assertEquals(Byte.class, instance.getDefaultType());
EdmEnumType instance = new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType().setName("MyEnum"));
assertEquals(Integer.class, instance.getUnderlyingType().getDefaultType());
}
@Test
public void members() throws Exception {
assertArrayEquals(new String[] { "first", "second" }, instance.getMemberNames().toArray());
assertEquals("64", instance.getMember("second").getValue());
assertNull(instance.getMember("notExisting"));
}
@Test
public void underlyingType() throws Exception {
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
}
@Test
public void validate() throws Exception {
assertTrue(instance.validate(null, null, null, null, null, null));
assertTrue(instance.validate(null, true, null, null, null, null));
assertFalse(instance.validate(null, false, null, null, null, null));
assertFalse(instance.validate("", null, null, null, null, null));
assertFalse(instance.validate("something", null, null, null, null, null));
assertTrue(instance.validate("second", null, null, null, null, null));
assertTrue(instance.validate("first,second", null, null, null, null, null));
assertTrue(instance.validate("64", null, null, null, null, null));
assertTrue(instance.validate("1,64", null, null, null, null, null));
}
@Test
public void toUriLiteral() throws Exception {
assertNull(instance.toUriLiteral(null));
assertEquals("namespace.name'first'", instance.toUriLiteral("first"));
}
@Test
public void fromUriLiteral() throws Exception {
assertNull(instance.fromUriLiteral(null));
assertEquals("first", instance.fromUriLiteral("namespace.name'first'"));
expectErrorInFromUriLiteral(instance, "");
expectErrorInFromUriLiteral(instance, "name'first'");
expectErrorInFromUriLiteral(instance, "namespace.name'first");
expectErrorInFromUriLiteral(instance, "namespace.namespace'first");
}
@Test
public void valueToString() throws Exception {
assertNull(instance.valueToString(null, null, null, null, null, null));
assertNull(instance.valueToString(null, true, null, null, null, null));
assertEquals("first", instance.valueToString(1, null, null, null, null, null));
assertEquals("first", instance.valueToString((byte) 1, null, null, null, null, null));
assertEquals("first", instance.valueToString((short) 1, null, null, null, null, null));
assertEquals("second", instance.valueToString(Integer.valueOf(64), null, null, null, null, null));
assertEquals("second", instance.valueToString(64L, null, null, null, null, null));
assertEquals("first,second", instance.valueToString(65, null, null, null, null, null));
expectNullErrorInValueToString(instance);
expectContentErrorInValueToString(instance, 3);
expectTypeErrorInValueToString(instance, 1.0);
assertEquals("A", int32EnumType.valueToString(0, false, 0, 0, 0, false));
assertEquals("B", int32EnumType.valueToString(1, false, 0, 0, 0, false));
assertEquals("C", int32EnumType.valueToString(2, false, 0, 0, 0, false));
assertEquals("A", int16EnumType.valueToString(0, false, 0, 0, 0, false));
assertEquals("B", int16EnumType.valueToString(1, false, 0, 0, 0, false));
assertEquals("C", int16EnumType.valueToString(2, false, 0, 0, 0, false));
assertEquals("A", int32FlagType.valueToString(2, false, 0, 0, 0, false));
assertEquals("B", int32FlagType.valueToString(4, false, 0, 0, 0, false));
assertEquals("C", int32FlagType.valueToString(8, false, 0, 0, 0, false));
assertEquals("A,B", int32FlagType.valueToString(0x2 + 0x4, false, 0, 0, 0, false));
assertEquals("B,C", int32FlagType.valueToString(0x4 + 0x8, false, 0, 0, 0, false));
}
@Test
public void valueOfString() throws Exception {
assertNull(instance.valueOfString(null, null, null, null, null, null, Byte.class));
assertNull(instance.valueOfString(null, true, null, null, null, null, Byte.class));
assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", null, null, null, null, null, Short.class));
assertEquals(Integer.valueOf(1), instance.valueOfString("1", null, null, null, null, null, Integer.class));
assertEquals(Long.valueOf(64L), instance.valueOfString("64", null, null, null, null, null, Long.class));
assertEquals(Long.valueOf(1), instance.valueOfString("first", null, null, null, null, null, Long.class));
assertEquals(Byte.valueOf((byte) 65), instance.valueOfString("first,64", null, null, null, null, null, Byte.class));
assertEquals(Integer.valueOf(1), instance.valueOfString("1,1,first", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(1), nonFlagsInstance.valueOfString("1", null, null, null, null, null, Integer.class));
expectContentErrorInValueOfString(nonFlagsInstance, "1,64");
expectNullErrorInValueOfString(instance);
expectContentErrorInValueOfString(instance, "2");
expectContentErrorInValueOfString(instance, "1,");
expectContentErrorInValueOfString(instance, ",1");
expectTypeErrorInValueOfString(instance, "1");
assertEquals(Integer.valueOf(0), int32EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(1), int32EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(2), int32EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(0), int16EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(1), int16EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(2), int16EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(2), int32FlagType.valueOfString("A", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(4), int32FlagType.valueOfString("B", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(8), int32FlagType.valueOfString("C", null, null, null, null, null, Integer.class));
assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("A,B", null, null, null, null, null,
Integer.class));
assertEquals(Integer.valueOf(0x4 + 0x8), int32FlagType.valueOfString("B,C", null, null, null, null, null,
Integer.class));
assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("B,A", null, null, null, null, null,
Integer.class));
}
private void expectErrorInValueToString(final EdmEnumType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String message) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
private void expectErrorInUnderlyingType(final EdmPrimitiveTypeKind underlyingType, final String message) {
try {
new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType()
.setName("MyEnum")
.setFlags(false)
.setUnderlyingType(underlyingType.getFullQualifiedName())
.setMembers(Arrays.asList(
new CsdlEnumMember().setName("A").setValue("0"))));
fail("Expected exception not thrown");
} catch (final EdmException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
@Test
public void unsupportedUnderlyingType() throws Exception {
// Test some random unsupported types
expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Date, "");
expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Geography, "");
expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Guid, "");
}
@Test
public void outOfRangeValueToString() throws Exception {
expectErrorInValueToString(int16EnumType, Integer.MAX_VALUE, null, null, null, null, null, "");
}
protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
try {
instance.fromUriLiteral(value);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
}
}
private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String message) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
}
protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, null, null, null, null, null, "value type");
}
protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid.");
}
private void expectErrorInValueOfString(final EdmPrimitiveType instance,
final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode, final Class<?> returnType,
final String message) {
try {
instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
"The value type class java.lang.Class is not supported.");
}
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
"illegal content");
}
protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
"The literal 'null' is not allowed.");
}
}

View File

@ -0,0 +1,137 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.edm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.apache.olingo.commons.api.edm.EdmAnnotationsTarget.TargetType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.commons.core.edm.primitivetype.PrimitiveTypeBaseTest;
import org.junit.Test;
public class EdmTypeDefinitionTest extends PrimitiveTypeBaseTest {
private final EdmPrimitiveType instance = new EdmTypeDefinitionImpl(null,
new FullQualifiedName("namespace", "def"),
new CsdlTypeDefinition().setName("def")
.setUnderlyingType(EdmString.getInstance().getFullQualifiedName())
.setMaxLength(5)
.setUnicode(false));
@Test
public void defaultType() throws Exception {
assertEquals(String.class, instance.getDefaultType());
}
@Test
public void compatibility() {
assertTrue(instance.isCompatible(instance));
for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
if (kind != EdmPrimitiveTypeKind.String) {
assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind)));
}
}
}
@Test
public void toUriLiteral() throws Exception {
assertEquals("'Value'", instance.toUriLiteral("Value"));
}
@Test
public void fromUriLiteral() throws Exception {
assertEquals("Value", instance.fromUriLiteral("'Value'"));
}
@Test
public void valueToString() throws Exception {
assertEquals("text", instance.valueToString("text", null, null, null, null, null));
expectFacetsErrorInValueToString(instance, "longtext", null, null, null, null, null);
expectFacetsErrorInValueToString(instance, "text", null, 3, null, null, null);
expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, null);
expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, false);
}
@Test
public void valueOfString() throws Exception {
assertEquals("text", instance.valueOfString("text", null, null, null, null, null, String.class));
expectFacetsErrorInValueOfString(instance, "longtext", null, null, null, null, null);
expectFacetsErrorInValueOfString(instance, "text", null, 3, null, null, null);
expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, null);
expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, false);
expectTypeErrorInValueOfString(instance, "text");
}
@Test
public void typeDefOnStringNoFacets() throws Exception {
final EdmTypeDefinition typeDef = new EdmTypeDefinitionImpl(null,
new FullQualifiedName("namespace", "name"),
new CsdlTypeDefinition().setName("typeDef")
.setUnderlyingType(EdmString.getInstance().getFullQualifiedName()));
assertEquals("name", typeDef.getName());
assertEquals("namespace", typeDef.getNamespace());
assertEquals(new FullQualifiedName("namespace", "name"), typeDef.getFullQualifiedName());
assertEquals(String.class, typeDef.getDefaultType());
assertEquals(EdmTypeKind.DEFINITION, typeDef.getKind());
assertEquals(EdmString.getInstance(), typeDef.getUnderlyingType());
assertTrue(typeDef.isCompatible(EdmString.getInstance()));
assertEquals(TargetType.TypeDefinition, typeDef.getAnnotationsTargetType());
assertEquals(typeDef.getFullQualifiedName(), typeDef.getAnnotationsTargetFQN());
assertEquals(typeDef.getName(), typeDef.getAnnotationsTargetPath());
// String validation
assertEquals("'StringValue'", typeDef.toUriLiteral("StringValue"));
assertEquals("String''Value", typeDef.fromUriLiteral("'String''''Value'"));
assertTrue(typeDef.validate("text", null, null, null, null, null));
assertEquals("text", typeDef.valueToString("text", null, null, null, null, null));
assertEquals("text", typeDef.valueOfString("text", null, null, null, null, null, String.class));
// Facets must be initial
assertNull(typeDef.getMaxLength());
assertNull(typeDef.getPrecision());
assertNull(typeDef.getScale());
assertNull(typeDef.getSrid());
assertTrue(typeDef.isUnicode());
}
@Test(expected = EdmException.class)
public void invalidTypeResultsInEdmException() throws Exception {
new EdmTypeDefinitionImpl(null,
new FullQualifiedName("namespace", "name"),
new CsdlTypeDefinition().setName("typeDef")
.setUnderlyingType(new FullQualifiedName("wrong", "wrong")))
.getUnderlyingType();
}
}

View File

@ -71,19 +71,16 @@ import com.fasterxml.aalto.stax.InputFactoryImpl;
public class ODataXmlDeserializer implements ODataDeserializer {
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
private static final String ATOM = "a";
private static final QName REF_ELEMENT = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
private static final QName PARAMETERS_ELEMENT = new QName(Constants.NS_METADATA, "parameters");
private static final QName ID_ATTR = new QName(Constants.NS_ATOM, ATOM);
private final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
private final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
private final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
private final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
private final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
private final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
private final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
private final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
private static final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
private static final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
private static final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
private static final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
private static final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
private static final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
private static final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
private static final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
private static final QName parametersQName = new QName(Constants.NS_METADATA, "parameters");
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
return FACTORY.createXMLEventReader(input);
@ -330,7 +327,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
link.setInlineEntitySet(entitySet(reader, inline, navigationProperty.getType()));
}
}
} else if (REF_ELEMENT.equals(event.asStartElement().getName())) {
} else if (entryRefQName.equals(event.asStartElement().getName())) {
if (navigationProperty.isCollection()) {
throw new DeserializerException("Binding annotation: " + link.getTitle() +
" must be collection of entity refercences",
@ -362,7 +359,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && REF_ELEMENT.equals(event.asStartElement().getName())) {
if (event.isStartElement() && entryRefQName.equals(event.asStartElement().getName())) {
references.add(entityRef(reader, event.asStartElement()));
}
@ -671,11 +668,8 @@ public class ODataXmlDeserializer implements ODataDeserializer {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
StartElement start = event.asStartElement();
if (REF_ELEMENT.equals(start.getName())) {
Attribute context = start.getAttributeByName(ID_ATTR);
if (context == null) {
context = start.getAttributeByName(new QName("id"));
}
if (entryRefQName.equals(start.getName())) {
Attribute context = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
URI uri = URI.create(context.getValue());
references.add(uri);
}
@ -683,8 +677,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
}
return DeserializerResultImpl.with().entityReferences(references).build();
} catch (XMLStreamException e) {
throw new DeserializerException("An IOException occurred", e,
DeserializerException.MessageKeys.IO_EXCEPTION);
throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@ -702,7 +695,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
final XMLEventReader reader = getReader(stream);
while (reader.hasNext()) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && PARAMETERS_ELEMENT.equals(event.asStartElement().getName())) {
if (event.isStartElement() && parametersQName.equals(event.asStartElement().getName())) {
consumeParameters(edmAction, reader, event.asStartElement(), parameters);
}
}
@ -765,7 +758,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
}
}
if (!found) {
throw new DeserializerException("failed to read "+event.asStartElement().getName().getLocalPart(),
throw new DeserializerException("failed to read " + event.asStartElement().getName().getLocalPart(),
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
}

View File

@ -25,7 +25,7 @@ import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
public abstract class AbstractODataSerializer implements ODataSerializer {
protected static final String IO_EXCEPTION_TEXT = "An I/O exception occurred.";
protected void closeCircleStreamBufferOutput(OutputStream outputStream, SerializerException cachedException)
@ -37,11 +37,10 @@ public abstract class AbstractODataSerializer implements ODataSerializer {
if (cachedException != null) {
throw cachedException;
} else {
throw new SerializerException("An I/O exception occurred.", e,
throw new SerializerException(IO_EXCEPTION_TEXT, e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
}
}

View File

@ -42,7 +42,9 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataServerError;
@ -399,25 +401,25 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
private void writePropertyValue(final EdmProperty edmProperty,
final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json)
throws IOException, SerializerException {
final EdmType type = edmProperty.getType();
try {
if (edmProperty.isPrimitive()) {
if (edmProperty.isPrimitive()
|| type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) {
if (edmProperty.isCollection()) {
writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
writePrimitiveCollection((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
} else {
writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
writePrimitive((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
}
} else if (edmProperty.isCollection()) {
writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
} else if (property.isComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex().getValue(), selectedPaths, json);
} else if (property.isEnum()) {
writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
if (edmProperty.isCollection()) {
writeComplexCollection((EdmComplexType) type, property, selectedPaths, json);
} else {
writeComplexValue((EdmComplexType) type, property.asComplex().getValue(), selectedPaths, json);
}
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@ -437,6 +439,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
for (Object value : property.asCollection()) {
switch (property.getValueType()) {
case COLLECTION_PRIMITIVE:
case COLLECTION_ENUM:
try {
writePrimitiveValue(type, value, isNullable, maxLength, precision, scale, isUnicode, json);
} catch (EdmPrimitiveTypeException e) {
@ -448,9 +451,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
case COLLECTION_GEOSPATIAL:
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
case COLLECTION_ENUM:
json.writeString(value.toString());
break;
default:
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());

View File

@ -21,7 +21,6 @@ package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
@ -73,48 +72,42 @@ public class ServiceDocumentJsonSerializer {
gen.writeArrayFieldStart(Constants.VALUE);
final Edm edm = metadata.getEdm();
writeEntitySets(gen, edm);
writeFunctionImports(gen, edm);
writeSingletons(gen, edm);
final EdmEntityContainer container = metadata.getEdm().getEntityContainer();
writeEntitySets(gen, container);
writeFunctionImports(gen, container);
writeSingletons(gen, container);
}
private void writeEntitySets(final JsonGenerator gen, final Edm edm) throws IOException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
if (edmEntitySet.isIncludeInServiceDocument()) {
gen.writeStartObject();
gen.writeObjectField(Constants.JSON_NAME, edmEntitySet.getName());
gen.writeObjectField(Constants.JSON_URL, edmEntitySet.getName());
gen.writeEndObject();
writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName());
}
}
}
private void writeFunctionImports(final JsonGenerator gen, final Edm edm) throws IOException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeFunctionImports(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
if (edmFunctionImport.isIncludeInServiceDocument()) {
gen.writeStartObject();
gen.writeObjectField(Constants.JSON_NAME, edmFunctionImport.getName());
gen.writeObjectField(Constants.JSON_URL, edmFunctionImport.getName());
gen.writeObjectField(KIND, FUNCTION_IMPORT);
gen.writeEndObject();
writeElement(gen, FUNCTION_IMPORT, edmFunctionImport.getName(), edmFunctionImport.getName());
}
}
}
private void writeSingletons(final JsonGenerator gen, final Edm edm) throws IOException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeSingletons(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmSingleton edmSingleton : container.getSingletons()) {
gen.writeStartObject();
gen.writeObjectField(Constants.JSON_NAME, edmSingleton.getName());
gen.writeObjectField(Constants.JSON_URL, edmSingleton.getName());
gen.writeObjectField(KIND, SINGLETON);
gen.writeEndObject();
writeElement(gen, SINGLETON, edmSingleton.getName(), edmSingleton.getName());
}
}
private void writeElement(JsonGenerator gen, final String kind, final String reference, final String title)
throws IOException {
gen.writeStartObject();
gen.writeObjectField(Constants.JSON_NAME, title);
gen.writeObjectField(Constants.JSON_URL, reference);
if (kind != null) {
gen.writeObjectField(KIND, kind);
}
gen.writeEndObject();
}
}

View File

@ -31,7 +31,6 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
@ -49,13 +48,14 @@ import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
@ -72,16 +72,14 @@ import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
public class ODataXmlSerializer extends AbstractODataSerializer {
private static final String CONTEXT = "context";
/** The default character set is UTF-8. */
public static final String DEFAULT_CHARSET = "UTF-8";
public static final String DEFAULT_CHARSET = Constants.UTF8;
private static final String ATOM = "a";
private static final String NS_ATOM = Constants.NS_ATOM;
private static final String METADATA = "m";
private static final String METADATA = Constants.PREFIX_METADATA;
private static final String NS_METADATA = Constants.NS_METADATA;
private static final String DATA = "d";
private static final String DATA = Constants.PREFIX_DATASERVICES;
private static final String NS_DATA = Constants.NS_DATASERVICES;
private static final String NS_SCHEMA = Constants.NS_SCHEME;
@Override
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
@ -155,13 +153,13 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement("error");
writer.writeDefaultNamespace(NS_METADATA);
writeErrorDetails(String.valueOf(error.getStatusCode()), error.getMessage(), error.getTarget(), writer);
if (error.getDetails() != null && !error.getDetails().isEmpty()) {
writer.writeStartElement("details");
writer.writeStartElement(Constants.ERROR_DETAILS);
for (ODataErrorDetail inner : error.getDetails()) {
writeErrorDetails(inner.getCode(), inner.getMessage(), inner.getTarget(), writer);
}
@ -191,17 +189,17 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeErrorDetails(String code, String message, String target, XMLStreamWriter writer)
throws XMLStreamException {
if (code != null) {
writer.writeStartElement("code");
writer.writeCharacters(String.valueOf(code));
writer.writeStartElement(Constants.ERROR_CODE);
writer.writeCharacters(code);
writer.writeEndElement();
}
writer.writeStartElement("message");
writer.writeStartElement(Constants.ERROR_MESSAGE);
writer.writeCharacters(message);
writer.writeEndElement();
if (target != null) {
writer.writeStartElement("target");
writer.writeStartElement(Constants.ERROR_TARGET);
writer.writeCharacters(target);
writer.writeEndElement();
}
@ -225,18 +223,18 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartElement(ATOM, "feed", NS_ATOM);
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
writer.writeAttribute(METADATA, NS_METADATA, "context",
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
if (options != null && options.getId() != null) {
writer.writeStartElement(ATOM, "id", NS_ATOM);
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ID, NS_ATOM);
writer.writeCharacters(options.getId());
writer.writeEndElement();
}
@ -293,7 +291,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writeEntity(metadata, entityType, entity, contextURL,
options == null ? null : options.getExpand(),
options == null ? null : options.getSelect(), writer, true);
@ -329,7 +327,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
if (metadata != null
&& metadata.getServiceMetadataETagSupport() != null
&& metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
writer.writeAttribute(METADATA, NS_METADATA, "metadata-etag",
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG,
metadata.getServiceMetadataETagSupport().getMetadataETag());
}
}
@ -347,25 +345,24 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final SelectOption select, final XMLStreamWriter writer, final boolean top)
throws XMLStreamException, SerializerException {
writer.writeStartElement(ATOM, "entry", NS_ATOM);
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ENTRY, NS_ATOM);
if (top) {
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
if (contextURL != null) { // top-level entity
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
}
}
if (entity.getETag() != null) {
writer.writeAttribute(METADATA, NS_METADATA, "etag", entity.getETag());
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_ETAG, entity.getETag());
}
if (entity.getId() != null) {
writer.writeStartElement(NS_ATOM, "id");
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_ID);
writer.writeCharacters(entity.getId().toASCIIString());
writer.writeEndElement();
}
@ -373,24 +370,21 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
writerAuthorInfo(entity.getTitle(), writer);
if (entity.getId() != null) {
writer.writeStartElement(NS_ATOM, "link");
writer.writeAttribute("rel", "edit");
writer.writeAttribute("href", entity.getId().toASCIIString());
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_LINK);
writer.writeAttribute(Constants.ATTR_REL, Constants.EDIT_LINK_REL);
writer.writeAttribute(Constants.ATTR_HREF, entity.getId().toASCIIString());
writer.writeEndElement();
}
if (entityType.hasStream()) {
writer.writeStartElement(NS_ATOM, "content");
writer.writeAttribute("type", entity.getMediaContentType());
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT);
writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
if (entity.getMediaContentSource() != null) {
writer.writeAttribute("src", entity.getMediaContentSource().toString());
writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toString());
} else {
String id = entity.getId().toASCIIString();
if (id.endsWith("/")) {
writer.writeAttribute("src", id + "$value");
} else {
writer.writeAttribute("src", id + "/$value");
}
writer.writeAttribute(Constants.ATOM_ATTR_SRC,
id + (id.endsWith("/") ? "" : "/") + "$value");
}
writer.writeEndElement();
}
@ -403,18 +397,19 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
writeNavigationProperties(metadata, resolvedType, entity, expand, writer);
writer.writeStartElement(ATOM, "category", NS_ATOM);
writer.writeAttribute("scheme", NS_SCHEMA);
writer.writeAttribute("term", "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_CATEGORY, NS_ATOM);
writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME);
writer.writeAttribute(Constants.ATOM_ATTR_TERM,
"#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement();
// In the case media, content is sibiling
if (!entityType.hasStream()) {
writer.writeStartElement(NS_ATOM, "content");
writer.writeAttribute("type", "application/xml");
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT);
writer.writeAttribute(Constants.ATTR_TYPE, "application/xml");
}
writer.writeStartElement(METADATA, "properties", NS_METADATA);
writer.writeStartElement(METADATA, Constants.PROPERTIES, NS_METADATA);
writeProperties(metadata, resolvedType, entity.getProperties(), select, writer);
writer.writeEndElement(); // properties
@ -425,15 +420,15 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(NS_ATOM, "title");
writer.writeStartElement(NS_ATOM, Constants.ATTR_TITLE);
if (title != null) {
writer.writeCharacters(title);
}
writer.writeEndElement();
writer.writeStartElement(NS_ATOM, "summary");
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_SUMMARY);
writer.writeEndElement();
writer.writeStartElement(NS_ATOM, "updated");
writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_UPDATED);
writer.writeCharacters(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis())));
writer.writeEndElement();
@ -528,7 +523,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
if (navigationLink != null) {
writeLink(writer, navigationLink, false);
writer.writeStartElement(METADATA, "inline", NS_METADATA);
writer.writeStartElement(METADATA, Constants.ATOM_ELEM_INLINE, NS_METADATA);
writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(),
@ -573,16 +568,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeLink(final XMLStreamWriter writer, final Link link, final boolean close)
throws XMLStreamException {
writer.writeStartElement(ATOM, "link", NS_ATOM);
writer.writeAttribute("rel", link.getRel());
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
writer.writeAttribute(Constants.ATTR_REL, link.getRel());
if (link.getType() != null) {
writer.writeAttribute("type", link.getType());
writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
}
if (link.getTitle() != null) {
writer.writeAttribute("title", link.getTitle());
writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
}
if (link.getHref() != null) {
writer.writeAttribute("href", link.getHref());
writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
}
if (close) {
writer.writeEndElement();
@ -595,7 +590,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throws XMLStreamException, SerializerException {
if (property.isCollection()) {
if (navigationLink != null && navigationLink.getInlineEntitySet() != null) {
writer.writeStartElement(ATOM, "feed", NS_ATOM);
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand,
innerSelect, writer);
writer.writeEndElement();
@ -615,7 +610,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA);
if (property == null || property.isNull()) {
if (edmProperty.isNullable()) {
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
throw new SerializerException("Non-nullable property not present!",
SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
@ -648,9 +643,14 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Property property, final Set<List<String>> selectedPaths,
final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
try {
if (edmProperty.isPrimitive()) {
if (edmProperty.isPrimitive()
|| edmProperty.getType().getKind() == EdmTypeKind.ENUM
|| edmProperty.getType().getKind() == EdmTypeKind.DEFINITION) {
if (edmProperty.isCollection()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + edmProperty.getType().getName() + ")");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
edmProperty.isPrimitive() ?
"#Collection(" + edmProperty.getType().getName() + ")" :
collectionType(edmProperty.getType()));
writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
@ -661,19 +661,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
writer);
}
} else if (edmProperty.isCollection()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", collectionType(edmProperty.getType()));
writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
} else if (property.isComplex()) {
writer.writeAttribute(METADATA, NS_METADATA, "type",
"#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, writer);
} else if (property.isEnum()) {
writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
writer);
if (edmProperty.isCollection()) {
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, collectionType(edmProperty.getType()));
writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
} else {
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
"#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, writer);
}
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@ -690,7 +687,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Boolean isUnicode,
final XMLStreamWriter writer) throws XMLStreamException, EdmPrimitiveTypeException, SerializerException {
for (Object value : property.asCollection()) {
writer.writeStartElement(METADATA, "element", NS_METADATA);
writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
switch (property.getValueType()) {
case COLLECTION_PRIMITIVE:
case COLLECTION_ENUM:
@ -711,9 +708,9 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Property property, final Set<List<String>> selectedPaths, final XMLStreamWriter writer)
throws XMLStreamException, SerializerException {
for (Object value : property.asCollection()) {
writer.writeStartElement(METADATA, "element", NS_METADATA);
writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
if (derivedComplexType(type, property.getType()) != null) {
writer.writeAttribute(METADATA, NS_METADATA, "type", property.getType());
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, property.getType());
}
switch (property.getValueType()) {
case COLLECTION_COMPLEX:
@ -733,7 +730,10 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throws EdmPrimitiveTypeException, XMLStreamException, SerializerException {
if (property.isPrimitive()) {
if (!(type instanceof EdmString)) {
writer.writeAttribute(METADATA, NS_METADATA, "type", type.getName());
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
type.getKind() == EdmTypeKind.DEFINITION ?
"#" + type.getFullQualifiedName().getFullQualifiedNameAsString() :
type.getName());
}
writePrimitiveValue(type, property.asPrimitive(),
isNullable, maxLength, precision, scale, isUnicode, writer);
@ -741,7 +741,8 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
} else if (property.isEnum()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", "#" + type.getName());
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
"#" + type.getFullQualifiedName().getFullQualifiedNameAsString());
writePrimitiveValue(type, property.asEnum(),
isNullable, maxLength, precision, scale, isUnicode, writer);
} else {
@ -757,7 +758,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final String value = type.valueToString(primitiveValue,
isNullable, maxLength, precision, scale, isUnicode);
if (value == null) {
writer.writeAttribute(DATA, NS_DATA, "null", "true");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
writer.writeCharacters(value);
}
@ -797,16 +798,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, "value", NS_METADATA);
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) {
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
if (property.isNull()) {
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
writePrimitive(type, property,
options == null ? null : options.isNullable(),
@ -853,17 +854,17 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, "value", NS_METADATA);
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
writer.writeAttribute(METADATA, NS_METADATA, "type", "#"
+ resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
"#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
if (property.isNull()) {
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
final List<Property> values = property.asComplex().getValue();
writeProperties(metadata, resolvedType, values, options == null ? null : options.getSelect(), writer);
@ -899,15 +900,15 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, "value", NS_METADATA);
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) {
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + type.getName() + ")");
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#Collection(" + type.getName() + ")");
writePrimitiveCollection(type, property,
options == null ? null : options.isNullable(),
options == null ? null : options.getMaxLength(),
@ -952,11 +953,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartElement(METADATA, "value", NS_METADATA);
writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
writer.writeAttribute(METADATA, NS_METADATA, "type", collectionType(type));
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, collectionType(type));
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
writeComplexCollection(metadata, type, property, null, writer);
@ -993,7 +994,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writeReference(entity, options == null ? null : options.getContextURL(), writer, true);
writer.writeEndDocument();
writer.flush();
@ -1020,11 +1021,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
if (top) {
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) { // top-level entity
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
}
writer.writeAttribute("id", entity.getId().toASCIIString());
writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString());
writer.writeEndElement();
}
@ -1043,13 +1044,13 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
writer.writeStartElement(ATOM, "feed", NS_ATOM);
writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
if (options != null && options.getContextURL() != null) { // top-level entity
writer.writeAttribute(METADATA, NS_METADATA, CONTEXT, ContextURLBuilder.create(options.getContextURL())
.toASCIIString());
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(options.getContextURL()).toASCIIString());
}
if (options != null && options.getCount() != null && options.getCount().getValue()
&& entitySet.getCount() != null) {
@ -1083,16 +1084,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeCount(final EntityCollection entitySet, XMLStreamWriter writer)
throws XMLStreamException {
writer.writeStartElement(METADATA, "count", NS_METADATA);
writer.writeStartElement(METADATA, Constants.ATOM_ELEM_COUNT, NS_METADATA);
writer.writeCharacters(String.valueOf(entitySet.getCount()));
writer.writeEndElement();
}
private void writeNextLink(final EntityCollection entitySet, XMLStreamWriter writer)
throws XMLStreamException {
writer.writeStartElement(ATOM, "link", NS_ATOM);
writer.writeAttribute("rel", "next");
writer.writeAttribute("href", entitySet.getNext().toASCIIString());
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
writer.writeAttribute(Constants.ATTR_REL, Constants.NEXT_LINK_REL);
writer.writeAttribute(Constants.ATTR_HREF, entitySet.getNext().toASCIIString());
writer.writeEndElement();
}
}

View File

@ -22,7 +22,6 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
@ -33,18 +32,12 @@ import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
public class ServiceDocumentXmlSerializer {
public static final String KIND = "kind";
public static final String FUNCTION_IMPORT = "FunctionImport";
public static final String SINGLETON = "Singleton";
public static final String SERVICE_DOCUMENT = "ServiceDocument";
private static final String APP = "app";
private static final String NS_APP = "http://www.w3.org/2007/app";
private static final String ATOM = "atom";
private static final String NS_ATOM = "http://www.w3.org/2005/Atom";
private static final String NS_ATOM = Constants.NS_ATOM;
private static final String METADATA = "metadata";
private static final String NS_METADATA = "http://docs.oasis-open.org/odata/ns/metadata";
private static final String NS_METADATA = Constants.NS_METADATA;
private final ServiceMetadata metadata;
private final String serviceRoot;
@ -69,81 +62,73 @@ public class ServiceDocumentXmlSerializer {
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(APP, NS_APP);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeAttribute(METADATA, NS_METADATA, "context", metadataUri);
writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT, metadataUri);
if (metadata != null
&& metadata.getServiceMetadataETagSupport() != null
&& metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
writer.writeAttribute(METADATA, NS_METADATA, "metadata-etag",
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG,
metadata.getServiceMetadataETagSupport().getMetadataETag());
}
writer.writeStartElement(APP, "workspace", NS_APP);
final Edm edm = metadata.getEdm();
writer.writeStartElement(ATOM, "title", NS_APP);
writer.writeCharacters(edm.getEntityContainer(null).getFullQualifiedName().getFullQualifiedNameAsString());
final EdmEntityContainer container = metadata.getEdm().getEntityContainer();
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
writer.writeCharacters(container.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement();
writeEntitySets(writer, edm);
writeFunctionImports(writer, edm);
writeSingletons(writer, edm);
writeEntitySets(writer, container);
writeFunctionImports(writer, container);
writeSingletons(writer, container);
writeServiceDocuments(writer);
writer.writeEndElement(); // end workspace
writer.writeEndElement(); // end service
}
private void writeServiceDocuments(XMLStreamWriter writer) throws XMLStreamException {
for (EdmxReference reference : this.metadata.getReferences()) {
writer.writeStartElement(METADATA, "service-document", NS_METADATA);
writer.writeAttribute("href", reference.getUri().toASCIIString());
writer.writeStartElement(ATOM, "title", NS_ATOM);
writer.writeCharacters(reference.getUri().toASCIIString());
writer.writeEndElement();
writer.writeEndElement();
for (EdmxReference reference : metadata.getReferences()) {
final String referenceString = reference.getUri().toASCIIString();
writeElement(writer, false, "service-document", referenceString, referenceString);
}
}
private void writeEntitySets(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeEntitySets(final XMLStreamWriter writer, final EdmEntityContainer container)
throws XMLStreamException {
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
if (edmEntitySet.isIncludeInServiceDocument()) {
writer.writeStartElement(APP, "collection", NS_APP);
writer.writeAttribute("href", edmEntitySet.getName());
writer.writeStartElement(ATOM, "title", NS_ATOM);
writer.writeCharacters(edmEntitySet.getName());
writer.writeEndElement();
writer.writeEndElement();
writeElement(writer, true, "collection", edmEntitySet.getName(), edmEntitySet.getName());
}
}
}
private void writeFunctionImports(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeFunctionImports(final XMLStreamWriter writer, final EdmEntityContainer container)
throws XMLStreamException {
for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
if (edmFunctionImport.isIncludeInServiceDocument()) {
writer.writeStartElement(METADATA, "function-import", NS_METADATA);
writer.writeAttribute("href", edmFunctionImport.getName());
writer.writeStartElement(ATOM, "title", NS_ATOM);
writer.writeCharacters(edmFunctionImport.getName());
writer.writeEndElement();
writer.writeEndElement();
writeElement(writer, false, "function-import", edmFunctionImport.getName(), edmFunctionImport.getName());
}
}
}
private void writeSingletons(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
EdmEntityContainer container = edm.getEntityContainer(null);
private void writeSingletons(final XMLStreamWriter writer, final EdmEntityContainer container)
throws XMLStreamException {
for (EdmSingleton edmSingleton : container.getSingletons()) {
writer.writeStartElement(METADATA, "singleton", NS_METADATA);
writer.writeAttribute("href", edmSingleton.getName());
writer.writeStartElement(ATOM, "title", NS_ATOM);
writer.writeCharacters(edmSingleton.getName());
writer.writeEndElement();
writer.writeEndElement();
writeElement(writer, false, "singleton", edmSingleton.getName(), edmSingleton.getName());
}
}
private void writeElement(XMLStreamWriter writer, final boolean isApp, final String kind, final String reference,
final String title) throws XMLStreamException {
if (isApp) {
writer.writeStartElement(APP, kind, NS_APP);
} else {
writer.writeStartElement(METADATA, kind, NS_METADATA);
}
writer.writeAttribute(Constants.ATTR_HREF, reference);
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
writer.writeCharacters(title);
writer.writeEndElement();
writer.writeEndElement();
}
}

View File

@ -331,6 +331,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmEntitySet != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceEntitySetImpl().setEntitSet(edmEntitySet));
return null;
@ -341,6 +342,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmSingleton != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceSingletonImpl().setSingleton(edmSingleton));
return null;
@ -351,6 +353,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmActionImport != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceActionImpl().setActionImport(edmActionImport));
return null;
@ -396,7 +399,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ "' with parameters [" + tmp.toString() + "] not found",
UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp.toString()));
}
ensureNamespaceIsNull(ctx.vNS);
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
context.contextUriInfo.addResourcePart(uriResource);
return null;
@ -662,9 +666,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// do a check for bound functions (which requires a parameter list)
if (ctx.vlNVO.size() == 0) {
throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString()
+ "'",
UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED, fullBindingTypeName.toString()));
throw wrap(new UriParserSemanticException("Unknown type for type cast " + fullFilterName.toString()
+ " not found", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE , fullFilterName.toString()));
}
context.contextReadingFunctionParameters = true;
@ -709,6 +712,19 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriParserSemanticException.MessageKeys.UNKNOWN_PART, fullFilterName.toString()));
}
}
/**
* Ensures that the namespace of the first resource parts is null
* @param vNS namespace or null
*/
private void ensureNamespaceIsNull(final NamespaceContext vNS) {
if(vNS != null && context.contextUriInfo.getLastResourcePart() == null) {
// First resource part and namespace is not null!
throw wrap(new UriParserSemanticException("Namespace is not allowed for EntitySets, Singeltons, "
+ " Action Imports and Function Imports. Found " + vNS.getText(),
UriParserSemanticException.MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT, vNS.getText()));
}
}
private String getName(final EdmType type) {
return type.getFullQualifiedName().getFullQualifiedNameAsString();

View File

@ -48,6 +48,8 @@ public class UriParserSemanticException extends UriParserException {
FUNCTION_PARAMETERS_EXPECTED,
/** parameter: resource part */
UNKNOWN_PART,
/** parameter: type */
UNKNOWN_TYPE,
/** parameter: expression */
ONLY_FOR_TYPED_PARTS,
/** parameter: entity type name */
@ -75,8 +77,10 @@ public class UriParserSemanticException extends UriParserException {
/** parameter: resource_name */
RESOURCE_NOT_FOUND,
/** parameter: not implemented part */
NOT_IMPLEMENTED;
NOT_IMPLEMENTED,
/** parameter: namespace **/
NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT;
@Override
public String getKey() {
return name();

View File

@ -50,6 +50,7 @@ UriParserSemanticException.FUNCTION_PARAMETERS_EXPECTED=Function parameters expe
UriParserSemanticException.UNKNOWN_PART=The part '%1$s' is not defined.
UriParserSemanticException.ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts.
UriParserSemanticException.UNKNOWN_ENTITY_TYPE=The entity type '%1$s' is not defined.
UriParserSemanticException.UNKNOWN_TYPE=The type of the type cast '%1$s' is not defined.
UriParserSemanticException.ONLY_FOR_COLLECTIONS='%1$s' is only allowed for collections.
UriParserSemanticException.ONLY_FOR_ENTITY_TYPES='%1$s' is only allowed for entity types.
UriParserSemanticException.ONLY_FOR_STRUCTURAL_TYPES='%1$s' is only allowed for structural types.
@ -66,6 +67,7 @@ UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
UriParserSemanticException.RESOURCE_NOT_FOUND=Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name '%1$s'.
UriParserSemanticException.NOT_IMPLEMENTED=%1$s is not implemented!
UriParserSemanticException.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT=Namespace is not allowed for Entity Sets, Singeltons, Action Imports and Function Imports. Found '%1$s'.
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.

View File

@ -23,7 +23,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
@ -43,7 +42,6 @@ import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.ServiceMetadataImpl;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
public class ServiceDocumentXmlSerializerTest {
private static ODataSerializer serializer;
@ -52,16 +50,16 @@ public class ServiceDocumentXmlSerializerTest {
public static void init() throws SerializerException {
serializer = OData.newInstance().createSerializer(ContentType.APPLICATION_ATOM_XML);
}
@Test
public void writeServiceWithEmptyMockedEdm() throws Exception {
final Edm edm = mock(Edm.class);
EdmEntityContainer container = mock(EdmEntityContainer.class);
Mockito.stub(container.getFullQualifiedName()).toReturn(new FullQualifiedName("service.test"));
when(container.getEntitySets()).thenReturn(new ArrayList<EdmEntitySet>());
when(container.getFunctionImports()).thenReturn(new ArrayList<EdmFunctionImport>());
when(container.getSingletons()).thenReturn(new ArrayList<EdmSingleton>());
when(edm.getEntityContainer(null)).thenReturn(container);
when(container.getFullQualifiedName()).thenReturn(new FullQualifiedName("service", "test"));
when(container.getEntitySets()).thenReturn(Collections.<EdmEntitySet> emptyList());
when(container.getFunctionImports()).thenReturn(Collections.<EdmFunctionImport> emptyList());
when(container.getSingletons()).thenReturn(Collections.<EdmSingleton> emptyList());
when(edm.getEntityContainer()).thenReturn(container);
ServiceMetadata metadata = mock(ServiceMetadata.class);
when(metadata.getEdm()).thenReturn(edm);

View File

@ -54,8 +54,7 @@ public class ActionData {
return DataCreator.createPrimitive(null, "UARTString string value");
} else if ("UARTByteNineParam".equals(name)) {
short count = 0; // counts non-empty parameters
for (final String parameterName : parameters.keySet()) {
final Parameter parameter = parameters.get(parameterName);
for (final Parameter parameter : parameters.values()) {
if (!(parameter.isNull()
|| !parameter.isCollection()
&& (parameter.isComplex() && parameter.asComplex().getValue().isEmpty()
@ -81,10 +80,9 @@ public class ActionData {
String param16String = valueAsString(paramInt16, EdmPrimitiveTypeKind.Int16, oData);
String paramDurationString = valueAsString(paramDuration, EdmPrimitiveTypeKind.Duration, oData);
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(new String[] {
name + " int16 value: " + param16String,
name + " duration value: " + paramDurationString
}));
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(
name + " int16 value: " + param16String,
name + " duration value: " + paramDurationString));
} catch(EdmPrimitiveTypeException e) {
throw new DataProviderException("EdmPrimitiveTypeException", e);
}

View File

@ -1138,7 +1138,11 @@ public class DataCreator {
}
protected static Property createPrimitiveCollection(final String name, final Object... values) {
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
List<Object> propertyValues = new ArrayList<Object>();
for (final Object value : values) {
propertyValues.add(value);
}
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, propertyValues);
}
protected static Property createComplex(final String name, final Property... properties) {

View File

@ -48,6 +48,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.http.HttpStatusCode;
@ -235,9 +236,10 @@ public class DataProvider {
private Property createProperty(final EdmProperty edmProperty, final String propertyName)
throws DataProviderException {
final EdmType type = edmProperty.getType();
Property newProperty;
if (edmProperty.isPrimitive()) {
if (edmProperty.isPrimitive()
|| type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) {
newProperty = edmProperty.isCollection() ?
DataCreator.createPrimitiveCollection(propertyName) :
DataCreator.createPrimitive(propertyName, null);
@ -248,10 +250,9 @@ public class DataProvider {
newProperty = newProperty2;
} else {
newProperty = DataCreator.createComplex(propertyName);
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
createProperties((EdmComplexType) type, newProperty.asComplex().getValue());
}
}
return newProperty;
}
@ -414,40 +415,36 @@ public class DataProvider {
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
final boolean patch) throws DataProviderException {
if (edmProperty.isPrimitive()) {
if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue();
updatePropertyValue(property, value);
}
} else if (edmProperty.isCollection()) {
final EdmType type = edmProperty.getType();
if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones.
property.asCollection().clear();
if (newProperty != null) {
if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
// Complex type
final List<ComplexValue> complexValues = (List<ComplexValue>) newProperty.asCollection();
// Create each complex value
for (final ComplexValue complexValue : complexValues) {
if (type.getKind() == EdmTypeKind.COMPLEX) {
// Create each complex value.
for (final ComplexValue complexValue : (List<ComplexValue>) newProperty.asCollection()) {
((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
}
} else {
// Primitive type
final List<Object> values = (List<Object>) newProperty.asCollection();
((List<Object>) property.asCollection()).addAll(values);
((List<Object>) property.asCollection()).addAll(newProperty.asCollection());
}
}
} else {
final EdmComplexType type = (EdmComplexType) edmProperty.getType();
for (final String propertyName : type.getPropertyNames()) {
} else if (type.getKind() == EdmTypeKind.COMPLEX) {
for (final String propertyName : ((EdmComplexType) type).getPropertyNames()) {
final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null ? null :
newProperty.asComplex().getValue();
updateProperty(type.getStructuralProperty(propertyName),
updateProperty(((EdmComplexType) type).getStructuralProperty(propertyName),
findProperty(propertyName, property.asComplex().getValue()),
newProperties == null ? null : findProperty(propertyName, newProperties),
patch);
}
} else {
if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue();
updatePropertyValue(property, value);
}
}
}

View File

@ -50,8 +50,8 @@ public class FunctionProvider {
public static final FullQualifiedName nameBFCCTPrimCompRTETTwoKeyNavParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCCTPrimCompRTETTwoKeyNavParam");
public static final FullQualifiedName nameBFCESAllPrimRTCTAllPrim =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCESAllPrimRTCTAllPrim");
public static final FullQualifiedName nameBFNESAllPrimRTCTAllPrim =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFNESAllPrimRTCTAllPrim");
public static final FullQualifiedName nameBFCESBaseTwoKeyNavRTESBaseTwoKey =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCESBaseTwoKeyNavRTESBaseTwoKey");
@ -574,22 +574,22 @@ public class FunctionProvider {
.setParameters(Arrays.asList(
new CsdlParameter().setName("BindingParam").setType(EntityTypeProvider.nameETBaseTwoKeyNav)
.setCollection(true).setNullable(false)))
.setComposable(false)
.setComposable(true)
.setReturnType(
new CsdlReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav).setCollection(true)
.setNullable(false))
);
} else if (functionName.equals(nameBFCESAllPrimRTCTAllPrim)) {
} else if (functionName.equals(nameBFNESAllPrimRTCTAllPrim)) {
return Arrays.asList(
new CsdlFunction()
.setName("BFCESAllPrimRTCTAllPrim")
.setName("BFNESAllPrimRTCTAllPrim")
.setBound(true)
.setParameters(
Arrays.asList(
new CsdlParameter().setName("BindingParam").setType(EntityTypeProvider.nameETAllPrim)
.setCollection(true).setNullable(false)))
.setComposable(true)
.setComposable(false)
.setReturnType(
new CsdlReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false))
);

View File

@ -777,12 +777,10 @@ public class PropertyProvider {
// TypeDefinition Properties ---------------------------------------------------------------------------------------
public static final CsdlProperty propertyTypeDefinition_TDString = new CsdlProperty()
.setName("PropertyDefString")
.setType(TypeDefinitionProvider.nameTDString)
.setMaxLength(15);
.setType(TypeDefinitionProvider.nameTDString);
public static final CsdlProperty collPropertyTypeDefinition_TDString = new CsdlProperty()
.setName("CollPropertyDefString")
.setType(TypeDefinitionProvider.nameTDString)
.setMaxLength(15)
.setCollection(true);
}

View File

@ -163,7 +163,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCStringRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETBaseTwoKeyNavRTETTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESBaseTwoKeyNavRTESBaseTwoKey));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESAllPrimRTCTAllPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFNESAllPrimRTCTAllPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCollCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTString));

View File

@ -28,10 +28,10 @@ public class TypeDefinitionProvider {
public CsdlTypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) {
if (nameTDString.equals(typeDefinitionName)) {
return new CsdlTypeDefinition().setName(nameTDString.getName()).setUnderlyingType(
EdmPrimitiveTypeKind.String.getFullQualifiedName()).setMaxLength(15);
return new CsdlTypeDefinition().setName(nameTDString.getName())
.setUnderlyingType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
.setMaxLength(15);
}
return null;
}
}

View File

@ -466,6 +466,10 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
Property complexProperty = entity.getProperty("PropertyCompMixedEnumDef");
List<Property> value = complexProperty.asComplex().getValue();
assertEquals((short) 2, value.get(0).getValue());
defProperty = ((ComplexValue) entity.getProperty("CollPropertyCompMixedEnumDef").asCollection().get(1))
.getValue().get(2);
assertEquals("string", defProperty.getValue());
stream.close();
}

View File

@ -25,21 +25,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
import org.apache.olingo.commons.core.edm.EdmPropertyImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
@ -50,7 +44,6 @@ import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
@ -264,7 +257,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Assert.assertNotNull(result.getProperty("PropertyComp"));
Property comp = result.getProperty("PropertyComp");
Assert.assertEquals("olingo.odata.test1.CTAllPrim", comp.getType());
ComplexValue cv = (ComplexValue)comp.getValue();
ComplexValue cv = comp.asComplex();
Assert.assertEquals(16, cv.getValue().size());
@ -277,14 +270,14 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
}
private Property getCVProperty(ComplexValue cv, String name) {
for (Property p:cv.getValue()) {
for (Property p : cv.getValue()) {
if (p.getName().equals(name)) {
return p;
}
}
return null;
}
@Test
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
@ -336,7 +329,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Property comp = result.getProperty("PropertyComp");
Assert.assertEquals("olingo.odata.test1.CTTwoPrim", comp.getType());
ComplexValue cv = (ComplexValue)comp.getValue();
ComplexValue cv = comp.asComplex();
Assert.assertEquals(2, cv.getValue().size());
Assert.assertEquals((short) 111, getCVProperty(cv, "PropertyInt16").asPrimitive());
@ -344,21 +337,85 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
comp = result.getProperty("CollPropertyComp");
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());
@SuppressWarnings("unchecked")
List<ComplexValue> properties = (List<ComplexValue>)comp.getValue();
List<?> properties = comp.asCollection();
Assert.assertEquals(3, properties.size());
Assert.assertEquals((short) 123,
getCVProperty(properties.get(0), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 1",
getCVProperty(properties.get(0), "PropertyString").asPrimitive());
Assert.assertEquals((short) 123, getCVProperty((ComplexValue) properties.get(0), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 1", getCVProperty((ComplexValue) properties.get(0), "PropertyString").asPrimitive());
Assert.assertEquals((short) 789, getCVProperty(properties.get(2), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 3", getCVProperty(properties.get(2), "PropertyString")
.asPrimitive());
Assert.assertEquals((short) 789, getCVProperty((ComplexValue) properties.get(2), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 3", getCVProperty((ComplexValue) properties.get(2), "PropertyString").asPrimitive());
}
@Test
public void entityMixEnumDefCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
final String payload = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<a:entry xmlns:a=\"" + Constants.NS_ATOM + "\""
+ " xmlns:m=\"" + Constants.NS_METADATA + "\" xmlns:d=\"" + Constants.NS_DATASERVICES + "\">\n"
+ " <a:content type=\"application/xml\">\n"
+ " <m:properties>\n"
+ " <d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " <d:PropertyCompMixedEnumDef m:type=\"#olingo.odata.test1.CTMixEnumDef\">\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " </d:PropertyCompMixedEnumDef>\n"
+ " <d:CollPropertyCompMixedEnumDef m:type=\"#Collection(olingo.odata.test1.CTMixEnumDef)\">\n"
+ " <m:element>\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " </m:element>\n"
+ " </d:CollPropertyCompMixedEnumDef>\n"
+ " </m:properties>\n"
+ " </a:content>\n"
+ "</a:entry>";
final Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
edmEntitySet.getEntityType()).getEntity();
Assert.assertEquals(7, result.getProperties().size());
Assert.assertEquals((short) 1, result.getProperty("PropertyInt16").asPrimitive());
Assert.assertEquals((short) 6, result.getProperty("PropertyEnumString").asEnum());
Assert.assertEquals(3, result.getProperty("CollPropertyEnumString").asCollection().size());
Assert.assertEquals("Test", result.getProperty("PropertyDefString").asPrimitive());
Assert.assertEquals(2, result.getProperty("CollPropertyDefString").asCollection().size());
Assert.assertEquals(4, result.getProperty("PropertyCompMixedEnumDef").asComplex().getValue().size());
Assert.assertEquals(1, result.getProperty("CollPropertyCompMixedEnumDef").asCollection().size());
}
@Test
public void entityWithNavigation() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
@ -461,54 +518,30 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
Assert.assertEquals(Arrays.asList("Employee1@company.example", "Employee2@company.example",
"Employee3@company.example"), result.getValue());
}
@Test
public void complexProperty() throws Exception {
Edm edm = Mockito.mock(Edm.class);
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp");
final String payload = "<data:PropertyComp xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ " xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n"
+ " metadata:type=\"#olingo.odata.test1.CTTwoPrim\">\n"
+ " <data:PropertyInt16>123</data:PropertyInt16>\n"
+ " <data:PropertyString metadata:null=\"true\"/>\n"
+ "</data:PropertyComp>";
CsdlProperty street = new CsdlProperty().setName("Street")
.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
CsdlProperty city = new CsdlProperty().setName("City")
.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
CsdlProperty region = new CsdlProperty().setName("Region")
.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
CsdlProperty postalcode = new CsdlProperty().setName("PostalCode")
.setType(EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
CsdlComplexType ct = new CsdlComplexType()
.setName("Model.Address")
.setProperties(Arrays.asList(street, city, region, postalcode));
EdmComplexTypeImpl complexType = new EdmComplexTypeImpl(edm, new FullQualifiedName("Model.Address"), ct);
Mockito.stub(edm.getComplexType(new FullQualifiedName("Model.Address"))).toReturn(complexType);
CsdlProperty prop = new CsdlProperty();
prop.setName("ShipTo");
prop.setType(new FullQualifiedName("Model.Address"));
EdmPropertyImpl edmProperty = new EdmPropertyImpl(edm, prop);
final Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty)
.getProperty();
String payload = "<data:ShipTo xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" " +
" xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" metadata:type=\"#Model.Address\">\n" +
" <data:Street>Obere Str. 57</data:Street>\n" +
" <data:City>Berlin</data:City>\n" +
" <data:Region metadata:null=\"true\"/>\n" +
" <data:PostalCode>12209</data:PostalCode>\n" +
"</data:ShipTo>";
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
Assert.assertEquals("ShipTo", result.getName());
Assert.assertTrue(result.getValue() instanceof ComplexValue);
ComplexValue cv = (ComplexValue)result.getValue();
Assert.assertEquals("Model.Address", result.getType());
Assert.assertEquals("Berlin", getCVProperty(cv, "City").asPrimitive());
Assert.assertEquals("Obere Str. 57", getCVProperty(cv, "Street").asPrimitive());
Assert.assertEquals("PropertyComp", result.getName());
Assert.assertTrue(result.isComplex());
final ComplexValue cv = result.asComplex();
Assert.assertEquals("olingo.odata.test1.CTTwoPrim", result.getType());
Assert.assertEquals((short) 123, getCVProperty(cv, "PropertyInt16").asPrimitive());
Assert.assertTrue(getCVProperty(cv, "PropertyString").isNull());
}
@SuppressWarnings("unchecked")
@Test
public void complexCollectionProperty() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
@ -531,16 +564,20 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
"</metadata:value>";
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
List<ComplexValue> complex = (List<ComplexValue>)result.getValue();
Assert.assertEquals(3, complex.size());
List<?> complexCollection = result.asCollection();
Assert.assertEquals(3, complexCollection.size());
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", result.getType());
Assert.assertEquals((short) 123, getCVProperty(complex.get(0), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 1", getCVProperty(complex.get(0), "PropertyString").asPrimitive());
Assert.assertEquals((short) 789, getCVProperty(complex.get(2), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 3", getCVProperty(complex.get(2), "PropertyString").asPrimitive());
Assert.assertEquals((short) 123,
getCVProperty((ComplexValue) complexCollection.get(0), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 1",
getCVProperty((ComplexValue) complexCollection.get(0), "PropertyString").asPrimitive());
Assert.assertEquals((short) 789,
getCVProperty((ComplexValue) complexCollection.get(2), "PropertyInt16").asPrimitive());
Assert.assertEquals("TEST 3",
getCVProperty((ComplexValue) complexCollection.get(2), "PropertyString").asPrimitive());
}
@Test
public void entityReference() throws Exception {
String payload = "<metadata:ref xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -553,7 +590,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Assert.assertEquals(1, result.size());
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
}
@Test
public void entityReferences() throws Exception {
String payload = "<feed xmlns=\"http://www.w3.org/2005/Atom\"\n" +
@ -562,7 +599,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
" <metadata:ref id=\"http://host/service/Orders(10643)\" />\n" +
" <metadata:ref id=\"http://host/service/Orders(10759)\" />\n" +
"</feed>";
List<URI> result = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
.getEntityReferences();
Assert.assertEquals(2, result.size());

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.Entity;
@ -113,7 +114,7 @@ public class ODataJsonSerializerTest {
public void entityAllPrimAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
entity.getProperties().retainAll(Collections.singletonList(entity.getProperties().get(0)));
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
entity,
EntitySerializerOptions.with()
@ -292,7 +293,7 @@ public class ODataJsonSerializerTest {
public void entityMixPrimCollCompAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
entity.getProperties().retainAll(Collections.singletonList(entity.getProperties().get(0)));
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@ -304,6 +305,45 @@ public class ODataJsonSerializerTest {
Assert.assertEquals(expectedResult, resultString);
}
@Test
public void enumAndTypeDefinition() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
Entity entity = new Entity();
entity.addProperty(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1));
entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6));
entity.addProperty(new Property(null, "CollPropertyEnumString", ValueType.COLLECTION_ENUM,
Arrays.asList(2, 4, 6)));
entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
entity.addProperty(new Property(null, "CollPropertyDefString", ValueType.COLLECTION_PRIMITIVE,
Arrays.asList("Test1", "Test2")));
ComplexValue complexValue = new ComplexValue();
complexValue.getValue().add(entity.getProperty("PropertyEnumString"));
complexValue.getValue().add(entity.getProperty("CollPropertyEnumString"));
complexValue.getValue().add(entity.getProperty("PropertyDefString"));
complexValue.getValue().add(entity.getProperty("CollPropertyDefString"));
entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, complexValue));
entity.addProperty(new Property(null, "CollPropertyCompMixedEnumDef", ValueType.COLLECTION_COMPLEX,
Collections.singletonList(complexValue)));
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()).getContent());
Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixEnumDefCollComp/$entity\","
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ "\"PropertyInt16\":1,"
+ "\"PropertyEnumString\":\"String2,String3\","
+ "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ "\"PropertyDefString\":\"Test\","
+ "\"CollPropertyDefString\":[\"Test1\",\"Test2\"],"
+ "\"PropertyCompMixedEnumDef\":{\"PropertyEnumString\":\"String2,String3\","
+ "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ "\"PropertyDefString\":\"Test\",\"CollPropertyDefString\":[\"Test1\",\"Test2\"]},"
+ "\"CollPropertyCompMixedEnumDef\":[{\"PropertyEnumString\":\"String2,String3\","
+ "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ "\"PropertyDefString\":\"Test\",\"CollPropertyDefString\":[\"Test1\",\"Test2\"]}]}",
resultString);
}
@Test
public void entityTwoPrimNoMetadata() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
@ -452,7 +492,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
final EdmEntityType entityType = edmEntitySet.getEntityType();
final EntityCollection entitySet = data.readAll(edmEntitySet);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
InputStream result = serializer
.entityCollection(metadata, entityType, entitySet,
@ -501,7 +541,7 @@ public class ODataJsonSerializerTest {
public void expand() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
@ -537,11 +577,11 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
@ -568,7 +608,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItemAll.isStar()).thenReturn(true);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
expandItem, expandItem, expandItemAll));
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
@ -595,8 +635,8 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
Mockito.when(expandItemAll.isStar()).thenReturn(true);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemAll));
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemAll));
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
@ -623,13 +663,13 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemSecond = Mockito.mock(ExpandItem.class);
Mockito.when(expandItemSecond.isStar()).thenReturn(true);
final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemSecond));
final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemSecond));
ExpandItem expandItemFirst = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany");
Mockito.when(expandItemFirst.getExpandOption()).thenReturn(expandInner);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32")));
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()

View File

@ -30,20 +30,29 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.etag.ServiceMetadataETagSupport;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.tecsvc.MetadataETagSupport;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
public class ServiceDocumentTest {
private static final String serviceRoot = "http://localhost:8080/odata.svc";
private static final ServiceMetadata metadata = OData.newInstance().createServiceMetadata(
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("W/\"metadataETag\""));
new EdmTechProvider(), Collections.<EdmxReference> emptyList(),
new ServiceMetadataETagSupport() {
@Override
public String getServiceDocumentETag() {
return "W/\"serviceDocumentETag\"";
}
@Override
public String getMetadataETag() {
return "W/\"metadataETag\"";
}
});
@Test
public void writeServiceDocumentJson() throws Exception {
final String serviceRoot = "http://localhost:8080/odata.svc";
OData server = OData.newInstance();
assertNotNull(server);
@ -54,7 +63,8 @@ public class ServiceDocumentTest {
assertNotNull(result);
final String jsonString = IOUtils.toString(result);
assertTrue(jsonString.contains(metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
assertTrue(jsonString.contains(
metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
assertTrue(jsonString.contains("ESAllPrim"));
assertTrue(jsonString.contains("ESCollAllPrim"));
@ -75,7 +85,6 @@ public class ServiceDocumentTest {
@Test
public void serviceDocumentNoMetadata() throws Exception {
final String serviceRoot = "http://localhost:8080/odata.svc";
final String result = IOUtils.toString(
OData.newInstance().createSerializer(ContentType.JSON_NO_METADATA)
.serviceDocument(metadata, serviceRoot).getContent());

View File

@ -23,8 +23,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.format.ContentType;
@ -44,7 +43,10 @@ public class MetadataDocumentTest {
public void writeMetadataWithTechnicalScenario() throws Exception {
final OData odata = OData.newInstance();
final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
new EdmTechProvider(), getEdmxReferences());
new EdmTechProvider(),
Collections.singletonList(
new EdmxReference(URI.create(CORE_VOCABULARY))
.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"))));
final String metadata = IOUtils.toString(
odata.createSerializer(ContentType.APPLICATION_XML).metadataDocument(serviceMetadata).getContent());
@ -154,23 +156,8 @@ public class MetadataDocumentTest {
// TypeDefCheck
assertThat(metadata,
containsString("<Property Name=\"PropertyDefString\" Type=\"Namespace1_Alias.TDString\" MaxLength=\"15\"/>"));
assertThat(metadata, containsString("<Property Name=\"CollPropertyDefString\" " +
"Type=\"Collection(Namespace1_Alias.TDString)\" MaxLength=\"15\"/>"));
}
/**
* <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() {
EdmxReference reference = new EdmxReference(URI.create(CORE_VOCABULARY));
reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"));
return Arrays.asList(reference);
containsString("<Property Name=\"PropertyDefString\" Type=\"Namespace1_Alias.TDString\"/>"));
assertThat(metadata,
containsString("<Property Name=\"CollPropertyDefString\" Type=\"Collection(Namespace1_Alias.TDString)\"/>"));
}
}

View File

@ -28,8 +28,10 @@ import java.util.Collections;
import java.util.Date;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.data.Property;
@ -81,11 +83,11 @@ import org.xml.sax.SAXException;
public class ODataXmlSerializerTest {
private static final ServiceMetadata metadata = new ServiceMetadataImpl(
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("WmetadataETag"));
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("metadataETag"));
private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer();
private static final DifferenceListener DIFFERENCE_LISTENER = new CustomDifferenceListener();
private static final int MAX_ALLOWED_UPDATED_DIFFERENCE = 2000;
private static final String UPDATED_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final SimpleDateFormat UPDATED_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private final DataProvider data = new DataProvider(OData.newInstance(), metadata.getEdm());
private final ODataSerializer serializer = new ODataXmlSerializer();
@ -115,12 +117,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -182,12 +183,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
"m:context=\"$metadata#ESAllPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -279,7 +279,7 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host:port$metadata#ESCompAllPrim\" "
+ "m:metadata-etag=\"WmetadataETag\">"
+ "m:metadata-etag=\"metadataETag\">"
+ "<a:id>http://host/svc/ESCompAllPrim</a:id>"
+ "<m:count>4</m:count>"
+ "<a:link rel=\"next\" href=\"/next\"/>"
@ -304,12 +304,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host/service/$metadata#ESCollAllPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESCollAllPrim(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
"<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -421,12 +420,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESCompAllPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\" m:etag=\"W/&quot;32767&quot;\">\n" +
" m:metadata-etag=\"metadataETag\" m:etag=\"W/&quot;32767&quot;\">\n" +
" <a:id>ESCompAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
"<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -476,12 +474,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" +
" m:context=\"$metadata#ESMixPrimCollComp/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -537,12 +534,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESMixPrimCollComp/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -561,6 +557,90 @@ public class ODataXmlSerializerTest {
checkXMLEqual(expectedResult, resultString);
}
@Test
public void enumAndTypeDefinition() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
Entity entity = new Entity();
entity.addProperty(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1));
entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6));
entity.addProperty(new Property(null, "CollPropertyEnumString", ValueType.COLLECTION_ENUM,
Arrays.asList(2, 4, 6)));
entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
entity.addProperty(new Property(null, "CollPropertyDefString", ValueType.COLLECTION_PRIMITIVE,
Arrays.asList("Test1", "Test2")));
ComplexValue complexValue = new ComplexValue();
complexValue.getValue().add(entity.getProperty("PropertyEnumString"));
complexValue.getValue().add(entity.getProperty("CollPropertyEnumString"));
complexValue.getValue().add(entity.getProperty("PropertyDefString"));
complexValue.getValue().add(entity.getProperty("CollPropertyDefString"));
entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, complexValue));
entity.addProperty(new Property(null, "CollPropertyCompMixedEnumDef", ValueType.COLLECTION_COMPLEX,
Collections.singletonList(complexValue)));
final long currentTimeMillis = System.currentTimeMillis();
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()).getContent());
checkXMLEqual(resultString,
"<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<a:entry xmlns:a=\"" + Constants.NS_ATOM + "\""
+ " xmlns:m=\"" + Constants.NS_METADATA + "\" xmlns:d=\"" + Constants.NS_DATASERVICES + "\""
+ " m:context=\"$metadata#ESMixEnumDefCollComp/$entity\" m:metadata-etag=\"metadataETag\">\n"
+ " <a:title /> <a:summary />\n"
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>\n"
+ " <a:author> <a:name /> </a:author>\n"
+ " <a:category scheme=\"" + Constants.NS_SCHEME + "\"\n"
+ " term=\"#olingo.odata.test1.ETMixEnumDefCollComp\" />\n"
+ " <a:content type=\"application/xml\">\n"
+ " <m:properties>\n"
+ " <d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " <d:PropertyCompMixedEnumDef m:type=\"#olingo.odata.test1.CTMixEnumDef\">\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " </d:PropertyCompMixedEnumDef>\n"
+ " <d:CollPropertyCompMixedEnumDef m:type=\"#Collection(olingo.odata.test1.CTMixEnumDef)\">\n"
+ " <m:element>\n"
+ " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ "</d:PropertyEnumString>\n"
+ " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ " <m:element>String2</m:element>\n"
+ " <m:element>String3</m:element>\n"
+ " <m:element>String2,String3</m:element>\n"
+ " </d:CollPropertyEnumString>\n"
+ " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ " <m:element>Test1</m:element>\n"
+ " <m:element>Test2</m:element>\n"
+ " </d:CollPropertyDefString>\n"
+ " </m:element>\n"
+ " </d:CollPropertyCompMixedEnumDef>\n"
+ " </m:properties>\n"
+ " </a:content>\n"
+ "</a:entry>");
}
@Test
public void entityTwoPrimNoMetadata() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
@ -605,12 +685,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
" m:context=\"$metadata#ESMedia/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -643,14 +722,13 @@ public class ODataXmlSerializerTest {
"<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" m:context=\"$metadata#ESMedia\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESMedia</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -667,8 +745,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -685,8 +762,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(3)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -703,8 +779,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(4)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -740,14 +815,13 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host/svc$metadata#ESAllNullable\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESAllNullable</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESAllNullable(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -775,82 +849,82 @@ public class ODataXmlSerializerTest {
" <d:PropertyTimeOfDay m:null=\"true\" />\n" +
" <d:CollPropertyString m:type=\"#Collection(String)\">\n" +
" <m:element>spiderman@comic.com</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>spidergirl@comic.com</m:element>\n" +
" </d:CollPropertyString>\n" +
" <d:CollPropertyBoolean m:type=\"#Collection(Boolean)\">\n" +
" <m:element>true</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>false</m:element>\n" +
" </d:CollPropertyBoolean>\n" +
" <d:CollPropertyByte m:type=\"#Collection(Byte)\">\n" +
" <m:element>50</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>249</m:element>\n" +
" </d:CollPropertyByte>\n" +
" <d:CollPropertySByte m:type=\"#Collection(SByte)\">\n" +
" <m:element>-120</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>126</m:element>\n" +
" </d:CollPropertySByte>\n" +
" <d:CollPropertyInt16 m:type=\"#Collection(Int16)\">\n" +
" <m:element>1000</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>30112</m:element>\n" +
" </d:CollPropertyInt16>\n" +
" <d:CollPropertyInt32 m:type=\"#Collection(Int32)\">\n" +
" <m:element>23232323</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>10000001</m:element>\n" +
" </d:CollPropertyInt32>\n" +
" <d:CollPropertyInt64 m:type=\"#Collection(Int64)\">\n" +
" <m:element>929292929292</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>444444444444</m:element>\n" +
" </d:CollPropertyInt64>\n" +
" <d:CollPropertySingle m:type=\"#Collection(Single)\">\n" +
" <m:element>1790.0</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>3210.0</m:element>\n" +
" </d:CollPropertySingle>\n" +
" <d:CollPropertyDouble m:type=\"#Collection(Double)\">\n" +
" <m:element>-17900.0</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>3210.0</m:element>\n" +
" </d:CollPropertyDouble>\n" +
" <d:CollPropertyDecimal m:type=\"#Collection(Decimal)\">\n" +
" <m:element>12</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>1234</m:element>\n" +
" </d:CollPropertyDecimal>\n" +
" <d:CollPropertyBinary m:type=\"#Collection(Binary)\">\n" +
" <m:element>q83v</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>VGeJ</m:element>\n" +
" </d:CollPropertyBinary>\n" +
" <d:CollPropertyDate m:type=\"#Collection(Date)\">\n" +
" <m:element>1958-12-03</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>2013-06-25</m:element>\n" +
" </d:CollPropertyDate>\n" +
" <d:CollPropertyDateTimeOffset m:type=\"#Collection(DateTimeOffset)\">\n" +
" <m:element>2015-08-12T03:08:34Z</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>1948-02-17T09:09:09Z</m:element>\n" +
" </d:CollPropertyDateTimeOffset>\n" +
" <d:CollPropertyDuration m:type=\"#Collection(Duration)\">\n" +
" <m:element>PT13S</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>PT1H0S</m:element>\n" +
" </d:CollPropertyDuration>\n" +
" <d:CollPropertyGuid m:type=\"#Collection(Guid)\">\n" +
" <m:element>ffffff67-89ab-cdef-0123-456789aaaaaa</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>cccccc67-89ab-cdef-0123-456789cccccc</m:element>\n" +
" </d:CollPropertyGuid>\n" +
" <d:CollPropertyTimeOfDay m:type=\"#Collection(TimeOfDay)\">\n" +
" <m:element>04:14:13</m:element>\n" +
" <m:element d:null=\"true\" />\n" +
" <m:element m:null=\"true\" />\n" +
" <m:element>00:37:13</m:element>\n" +
" </d:CollPropertyTimeOfDay>\n" +
" </m:properties>\n" +
@ -884,12 +958,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
" m:context=\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -937,14 +1010,13 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESCompComp(PropertyComp/PropertyComp/PropertyString)\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESCompComp</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
"<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -965,8 +1037,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
"<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1011,14 +1082,13 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" +
" m:context=\"$metadata#ESCompComp(PropertyComp/PropertyComp)\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESCompComp</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1040,8 +1110,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1080,12 +1149,11 @@ public class ODataXmlSerializerTest {
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" m:context=\"$metadata#ESTwoPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1099,8 +1167,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1191,12 +1258,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1210,8 +1276,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1278,12 +1343,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim(PropertySByte)/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1297,8 +1361,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1332,8 +1396,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1396,12 +1460,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1462,12 +1525,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1486,8 +1548,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1518,8 +1580,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(0)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1540,9 +1602,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1568,8 +1629,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1595,8 +1656,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1660,7 +1721,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESAllPrim(32767)/PropertyString\" "
+ "m:metadata-etag=\"WmetadataETag\">"
+ "m:metadata-etag=\"metadataETag\">"
+ "First Resource - positive values</m:value>";
Assert.assertEquals(expected, resultString);
}
@ -1680,7 +1741,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESAllPrim(4242)/PropertyString\" "
+ "m:metadata-etag=\"WmetadataETag\" "
+ "m:metadata-etag=\"metadataETag\" "
+ "m:null=\"true\"/>";
Assert.assertEquals(expected, response);
}
@ -1701,7 +1762,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESCollAllPrim(1)/CollPropertyString\" "
+ "m:metadata-etag=\"WmetadataETag\" m:type=\"#Collection(String)\">"
+ "m:metadata-etag=\"metadataETag\" m:type=\"#Collection(String)\">"
+ "<m:element>Employee1@company.example</m:element>"
+ "<m:element>Employee2@company.example</m:element>"
+ "<m:element>Employee3@company.example</m:element>"
@ -1727,7 +1788,7 @@ public class ODataXmlSerializerTest {
+ "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:type=\"#olingo.odata.test1.CTTwoPrim\" "
+ "m:context=\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\" "
+ "m:metadata-etag=\"WmetadataETag\">"
+ "m:metadata-etag=\"metadataETag\">"
+ "<d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>"
+ "<d:PropertyString>TEST A</d:PropertyString>"
+ "</m:value>";
@ -1751,7 +1812,7 @@ public class ODataXmlSerializerTest {
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:type=\"#Collection(olingo.odata.test1.CTTwoPrim)\"\n" +
" m:context=\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" m:metadata-etag=\"metadataETag\">\n" +
" <m:element>\n" +
" <d:PropertyInt16 m:type=\"Int16\">123</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 1</d:PropertyString>\n" +
@ -1838,31 +1899,28 @@ public class ODataXmlSerializerTest {
private static class CustomDifferenceListener implements DifferenceListener {
@Override
public int differenceFound(Difference difference) {
final String xpath = "/updated[1]/text()[1]";
if(difference.getControlNodeDetail().getXpathLocation().endsWith(xpath)) {
String controlValue = difference.getControlNodeDetail().getValue();
String testValue = difference.getTestNodeDetail().getValue();
// allow a difference from two seconds
SimpleDateFormat sdf = new SimpleDateFormat(UPDATED_FORMAT);
// Allow a difference of up to 2 seconds.
try {
long controlTime = sdf.parse(controlValue).getTime();
long testTime = sdf.parse(testValue).getTime();
long controlTime = UPDATED_FORMAT.parse(controlValue).getTime();
long testTime = UPDATED_FORMAT.parse(testValue).getTime();
long diff = controlTime - testTime;
if(diff < 0) {
if (diff < 0) {
diff = diff * -1;
}
if(diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
// allow a difference from 2 seconds
if (diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
} catch (ParseException e) {
throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
}
}
//Yes it is a difference so throw an exception
// Yes it is a difference so throw an exception.
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}

View File

@ -294,12 +294,12 @@ public class TestFullResourcePath {
@Test
public void runBfuncBnEsRtCprop() throws Exception {
testUri.run("ESAllPrim/olingo.odata.test1.BFCESAllPrimRTCTAllPrim()")
testUri.run("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESAllPrim")
.n()
.isFunction("BFCESAllPrimRTCTAllPrim")
.isFunction("BFNESAllPrimRTCTAllPrim")
.isType(ComplexTypeProvider.nameCTAllPrim);
testUri.run("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()/olingo.odata.test1.CTBase")
@ -1188,25 +1188,15 @@ public class TestFullResourcePath {
testUri.runEx("FICRTCollETMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='1')", "$search=test")
.isExSemantic(MessageKeys.NOT_IMPLEMENTED);
testUri.run("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()")
testUri.run("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()")
.isKind(UriInfoKind.resource)
.goPath().first()
.isEntitySet("ESBaseTwoKeyNav")
.isEntitySet("ESAllPrim")
.at(1)
.isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey");
.isFunction("BFNESAllPrimRTCTAllPrim");
testUri.run("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()"
+ "(PropertyInt16=1,PropertyString='1')")
.isKind(UriInfoKind.resource)
.goPath().first()
.isEntitySet("ESBaseTwoKeyNav")
.at(1)
.isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey")
.isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicate(1, "PropertyString", "'1'");
testUri.runEx("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()"
+ "(PropertyInt16=1,PropertyString='1')/NavPropertyETBaseTwoKeyNavOne")
testUri.runEx("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()"
+ "/PropertyString")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_RESOURCE_PATH);
}
@ -5442,7 +5432,7 @@ public class TestFullResourcePath {
.isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav")
.isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED);
.isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_TYPE);
// $ref
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref")
@ -5563,7 +5553,22 @@ public class TestFullResourcePath {
testUri.runEx("AIRTESAllPrimParam/FICRTString()").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("AIRTESAllPrimParam/AIRTString").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
}
@Test
public void invalidTypeCast() {
testUri.runEx("ESAllPrim/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
testUri.runEx("ESAllPrim(0)/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
}
@Test
public void testFirstResourcePathWithNamespace() {
testUri.runEx("olingo.odata.test1.ESAllPrim").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
testUri.runEx("olingo.odata.test1.ESAllPrim(0)").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
testUri.runEx("olingo.odata.test1.FINRTInt16()").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
testUri.runEx("olingo.odata.test1.AIRTString").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
testUri.runEx("olingo.odata.test1.SINav").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
}
@Test
public void navPropertySameNameAsEntitySet() throws Exception {
testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")