diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 100aff5d3..fc886ff0e 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -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) {
diff --git a/fit/src/main/java/org/apache/olingo/fit/Services.java b/fit/src/main/java/org/apache/olingo/fit/Services.java
index cb8532967..45f11a5cd 100644
--- a/fit/src/main/java/org/apache/olingo/fit/Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/Services.java
@@ -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,
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
index 9595573bc..a14484aa4 100644
--- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
@@ -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;
diff --git a/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
index cd937ab59..0705384bf 100644
--- a/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
@@ -185,7 +185,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
}
/**
- * Test $inlinecount.
+ * Test $count.
*/
@Test
public void count() {
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index ed7221b88..8656e6e63 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -27,6 +27,7 @@ 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 static org.junit.Assume.assumeTrue;
import java.math.BigDecimal;
import java.net.URI;
@@ -78,22 +79,24 @@ import org.junit.Ignore;
import org.junit.Test;
public class BasicITCase extends AbstractParamTecSvcITCase {
-
+
private static final String CONTENT_TYPE_JSON_IEEE754_COMPATIBLE =
ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true").toContentTypeString();
- private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
- private static final String ET_ALL_PRIM_NAME = "ETAllPrim";
- private static final FullQualifiedName ET_ALL_PRIM = new FullQualifiedName(SERVICE_NAMESPACE, ET_ALL_PRIM_NAME);
+ private static final FullQualifiedName ET_ALL_PRIM = new FullQualifiedName(SERVICE_NAMESPACE, "ETAllPrim");
+ private static final FullQualifiedName ET_KEY_NAV = new FullQualifiedName(SERVICE_NAMESPACE, "ETKeyNav");
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_INT64 = "PropertyInt64";
private static final String PROPERTY_DECIMAL = "PropertyDecimal";
+ private static final String PROPERTY_STRING = "PropertyString";
+ private static final String PROPERTY_COMP = "PropertyComp";
private static final String PROPERTY_COMP_ALL_PRIM = "PropertyCompAllPrim";
private static final String NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
private static final String ES_ALL_PRIM = "ESAllPrim";
private static final String ES_TWO_PRIM = "ESTwoPrim";
private static final String ES_KEY_NAV = "ESKeyNav";
+ private static final String ES_MIX_PRIM_COLL_COMP = "ESMixPrimCollComp";
@Test
public void readServiceDocument() {
@@ -108,7 +111,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
ClientServiceDocument serviceDocument = response.getBody();
assertNotNull(serviceDocument);
- assertThat(serviceDocument.getEntitySetNames(), hasItem("ESAllPrim"));
+ assertThat(serviceDocument.getEntitySetNames(), hasItem(ES_ALL_PRIM));
assertThat(serviceDocument.getFunctionImportNames(), hasItem("FICRTCollCTTwoPrim"));
assertThat(serviceDocument.getSingletonNames(), hasItem("SIMedia"));
}
@@ -127,8 +130,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(edm);
assertEquals(2, edm.getSchemas().size());
- assertEquals("olingo.odata.test1", edm.getSchema("olingo.odata.test1").getNamespace());
- assertEquals("Namespace1_Alias", edm.getSchema("olingo.odata.test1").getAlias());
+ assertEquals(SERVICE_NAMESPACE, edm.getSchema(SERVICE_NAMESPACE).getNamespace());
+ assertEquals("Namespace1_Alias", edm.getSchema(SERVICE_NAMESPACE).getAlias());
assertEquals("Org.OData.Core.V1", edm.getSchema("Org.OData.Core.V1").getNamespace());
assertEquals("Core", edm.getSchema("Org.OData.Core.V1").getAlias());
}
@@ -147,7 +150,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(xmlMetadata);
assertEquals(2, xmlMetadata.getSchemas().size());
- assertEquals("olingo.odata.test1", xmlMetadata.getSchema("olingo.odata.test1").getNamespace());
+ assertEquals(SERVICE_NAMESPACE, xmlMetadata.getSchema(SERVICE_NAMESPACE).getNamespace());
final List references = xmlMetadata.getReferences();
assertEquals(1, references.size());
assertThat(references.get(0).getUri().toASCIIString(), containsString("vocabularies/Org.OData.Core.V1"));
@@ -157,7 +160,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void readEntitySet() {
ODataEntitySetRequest request = getClient().getRetrieveRequestFactory()
.getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").build());
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).build());
assertNotNull(request);
setCookieHeader(request);
@@ -179,14 +182,10 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(3, entities.size());
final ClientEntity entity = entities.get(2);
assertNotNull(entity);
- final ClientProperty property = entity.getProperty("PropertyInt16");
+ final ClientProperty property = entity.getProperty(PROPERTY_INT16);
assertNotNull(property);
assertNotNull(property.getPrimitiveValue());
- if (isJson()) {
- assertEquals(0, property.getPrimitiveValue().toValue());
- } else {
- assertEquals((short)0, property.getPrimitiveValue().toValue());
- }
+ assertShortOrInt(0, property.getPrimitiveValue().toValue());
}
@Test
@@ -211,7 +210,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void readException() throws Exception {
ODataEntityRequest request = getClient().getRetrieveRequestFactory()
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).appendKeySegment("42").build());
assertNotNull(request);
setCookieHeader(request);
@@ -245,20 +244,14 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(property.getCollectionValue());
assertEquals(3, property.getCollectionValue().size());
Iterator iterator = property.getCollectionValue().iterator();
- if(isJson()) {
- assertEquals(1000, iterator.next().asPrimitive().toValue());
- assertEquals(2000, iterator.next().asPrimitive().toValue());
- assertEquals(30112, iterator.next().asPrimitive().toValue());
- } else {
- assertEquals((short)1000, iterator.next().asPrimitive().toValue());
- assertEquals((short)2000, iterator.next().asPrimitive().toValue());
- assertEquals((short)30112, iterator.next().asPrimitive().toValue());
- }
+ assertShortOrInt(1000, iterator.next().asPrimitive().toValue());
+ assertShortOrInt(2000, iterator.next().asPrimitive().toValue());
+ assertShortOrInt(30112, iterator.next().asPrimitive().toValue());
}
@Test
public void deleteEntity() throws Exception {
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataDeleteRequest request = getClient().getCUDRequestFactory().getDeleteRequest(uri);
final ODataDeleteResponse response = request.execute();
@@ -278,14 +271,14 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void patchEntity() throws Exception {
- ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ ClientEntity patchEntity = getFactory().newEntity(ET_ALL_PRIM);
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("new")));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyDecimal",
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_DECIMAL,
getFactory().newPrimitiveValueBuilder().buildDecimal(new BigDecimal(42.875))));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(null)));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataEntityUpdateRequest request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.PATCH, patchEntity);
@@ -295,36 +288,28 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the patched properties have changed and the other properties not.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientProperty property1 = entity.getProperty("PropertyString");
+ final ClientProperty property1 = entity.getProperty(PROPERTY_STRING);
assertNotNull(property1);
assertEquals("new", property1.getPrimitiveValue().toValue());
- final ClientProperty property2 = entity.getProperty("PropertyDecimal");
+ final ClientProperty property2 = entity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
- if (isJson()) {
- assertEquals(42.875, property2.getPrimitiveValue().toValue());
- } else {
- assertEquals(new BigDecimal(42.875), property2.getPrimitiveValue().toValue());
- }
- final ClientProperty property3 = entity.getProperty("PropertyInt64");
+ assertEquals(isJson() ? 42.875 : new BigDecimal(42.875),
+ property2.getPrimitiveValue().toValue());
+ final ClientProperty property3 = entity.getProperty(PROPERTY_INT64);
assertNotNull(property3);
assertNull(property3.getPrimitiveValue());
final ClientProperty property4 = entity.getProperty("PropertyDuration");
assertNotNull(property4);
- if (isJson()) {
- assertEquals("PT6S", property4.getPrimitiveValue().toValue());
- } else {
- assertEquals(new BigDecimal(6), property4.getPrimitiveValue().toValue());
- }
-
+ assertEquals(isJson() ? "PT6S" : BigDecimal.valueOf(6), property4.getPrimitiveValue().toValue());
}
@Test
public void updateEntity() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM);
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64((long) 42)));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataEntityUpdateRequest request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.REPLACE, newEntity);
@@ -334,26 +319,22 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the updated properties have changed and that other properties have their default values.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientProperty property1 = entity.getProperty("PropertyInt64");
+ final ClientProperty property1 = entity.getProperty(PROPERTY_INT64);
assertNotNull(property1);
- if (isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((long)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = entity.getProperty("PropertyDecimal");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = entity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
assertNull(property2.getPrimitiveValue());
}
@Test
public void patchEntityWithComplex() throws Exception {
- ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETCompComp"));
- patchEntity.getProperties().add(getFactory().newComplexProperty("PropertyComp",
- getFactory().newComplexValue("olingo.odata.test1.CTCompComp").add(
- getFactory().newComplexProperty("PropertyComp",
- getFactory().newComplexValue("olingo.odata.test1.CTTwoPrim").add(
- getFactory().newPrimitiveProperty("PropertyInt16",
+ ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETCompComp"));
+ patchEntity.getProperties().add(getFactory().newComplexProperty(PROPERTY_COMP,
+ getFactory().newComplexValue(SERVICE_NAMESPACE + ".CTCompComp").add(
+ getFactory().newComplexProperty(PROPERTY_COMP,
+ getFactory().newComplexValue(SERVICE_NAMESPACE + ".CTTwoPrim").add(
+ getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short)42)))))));
ODataClient client = getClient();
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESCompComp").appendKeySegment(1).build();
@@ -365,40 +346,36 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the patched properties have changed and the other properties not.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientComplexValue complex = entity.getProperty("PropertyComp").getComplexValue()
- .get("PropertyComp").getComplexValue();
+ final ClientComplexValue complex = entity.getProperty(PROPERTY_COMP).getComplexValue()
+ .get(PROPERTY_COMP).getComplexValue();
assertNotNull(complex);
- final ClientProperty property1 = complex.get("PropertyInt16");
+ final ClientProperty property1 = complex.get(PROPERTY_INT16);
assertNotNull(property1);
- if (isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((short)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = complex.get("PropertyString");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = complex.get(PROPERTY_STRING);
assertNotNull(property2);
assertEquals("String 1", property2.getPrimitiveValue().toValue());
}
@Test
public void updateEntityWithComplex() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ ClientEntity newEntity = getFactory().newEntity(ET_KEY_NAV);
newEntity.getProperties().add(getFactory().newComplexProperty("PropertyCompCompNav", null));
// The following properties must not be null
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test")));
newEntity.getProperties().add(
getFactory().newComplexProperty("PropertyCompTwoPrim",
getFactory().newComplexValue("CTTwoPrim")
.add(getFactory().newPrimitiveProperty(
- "PropertyInt16",
+ PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
.add(getFactory().newPrimitiveProperty(
- "PropertyString",
+ PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test2")))));
ODataClient client = getClient();
- final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").appendKeySegment(1).build();
+ final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
final ODataEntityUpdateRequest request = client.getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.REPLACE, newEntity);
final ODataEntityUpdateResponse response = request.execute();
@@ -410,67 +387,88 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ClientComplexValue complex = entity.getProperty("PropertyCompCompNav").getComplexValue()
.get("PropertyCompNav").getComplexValue();
assertNotNull(complex);
- final ClientProperty property = complex.get("PropertyInt16");
+ final ClientProperty property = complex.get(PROPERTY_INT16);
assertNotNull(property);
assertNull(property.getPrimitiveValue());
}
@Test
public void createEntity() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM);
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64((long) 42)));
final ODataClient client = getClient();
newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE,
client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESTwoPrim")
+ .appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32766)
.build()));
final ODataEntityCreateRequest createRequest = client.getCUDRequestFactory().getEntityCreateRequest(
- client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").build(),
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(),
newEntity);
assertNotNull(createRequest);
final ODataEntityCreateResponse createResponse = createRequest.execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), createResponse.getStatusCode());
- assertEquals(SERVICE_URI + "ESAllPrim(1)", createResponse.getHeader(HttpHeader.LOCATION).iterator().next());
+ assertEquals(SERVICE_URI + ES_ALL_PRIM + "(1)", createResponse.getHeader(HttpHeader.LOCATION).iterator().next());
final ClientEntity createdEntity = createResponse.getBody();
assertNotNull(createdEntity);
- final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
+ final ClientProperty property1 = createdEntity.getProperty(PROPERTY_INT64);
assertNotNull(property1);
- if(isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((long)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = createdEntity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
assertNull(property2.getPrimitiveValue());
}
@Test
public void createEntityMinimalResponse() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETTwoPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETTwoPrim"));
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("new")));
ODataEntityCreateRequest request = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESTwoPrim").build(),
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).build(),
newEntity);
request.setPrefer(getClient().newPreferences().returnMinimal());
final ODataEntityCreateResponse response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
- final String location = SERVICE_URI + "ESTwoPrim(1)";
+ final String location = SERVICE_URI + ES_TWO_PRIM + "(1)";
assertEquals(location, response.getHeader(HttpHeader.LOCATION).iterator().next());
assertEquals(location, response.getHeader(HttpHeader.ODATA_ENTITY_ID).iterator().next());
}
+ @Test
+ public void createEntityWithEnumAndTypeDefinition() throws Exception {
+ ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETMixEnumDefCollComp"));
+ newEntity.getProperties().add(getFactory().newEnumProperty("PropertyEnumString",
+ getFactory().newEnumValue(null, "String2")));
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyDefString",
+ getFactory().newPrimitiveValueBuilder().buildString("Test String")));
+ final ODataEntityCreateRequest request = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESMixEnumDefCollComp").build(),
+ newEntity);
+ final ODataEntityCreateResponse response = request.execute();
+ final ClientEntity createdEntity = response.getBody();
+ assertNotNull(createdEntity);
+ ClientProperty property = createdEntity.getProperty("PropertyEnumString");
+ assertNotNull(property);
+ // TODO: Improve client value types.
+ assertEquals("String2", isJson() ? property.getPrimitiveValue().toValue() : property.getEnumValue().getValue());
+ property = createdEntity.getProperty("PropertyDefString");
+ assertNotNull(property);
+ // TODO: Improve client value types.
+ assertEquals("Test String", isJson() ?
+ property.getPrimitiveValue().toValue() :
+ property.getEnumValue().getValue());
+ }
+
@Test
public void readEntityWithExpandedNavigationProperty() {
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build();
@@ -488,7 +486,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity();
assertNotNull(inlineEntity);
- assertShortOrInt(2, inlineEntity.getEntity().getProperty("PropertyInt16").getPrimitiveValue().toValue());
+ assertShortOrInt(2, inlineEntity.getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
// NavPropertyETKeyNavMany
assertNotNull(response.getBody().getNavigationLink("NavPropertyETKeyNavMany"));
@@ -500,42 +498,42 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, inlineEntitySet.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
assertShortOrInt(2, inlineEntitySet.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
}
@Test
public void updateCollectionOfComplexCollection() {
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETKeyNav"));
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
entity.getProperties().add(
getFactory().newCollectionProperty("CollPropertyComp",
getFactory().newCollectionValue("CTPrimComp")
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 42)))
- .add(getFactory().newComplexProperty("PropertyComp",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP,
getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("42"))))))
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 43)))
- .add(getFactory().newComplexProperty("PropertyComp",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP,
getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("43"))))))));
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(3)
.build();
@@ -553,26 +551,18 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.iterator();
ClientComplexValue complexProperty = collectionIterator.next().asComplex();
- if (isJson()) {
- assertEquals(42, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)42, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty.get("PropertyComp"));
+ assertShortOrInt(42, complexProperty.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty.get(PROPERTY_COMP));
- ClientComplexValue innerComplexProperty = complexProperty.get("PropertyComp").getComplexValue();
- assertEquals("42", innerComplexProperty.get("PropertyString").getPrimitiveValue().toValue());
+ ClientComplexValue innerComplexProperty = complexProperty.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("42", innerComplexProperty.get(PROPERTY_STRING).getPrimitiveValue().toValue());
complexProperty = collectionIterator.next().asComplex();
- if (isJson()) {
- assertEquals(43, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)43, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty.get("PropertyComp"));
+ assertShortOrInt(43, complexProperty.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty.get(PROPERTY_COMP));
- innerComplexProperty = complexProperty.get("PropertyComp").getComplexValue();
- assertEquals("43", innerComplexProperty.get("PropertyString").getPrimitiveValue().toValue());
+ innerComplexProperty = complexProperty.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("43", innerComplexProperty.get(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
@@ -581,30 +571,30 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
* Create a new entity which contains a collection of complex collections
* Check if all not filled fields are created by the server
*/
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
entity.getProperties().add(
- getFactory().newPrimitiveProperty("PropertyString",
+ getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Complex collection test")));
entity.getProperties().add(getFactory().newComplexProperty("PropertyCompTwoPrim",
getFactory().newComplexValue("CTTwoPrim")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("1")))));
entity.getProperties().add(getFactory().newCollectionProperty("CollPropertyComp",
getFactory().newCollectionValue("CTPrimComp")
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
- .add(getFactory().newComplexProperty("PropertyComp", getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue("CTAllPrim")
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("1"))))))
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newComplexProperty("PropertyComp", getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue("CTAllPrim")
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("2")))
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 2)))
.add(getFactory().newPrimitiveProperty("PropertySingle",
getFactory().newPrimitiveValueBuilder().buildSingle(2.0f))))))));
@@ -616,13 +606,13 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
private static final long serialVersionUID = 1L;
{
- put("PropertyInt16", 1);
- put("PropertyString", "1");
+ put(PROPERTY_INT16, 1);
+ put(PROPERTY_STRING, "1");
}
}).build()));
final ODataEntityCreateResponse response = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").build(), entity)
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build(), entity)
.execute();
// Check if not declared fields are also available
@@ -632,55 +622,46 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(2, newEntity.getProperty("CollPropertyComp").getCollectionValue().size());
final Iterator iter = newEntity.getProperty("CollPropertyComp").getCollectionValue().iterator();
final ClientComplexValue complexProperty1 = iter.next().asComplex();
- if (isJson()) {
- assertEquals(1, complexProperty1.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)1, complexProperty1.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty1.get("PropertyComp"));
- final ClientComplexValue innerComplexProperty1 = complexProperty1.get("PropertyComp").getComplexValue();
- assertEquals("1", innerComplexProperty1.get("PropertyString").getPrimitiveValue().toValue());
+ assertShortOrInt(1, complexProperty1.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty1.get(PROPERTY_COMP));
+ final ClientComplexValue innerComplexProperty1 = complexProperty1.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("1", innerComplexProperty1.get(PROPERTY_STRING).getPrimitiveValue().toValue());
assertTrue(innerComplexProperty1.get("PropertyBinary").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyBoolean").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyByte").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDate").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDateTimeOffset").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_DECIMAL).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDouble").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDuration").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyGuid").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_INT16).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyInt32").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_INT64).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertySByte").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyTimeOfDay").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertySingle").hasNullValue());
final ClientComplexValue complexProperty2 = iter.next().asComplex();
- assertTrue(complexProperty2.get("PropertyInt16").hasNullValue());
- assertNotNull(complexProperty2.get("PropertyComp"));
- final ClientComplexValue innerComplexProperty2 = complexProperty2.get("PropertyComp").getComplexValue();
- assertEquals("2", innerComplexProperty2.get("PropertyString").getPrimitiveValue().toValue());
- if(isJson()) {
- assertEquals(2, innerComplexProperty2.get("PropertyInt16").getPrimitiveValue().toValue());
- assertEquals(Double.valueOf(2), innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)2, innerComplexProperty2.get("PropertyInt16").getPrimitiveValue().toValue());
- assertEquals(Float.valueOf(2), innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
- }
-
+ assertTrue(complexProperty2.get(PROPERTY_INT16).hasNullValue());
+ assertNotNull(complexProperty2.get(PROPERTY_COMP));
+ final ClientComplexValue innerComplexProperty2 = complexProperty2.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("2", innerComplexProperty2.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertShortOrInt(2, innerComplexProperty2.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(isJson() ? 2.0 : (Number) 2.0F,
+ innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
+
assertTrue(innerComplexProperty2.get("PropertyBinary").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyBoolean").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyByte").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDate").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDateTimeOffset").hasNullValue());
- assertTrue(innerComplexProperty2.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty2.get(PROPERTY_DECIMAL).hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDouble").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDuration").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyGuid").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyInt32").hasNullValue());
- assertTrue(innerComplexProperty2.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty2.get(PROPERTY_INT64).hasNullValue());
assertTrue(innerComplexProperty2.get("PropertySByte").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyTimeOfDay").hasNullValue());
@@ -692,9 +673,9 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void complexPropertyWithNotNullablePrimitiveValue() {
// PropertyComp is null, but the primitive values in PropertyComp must not be null
final ClientEntity entity = getFactory().newEntity(
- new FullQualifiedName("olingo.odata.test1", "ETMixPrimCollComp"));
+ new FullQualifiedName(SERVICE_NAMESPACE, "ETMixPrimCollComp"));
final URI targetURI = getEdmEnabledClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").build();
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).build();
try {
getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(targetURI, entity).execute();
@@ -706,43 +687,43 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void upsert() throws EdmPrimitiveTypeException {
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETTwoPrim"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETTwoPrim"));
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test")));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESTwoPrim").appendKeySegment(33)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).appendKeySegment(33)
.build();
final ODataEntityUpdateResponse updateResponse =
getEdmEnabledClient().getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.PATCH, entity).execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), updateResponse.getStatusCode());
- assertEquals("Test", updateResponse.getBody().getProperty("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Test", updateResponse.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
final String cookie = updateResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next();
- final Short key = updateResponse.getBody().getProperty("PropertyInt16")
+ final Short key = updateResponse.getBody().getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toCastValue(Short.class);
final ODataEntityRequest entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESTwoPrim")
+ .appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(key)
.build());
entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse responseEntityRequest = entityRequest.execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), responseEntityRequest.getStatusCode());
- assertEquals("Test", responseEntityRequest.getBody().getProperty("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Test", responseEntityRequest.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
public void updatePropertyWithNull() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESAllPrim")
+ .appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(32767)
.build();
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString(null)));
ODataEntityUpdateRequest request = getEdmEnabledClient().getCUDRequestFactory()
@@ -752,19 +733,19 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertEquals("return=representation", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
- assertTrue(response.getBody().getProperty("PropertyString").hasNullValue());
- assertShortOrInt(34, response.getBody().getProperty("PropertyDecimal").getPrimitiveValue().toValue());
+ assertTrue(response.getBody().getProperty(PROPERTY_STRING).hasNullValue());
+ assertShortOrInt(34, response.getBody().getProperty(PROPERTY_DECIMAL).getPrimitiveValue().toValue());
}
@Test(expected = ODataClientErrorException.class)
public void updatePropertyWithNullNotAllowed() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(32767)
.build();
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString(null)));
getEdmEnabledClient().getCUDRequestFactory().getEntityUpdateRequest(targetURI, UpdateType.PATCH, entity).execute();
@@ -773,22 +754,22 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateMerge() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.build();
final ClientObjectFactory factory = getFactory();
- final ClientEntity entity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.addLink(factory.newEntityNavigationLink("NavPropertyETKeyNavOne", targetURI));
entity.addLink(factory.newEntitySetNavigationLink("NavPropertyETKeyNavMany", getClient().newURIBuilder
(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav").appendKeySegment(3).build()));
+ .appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build()));
entity.getProperties().add(factory.newCollectionProperty("CollPropertyString",
factory.newCollectionValue("Edm.String").add(
factory.newPrimitiveValueBuilder().buildString("Single entry!"))));
- entity.getProperties().add(factory.newComplexProperty("PropertyCompAllPrim",
+ entity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
factory.newComplexValue("CTAllPrim")
- .add(factory.newPrimitiveProperty("PropertyString",
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("Changed")))));
final ODataEntityUpdateResponse response = getEdmEnabledClient().getCUDRequestFactory()
@@ -801,7 +782,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataEntityRequest entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(
getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build());
@@ -812,7 +793,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, entityResponse.getBody().getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity()
.getEntity()
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -827,7 +808,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -836,7 +817,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -845,7 +826,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(2)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -858,40 +839,40 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertFalse(collectionIterator.hasNext());
final ClientComplexValue complexValue = entityResponse.getBody()
- .getProperty("PropertyCompAllPrim")
+ .getProperty(PROPERTY_COMP_ALL_PRIM)
.getComplexValue();
- assertEquals("Changed", complexValue.get("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Changed", complexValue.get(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
public void updateReplace() {
final ODataClient client = getClient();
final URI targetURI = client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.build();
final ClientObjectFactory factory = getFactory();
- final ClientEntity entity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.addLink(factory.newEntityNavigationLink("NavPropertyETKeyNavOne", targetURI));
entity.addLink(factory.newEntitySetNavigationLink("NavPropertyETKeyNavMany", client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav").appendKeySegment(3).build()));
- entity.getProperties().add(factory.newPrimitiveProperty("PropertyString", factory
+ .appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build()));
+ entity.getProperties().add(factory.newPrimitiveProperty(PROPERTY_STRING, factory
.newPrimitiveValueBuilder()
.buildString("Must not be null")));
entity.getProperties().add(factory.newComplexProperty("PropertyCompTwoPrim", factory.newComplexValue
("CTTwoPrim")
- .add(factory.newPrimitiveProperty("PropertyString", factory.newPrimitiveValueBuilder()
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
.buildString("Must not be null")))
- .add(factory.newPrimitiveProperty("PropertyInt16",
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties().add(factory.newCollectionProperty("CollPropertyString",
factory.newCollectionValue("Edm.String")
.add(factory.newPrimitiveValueBuilder().buildString("Single entry!"))));
- entity.getProperties().add(factory.newComplexProperty("PropertyCompAllPrim",
+ entity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
factory.newComplexValue("CTAllPrim").add(
- factory.newPrimitiveProperty("PropertyString",
+ factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("Changed")))));
ODataEntityUpdateRequest request = getEdmEnabledClient().getCUDRequestFactory()
@@ -905,7 +886,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataEntityRequest entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(
getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build());
@@ -916,7 +897,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, entityResponse.getBody().getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity()
.getEntity()
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -931,7 +912,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -940,7 +921,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -949,7 +930,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(2)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -962,30 +943,32 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertFalse(collectionIterator.hasNext());
final ClientComplexValue propCompAllPrim = entityResponse.getBody()
- .getProperty("PropertyCompAllPrim")
+ .getProperty(PROPERTY_COMP_ALL_PRIM)
.getComplexValue();
- assertEquals("Changed", propCompAllPrim.get("PropertyString").getPrimitiveValue().toValue());
- assertTrue(propCompAllPrim.get("PropertyInt16").hasNullValue());
+ assertEquals("Changed", propCompAllPrim.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertTrue(propCompAllPrim.get(PROPERTY_INT16).hasNullValue());
assertTrue(propCompAllPrim.get("PropertyDate").hasNullValue());
final ClientComplexValue propCompTwoPrim = entityResponse.getBody()
.getProperty("PropertyCompTwoPrim")
.getComplexValue();
- assertEquals("Must not be null", propCompTwoPrim.get("PropertyString").getPrimitiveValue().toValue());
- assertShortOrInt(42, propCompTwoPrim.get("PropertyInt16").getPrimitiveValue().toValue());
+ assertEquals("Must not be null", propCompTwoPrim.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertShortOrInt(42, propCompTwoPrim.get(PROPERTY_INT16).getPrimitiveValue().toValue());
assertNotNull(entityResponse.getBody().getProperty("PropertyCompNav").getComplexValue());
assertTrue(entityResponse.getBody()
.getProperty("PropertyCompNav")
.getComplexValue()
- .get("PropertyInt16")
+ .get(PROPERTY_INT16)
.hasNullValue());
}
@Test
public void createEntityWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build();
final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767).build();
@@ -1010,6 +993,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void createEntityWithIEEE754CompatibleParameterNull() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build();
final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767).build();
@@ -1033,9 +1018,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+ .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(Long.MAX_VALUE)));
@@ -1064,9 +1051,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameterNull() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+ .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(null)));
@@ -1093,9 +1082,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameterWithNullString() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildString("null")));
@@ -1117,10 +1108,12 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEdmInt64PropertyWithIEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(0)
.appendPropertySegment(PROPERTY_INT64).build();
-
+
final ODataPropertyUpdateRequest requestUpdate =
getEdmEnabledClient().getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uri,
getFactory().newPrimitiveProperty(PROPERTY_INT64,
@@ -1142,10 +1135,12 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateComplexPropertyWithIEEE754CompatibleParamter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM).build();
-
+
final ODataPropertyUpdateRequest requestUpdate = getEdmEnabledClient().getCUDRequestFactory()
.getPropertyComplexValueUpdateRequest(uri, UpdateType.PATCH,
getFactory().newComplexProperty(PROPERTY_COMP_ALL_PRIM,
@@ -1177,6 +1172,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updatePropertyEdmDecimalWithIEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(0)
.appendPropertySegment(PROPERTY_DECIMAL).build();
@@ -1202,6 +1199,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESAllPrimCollectionWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.orderBy(PROPERTY_INT16)
.build();
@@ -1235,6 +1234,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESKeyNavCheckComplexPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
@@ -1262,6 +1263,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESKEyNavComplexPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendNavigationSegment(PROPERTY_COMP_ALL_PRIM)
@@ -1286,8 +1289,10 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
}
@Test
- @Ignore
+ @Ignore("The client does not recognize the IEEE754Compatible content-type parameter.")
public void readEdmInt64PropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM)
@@ -1300,13 +1305,15 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataRetrieveResponse response = request.execute();
saveCookieHeader(response);
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
-
+
assertEquals(Long.MAX_VALUE, response.getBody().getPrimitiveValue().toValue());
}
@Test
- @Ignore
+ @Ignore("The client does not recognize the IEEE754Compatible content-type parameter.")
public void readEdmDecimalPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM)
@@ -1319,7 +1326,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataRetrieveResponse response = request.execute();
saveCookieHeader(response);
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
-
+
assertEquals(BigDecimal.valueOf(34), response.getBody().getPrimitiveValue().toValue());
}
}
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
index ce31ec2b6..273779c12 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
@@ -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
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
index 5a20f2939..170fec447 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
@@ -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;
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
index 06e884e82..8d87197c7 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
@@ -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.
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
index b57960ac7..d59af9391 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
@@ -33,7 +33,7 @@ public abstract class AbstractClientEntitySet extends AbstractClientPayload impl
/**
* Number of ODataEntities contained in this entity set.
*
- * If $inlinecount was requested, this value comes from there.
+ * If $count was requested, this value comes from there.
*/
private Integer count;
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
index d3dac7284..47bfe64b0 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
@@ -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 VALID_UNDERLYING_TYPES = new HashSet();
- 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 memberNames;
- private LinkedHashMap membersMap;
+ private Map 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 membersMapLocal = new LinkedHashMap();
+ final Map membersMapLocal = new LinkedHashMap();
final List memberNamesLocal = new ArrayList();
if (enumType.getMembers() != null) {
for (final CsdlEnumMember member : enumType.getMembers()) {
@@ -154,7 +148,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class 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()));
}
}
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
index a275e34e8..e75ab8e50 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
@@ -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 valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException {
-
- return getUnderlyingType().
- valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ final Integer precision, final Integer scale, final Boolean isUnicode, final Class 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
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
new file mode 100644
index 000000000..18bb7989d
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
@@ -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 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.");
+ }
+}
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
new file mode 100644
index 000000000..3d41db4a1
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
@@ -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();
+ }
+}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
index 9fb08ab35..8ff833c98 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
@@ -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);
}
}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
index c27958654..0f0eff62a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
@@ -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);
}
}
}
}
-
}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 642a91e2f..1ddc97978 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -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> 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());
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
index 0136df4d1..2cae47636 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
@@ -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();
+ }
}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 27ba073fa..3e77239f5 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -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> 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> 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 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();
}
}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
index b9312276b..6d130bae8 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
@@ -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();
+ }
}
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index edd60581c..7ea1adbed 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -331,6 +331,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor