From 5501e8e3315b642ca904a598856dc9f7f1d0b2d7 Mon Sep 17 00:00:00 2001 From: Klaus Straubinger Date: Wed, 10 Jun 2015 15:06:33 +0200 Subject: [PATCH] [OLINGO-663] ETag annotation again in entity collections of technical service Change-Id: Ia150ba1705fa22e36c3821d5295f1b7f464a4852 Signed-off-by: Christian Amend --- .../client/FilterSystemQueryITCase.java | 247 ++++++++---------- .../client/SystemQueryOptionITCase.java | 27 +- .../commons/api/data/AbstractODataObject.java | 4 +- .../core/serialization/AtomDeserializer.java | 6 +- .../core/serialization/AtomSerializer.java | 2 +- .../serialization/JsonDeltaDeserializer.java | 2 +- .../serialization/JsonEntityDeserializer.java | 2 +- .../JsonEntitySetDeserializer.java | 2 +- .../processor/TechnicalEntityProcessor.java | 2 +- .../ExpandSystemQueryOptionHandler.java | 17 +- .../json/ODataJsonSerializerTest.java | 17 +- 11 files changed, 159 insertions(+), 169 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java index 75d58afc7..1e27357b1 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java @@ -32,7 +32,6 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientObjectFactory; -import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataFormat; @@ -62,7 +61,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -71,15 +70,15 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = response.getBody().getEntities().get(1); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); response = sendRequest(ES_ALL_PRIM, "PropertyBoolean eq true"); assertEquals(1, response.getBody().getEntities().size()); clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -88,7 +87,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -98,7 +97,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -109,7 +108,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -121,7 +120,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -130,12 +129,12 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -145,8 +144,8 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -166,8 +165,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); - - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -176,7 +174,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -185,18 +183,18 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { sendRequest(ES_TWO_KEY_NAV, "PropertyString eq '2' and PropertyInt16 eq 1"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyString eq '2' or PropertyInt16 eq 1"); assertEquals(2, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -296,26 +294,17 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { .appendKeySegment(32766) .build())); - final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").build(); + final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(); ODataEntityCreateResponse createResponse = client.getCUDRequestFactory().getEntityCreateRequest(uri, entity).execute(); - final URI receiveURI = - client.newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESAllPrim") - .filter(filterString) - .build(); - - ODataEntitySetRequest filterRequest = - client.getRetrieveRequestFactory().getEntitySetRequest(receiveURI); - filterRequest.addCustomHeader(HttpHeader.COOKIE, createResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next()); - ODataRetrieveResponse filterResponse = filterRequest.execute(); - + ODataRetrieveResponse filterResponse = sendRequest(ES_ALL_PRIM, filterString, + createResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next()); assertEquals(1, filterResponse.getBody().getEntities().size()); } @Test - public void testNumericComparisionOperators() { + public void numericComparisonOperators() { ODataRetrieveResponse result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 ge 1"); assertEquals(4, result.getBody().getEntities().size()); @@ -355,25 +344,22 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(3, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("11", ((ClientValuable) ((ClientValuable) clientEntity.getProperty("PropertyComp")).getComplexValue() - .get("PropertyInt16")).getValue() - .toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); + assertEquals(11, clientEntity.getProperty("PropertyComp").getComplexValue().get("PropertyInt16") + .getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("11", ((ClientValuable) ((ClientValuable) clientEntity.getProperty("PropertyComp")).getComplexValue() - .get("PropertyInt16")).getValue() - .toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); + assertEquals(11, clientEntity.getProperty("PropertyComp").getComplexValue().get("PropertyInt16") + .getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(2); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); - assertEquals("11", ((ClientValuable) ((ClientValuable) clientEntity.getProperty("PropertyComp")).getComplexValue() - .get("PropertyInt16")).getValue() - .toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); + assertEquals(11, clientEntity.getProperty("PropertyComp").getComplexValue().get("PropertyInt16") + .getPrimitiveValue().toValue()); } @Test @@ -382,12 +368,12 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -396,12 +382,12 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -410,12 +396,12 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -444,7 +430,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -455,30 +441,27 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(4, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(2); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(3); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test public void testSubstringDouble() { - try { - sendRequest(ES_ALL_PRIM, "substring(PropertyString, length('First')" - + "add 1, 2.0 * 4) eq ('Resource')"); - } catch (ODataClientErrorException e) { - assertEquals(400, e.getStatusLine().getStatusCode()); - } + fail(ES_ALL_PRIM, + "substring(PropertyString, length('First') add 1, 2.0 * 4) eq ('Resource')", + HttpStatusCode.BAD_REQUEST); } @Test @@ -487,7 +470,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -496,7 +479,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -505,13 +488,13 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(3, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(2); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -520,7 +503,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -529,13 +512,13 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(3, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(2); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -544,7 +527,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -553,10 +536,10 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -565,7 +548,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -574,7 +557,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -583,7 +566,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -592,7 +575,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -601,7 +584,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -611,10 +594,12 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("W/\"32767\"", clientEntity.getETag()); clientEntity = response.getBody().getEntities().get(1); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("W/\"0\"", clientEntity.getETag()); } @Test @@ -653,15 +638,15 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq floor(3.1)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -670,15 +655,15 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq ceiling(2.6)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -687,29 +672,29 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(2.4)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("2", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(2.6)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(3.1)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); - assertEquals("3", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); - assertEquals("1", ((ClientValuable) clientEntity.getProperty("PropertyString")).getValue().toString()); + assertEquals(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); + assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); } @Test @@ -718,10 +703,10 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -731,7 +716,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -740,7 +725,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -750,7 +735,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -760,7 +745,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -770,7 +755,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -780,7 +765,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(-32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -790,7 +775,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -808,7 +793,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -818,7 +803,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -835,7 +820,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -845,7 +830,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -855,7 +840,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -865,7 +850,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -875,7 +860,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test @@ -885,7 +870,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); - assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString()); + assertEquals(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); } @Test diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java index c8d1d0c01..bbd9d51f6 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java @@ -28,7 +28,6 @@ import org.apache.olingo.client.api.communication.ODataClientErrorException; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpStatusCode; @@ -47,7 +46,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_ALL_PRIM) - .addQueryOption(QueryOption.COUNT, "true") + .count(true) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -63,7 +62,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.COUNT, "true") + .count(true) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -79,7 +78,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.TOP, new Integer(5).toString()) + .top(5) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -99,7 +98,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.SKIP, new Integer(5).toString()) + .skip(5) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -119,8 +118,8 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.TOP, new Integer(20).toString()) - .addQueryOption(QueryOption.SKIP, new Integer(503).toString()) + .top(20) + .skip(503) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -135,7 +134,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.SKIP, new Integer(10000).toString()) + .skip(10000) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -152,9 +151,9 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) .filter("PropertyInt16 le 105") // 1, 2, ... , 105 .orderBy("PropertyInt16 desc") // 105, 104, ..., 2, 1 - .addQueryOption(QueryOption.COUNT, Boolean.TRUE.toString()) // 105 - .addQueryOption(QueryOption.SKIP, new Integer(3).toString()) // 102, 101, ..., 2, 1 - .addQueryOption(QueryOption.TOP, new Integer(43).toString()) // 102, 101, ...., 59 + .count(true) // 105 + .skip(3) // 102, 101, ..., 2, 1 + .top(43) // 102, 101, ...., 59 .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -228,7 +227,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_SERVER_SIDE_PAGING) - .addQueryOption(QueryOption.COUNT, Boolean.TRUE.toString()) + .count(true) .build(); ODataRetrieveResponse response = client.getRetrieveRequestFactory() @@ -264,7 +263,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_ALL_PRIM) - .addQueryOption(QueryOption.SKIP, new Integer(-5).toString()) + .skip(-5) .build(); try { @@ -282,7 +281,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { ODataClient client = getClient(); URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_ALL_PRIM) - .addQueryOption(QueryOption.TOP, new Integer(-5).toString()) + .top(-5) .build(); try { client.getRetrieveRequestFactory() diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractODataObject.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractODataObject.java index 237b8ef60..7e89123f9 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractODataObject.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractODataObject.java @@ -36,8 +36,8 @@ public abstract class AbstractODataObject extends Annotatable { return baseURI; } - public void setBaseURI(final String baseURI) { - this.baseURI = baseURI == null ? null : URI.create(baseURI); + public void setBaseURI(final URI baseURI) { + this.baseURI = baseURI; } /** diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java index c25da60ac..b8b51670b 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java @@ -431,7 +431,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria final Delta delta = new Delta(); final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); if (xmlBase != null) { - delta.setBaseURI(xmlBase.getValue()); + delta.setBaseURI(URI.create(xmlBase.getValue())); } boolean foundEndFeed = false; @@ -579,7 +579,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria entity = new Entity(); final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); if (xmlBase != null) { - entity.setBaseURI(xmlBase.getValue()); + entity.setBaseURI(URI.create(xmlBase.getValue())); } final Attribute etag = start.getAttributeByName(etagQName); @@ -737,7 +737,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria final EntityCollection entitySet = new EntityCollection(); final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); if (xmlBase != null) { - entitySet.setBaseURI(xmlBase.getValue()); + entitySet.setBaseURI(URI.create(xmlBase.getValue())); } boolean foundEndFeed = false; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java index 1ef177adb..ecd7be07f 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java @@ -550,7 +550,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (container.getContextURL() != null) { final ContextURL contextURL = ContextURLParser.parse(container.getContextURL()); - String base = contextURL.getServiceRoot().toASCIIString(); + final URI base = contextURL.getServiceRoot(); if (container.getPayload() instanceof EntityCollection) { ((EntityCollection) container.getPayload()).setBaseURI(base); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java index 64f6c8a9b..89f327fc9 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java @@ -52,7 +52,7 @@ public class JsonDeltaDeserializer extends JsonDeserializer { final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null; if (contextURL != null) { - delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + delta.setBaseURI(URI.create(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA))); } if (tree.hasNonNull(Constants.JSON_COUNT)) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java index 99abccb5e..10cc3bbc3 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java @@ -76,7 +76,7 @@ public class JsonEntityDeserializer extends JsonDeserializer { contextURL = null; } if (contextURL != null) { - entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + entity.setBaseURI(URI.create(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA))); } final String metadataETag; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java index 01f2f657f..354d4ddf2 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java @@ -66,7 +66,7 @@ public class JsonEntitySetDeserializer extends JsonDeserializer { contextURL = null; } if (contextURL != null) { - entitySet.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + entitySet.setBaseURI(URI.create(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA))); } final String metadataETag; diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index aae4f7a94..575b914df 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -435,7 +435,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor final CountOption countOption = uriInfo.getCountOption(); // Serialize - final SerializerResult serializerResult = (isReference) ? + final SerializerResult serializerResult = isReference ? serializeReferenceCollection(entitySetSerialization, edmEntitySet, format) : serializeEntityCollection(entitySetSerialization, edmEntitySet, edmEntityType, format, expand, select, countOption); diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java index f9ac6e779..c641516cf 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java @@ -41,6 +41,7 @@ import org.apache.olingo.server.api.uri.queryoption.FilterOption; import org.apache.olingo.server.api.uri.queryoption.OrderByOption; import org.apache.olingo.server.api.uri.queryoption.SkipOption; import org.apache.olingo.server.api.uri.queryoption.TopOption; +import org.apache.olingo.server.tecsvc.processor.queryoptions.options.CountHandler; import org.apache.olingo.server.tecsvc.processor.queryoptions.options.FilterHandler; import org.apache.olingo.server.tecsvc.processor.queryoptions.options.OrderByHandler; import org.apache.olingo.server.tecsvc.processor.queryoptions.options.SkipHandler; @@ -105,7 +106,7 @@ public class ExpandSystemQueryOptionHandler { FilterHandler.applyFilterSystemQuery(filterOption, entitySet, edmBindingTarget); OrderByHandler.applyOrderByOption(orderByOption, entitySet, edmBindingTarget); - // TODO Add CountHandler + CountHandler.applyCountSystemQueryOption(countOption, entitySet); SkipHandler.applySkipSystemQueryHandler(skipOption, entitySet); TopHandler.applyTopSystemQueryOption(topOption, entitySet); @@ -168,25 +169,29 @@ public class ExpandSystemQueryOptionHandler { newEntitySet.setCount(entitySet.getCount()); newEntitySet.setDeltaLink(entitySet.getDeltaLink()); newEntitySet.setNext(entitySet.getNext()); + newEntitySet.setId(entitySet.getId()); + newEntitySet.setBaseURI(entitySet.getBaseURI()); return newEntitySet; } private Entity newEntity(final Entity entity) { - final Entity newEntity = new Entity(); + Entity newEntity = new Entity(); newEntity.getProperties().addAll(entity.getProperties()); newEntity.getAnnotations().addAll(entity.getAnnotations()); - newEntity.getAssociationLinks().addAll(entity.getAssociationLinks()); - newEntity.setEditLink(entity.getEditLink()); newEntity.setId(entity.getId()); + newEntity.setBaseURI(entity.getBaseURI()); + newEntity.setType(entity.getType()); + newEntity.setETag(entity.getETag()); newEntity.setMediaContentSource(entity.getMediaContentSource()); newEntity.setMediaContentType(entity.getMediaContentType()); newEntity.setMediaETag(entity.getMediaETag()); - newEntity.getOperations().addAll(entity.getOperations()); newEntity.setSelfLink(entity.getSelfLink()); - newEntity.setType(entity.getType()); + newEntity.setEditLink(entity.getEditLink()); + newEntity.getAssociationLinks().addAll(entity.getAssociationLinks()); newEntity.getNavigationBindings().addAll(entity.getNavigationBindings()); + newEntity.getOperations().addAll(entity.getOperations()); return newEntity; } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java index 311ec082e..c9cfde9f5 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java @@ -37,7 +37,6 @@ import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; @@ -53,6 +52,7 @@ import org.apache.olingo.server.api.uri.queryoption.ExpandItem; import org.apache.olingo.server.api.uri.queryoption.ExpandOption; import org.apache.olingo.server.api.uri.queryoption.SelectItem; import org.apache.olingo.server.api.uri.queryoption.SelectOption; +import org.apache.olingo.server.core.ServiceMetadataImpl; import org.apache.olingo.server.core.serializer.ExpandSelectMock; import org.apache.olingo.server.core.uri.UriHelperImpl; import org.apache.olingo.server.tecsvc.MetadataETagSupport; @@ -64,7 +64,7 @@ import org.junit.Test; import org.mockito.Mockito; public class ODataJsonSerializerTest { - private static final ServiceMetadata metadata = OData.newInstance().createServiceMetadata( + private static final ServiceMetadata metadata = new ServiceMetadataImpl( new EdmTechProvider(), Collections. emptyList(), new MetadataETagSupport("W/\"metadataETag\"")); private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer(); private final DataProvider data = new DataProvider(); @@ -157,8 +157,8 @@ public class ODataJsonSerializerTest { } @Test - public void entitySetAllPrim() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); + public void entitySetCompAllPrim() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim"); EntityCollection entitySet = data.readAll(edmEntitySet); entitySet.setCount(entitySet.getEntities().size()); entitySet.setNext(URI.create("/next")); @@ -172,10 +172,11 @@ public class ODataJsonSerializerTest { final String resultString = IOUtils.toString(result); Assert.assertThat(resultString, CoreMatchers.startsWith("{" - + "\"@odata.context\":\"$metadata#ESAllPrim\"," + + "\"@odata.context\":\"$metadata#ESCompAllPrim\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@odata.count\":3,\"value\":[")); - Assert.assertThat(resultString, CoreMatchers.endsWith("]," + + "\"@odata.count\":3,\"value\":[" + + "{\"@odata.etag\":\"W/\\\"32767\\\"\",")); + Assert.assertThat(resultString, CoreMatchers.endsWith("\"}}]," + "\"@odata.nextLink\":\"/next\"}")); int count = 0; @@ -183,7 +184,7 @@ public class ODataJsonSerializerTest { while ((index = resultString.indexOf("PropertyInt16\":", ++index)) > 0) { count++; } - Assert.assertEquals(3, count); + Assert.assertEquals(6, count); } @Test