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 8514ca42c..6df42ebd9 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 @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -18,21 +18,35 @@ */ package org.apache.olingo.fit.tecsvc.client; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +import java.net.URI; +import java.util.Collections; +import java.util.List; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.domain.ODataServiceDocument; +import org.apache.olingo.commons.api.domain.v4.ODataAnnotation; +import org.apache.olingo.commons.api.domain.v4.ODataEntity; +import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; +import org.apache.olingo.commons.api.domain.v4.ODataProperty; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.fit.AbstractBaseTestITCase; +import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.tecsvc.TecSvcConst; import org.junit.Before; import org.junit.Test; @@ -52,20 +66,18 @@ public class BasicITCase extends AbstractBaseTestITCase { @Test public void readServiceDocument() { - ODataServiceDocumentRequest request = - odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI); + ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI); assertNotNull(request); ODataRetrieveResponse response = request.execute(); - - assertEquals(200, response.getStatusCode()); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); ODataServiceDocument serviceDocument = response.getBody(); assertNotNull(serviceDocument); - assertTrue(serviceDocument.getEntitySetNames().contains("ESAllPrim")); - assertTrue(serviceDocument.getFunctionImportNames().contains("FICRTCollCTTwoPrim")); - assertTrue(serviceDocument.getSingletonNames().contains("SIMedia")); + assertThat(serviceDocument.getEntitySetNames(), hasItem("ESAllPrim")); + assertThat(serviceDocument.getFunctionImportNames(), hasItem("FICRTCollCTTwoPrim")); + assertThat(serviceDocument.getSingletonNames(), hasItem("SIMedia")); } @Test @@ -74,7 +86,7 @@ public class BasicITCase extends AbstractBaseTestITCase { assertNotNull(request); ODataRetrieveResponse response = request.execute(); - assertEquals(200, response.getStatusCode()); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); Edm edm = response.getBody(); @@ -85,6 +97,35 @@ public class BasicITCase extends AbstractBaseTestITCase { assertEquals(2, edm.getSchemas().size()); } + @Test + public void readEntitySet() { + final ODataEntitySetRequest request = odata.getRetrieveRequestFactory() + .getEntitySetRequest(URI.create(SERVICE_URI + "/ESMixPrimCollComp")); + assertNotNull(request); + + final ODataRetrieveResponse response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); + + final ODataEntitySet entitySet = response.getBody(); + assertNotNull(entitySet); + + assertNull(entitySet.getCount()); + assertNull(entitySet.getNext()); + assertEquals(Collections. emptyList(), entitySet.getAnnotations()); + assertNull(entitySet.getDeltaLink()); + + final List entities = entitySet.getEntities(); + assertNotNull(entities); + assertEquals(3, entities.size()); + final ODataEntity entity = entities.get(2); + assertNotNull(entity); + final ODataProperty property = entity.getProperty("PropertyInt16"); + assertNotNull(property); + assertNotNull(property.getPrimitiveValue()); + assertEquals(0, property.getPrimitiveValue().toValue()); + } + @Override protected CommonODataClient getClient() { return null; } diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java index 1a89f6413..ba4bed6c3 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java @@ -318,7 +318,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { final ODataEntitySet entitySet = res.getBody(); assertNotNull(entitySet); - assertEquals(2, entitySet.getCount()); + assertEquals(2, entitySet.getEntities().size()); for (ODataEntity entity : entitySet.getEntities()) { final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class); diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java index 90028ee25..4891d5d78 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java @@ -156,7 +156,7 @@ public class EntitySetTestITCase extends AbstractTestITCase { assertNotNull(res); final ResWrap entitySet = res.getBodyAs(ODataEntitySet.class); - assertEquals(10, entitySet.getPayload().getCount()); + assertEquals(Integer.valueOf(10), entitySet.getPayload().getCount()); } private void rawRequest(final ODataFormat format) { diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java index ebf707128..41a5b8416 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java @@ -222,7 +222,7 @@ public class InvokeTestITCase extends AbstractTestITCase { ODataEntitySet employees = getClient().getRetrieveRequestFactory(). getEntitySetRequest(employeesURI).execute().getBody(); assertFalse(employees.getEntities().isEmpty()); - final Map preSalaries = new HashMap(employees.getCount()); + final Map preSalaries = new HashMap(employees.getEntities().size()); for (ODataEntity employee : employees.getEntities()) { preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class), employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class)); diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java index 59401c21a..9e39f533c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java @@ -155,7 +155,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase { req.setFormat(ODataFormat.ATOM); final ODataEntitySet feed = req.execute().getBody(); assertNotNull(feed); - assertEquals(feed.getEntities().size(), feed.getCount()); + assertEquals(Integer.valueOf(feed.getEntities().size()), feed.getCount()); } /** diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java index ddb520acd..5be15f750 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java @@ -88,7 +88,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { getProductDetailsReq.setFormat(format); final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody(); assertNotNull(getProductDetailsRes); - assertEquals(1, getProductDetailsRes.getCount()); + assertEquals(1, getProductDetailsRes.getEntities().size()); // GetRelatedProduct final Map keyMap = new LinkedHashMap(); @@ -202,7 +202,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { Collections. singletonMap("count", count)); final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody(); assertNotNull(getProductDetailsRes); - assertEquals(1, getProductDetailsRes.getCount()); + assertEquals(1, getProductDetailsRes.getEntities().size()); // GetRelatedProduct final Map keyMap = new LinkedHashMap(); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java index f37eeb051..4deb2651a 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java @@ -80,7 +80,7 @@ public class EntitySetTestITCase extends AbstractTestITCase { assertNotNull(res); final ResWrap entitySet = res.getBodyAs(ODataEntitySet.class); - assertEquals(5, entitySet.getPayload().getCount()); + assertEquals(5, entitySet.getPayload().getEntities().size()); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address", entitySet.getPayload().getEntities().get(2).getProperty("HomeAddress").getComplexValue().getTypeName()); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java index 636ea0d31..f89d1e780 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java @@ -93,7 +93,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { productsReq.setFormat(format); final ODataEntitySet products = productsReq.execute().getBody(); assertNotNull(products); - assertEquals(5, products.getCount()); + assertEquals(5, products.getEntities().size()); // GetProductsByAccessLevel final ODataEnumValue accessLevel = getClient().getObjectFactory(). @@ -165,7 +165,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getFunctionImportInvokeRequest("GetAllProducts"); final ODataEntitySet products = productsReq.execute().getBody(); assertNotNull(products); - assertEquals(5, products.getCount()); + assertEquals(5, products.getEntities().size()); // GetProductsByAccessLevel final ODataEnumValue accessLevel = getClient().getObjectFactory(). diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java index 2cd4edf09..f86f1c2d0 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java @@ -194,7 +194,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase { final ODataEntitySet feed = req.execute().getBody(); assertNotNull(feed); - assertEquals(feed.getEntities().size(), feed.getCount()); + assertEquals(Integer.valueOf(feed.getEntities().size()), feed.getCount()); } /** diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java index da106b1b2..b2d76fba9 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java @@ -45,7 +45,7 @@ public interface CommonODataEntitySet extends ODataInvokeResult { * * @return in-line count value. */ - int getCount(); + Integer getCount(); /** * Sets in-line count. diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java index 911a06ca0..2e8218c2a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java @@ -59,11 +59,9 @@ public abstract class AbstractODataEntitySet extends AbstractODataPayload implem return next; } - protected abstract int getEntitiesSize(); - @Override - public int getCount() { - return count == null ? getEntitiesSize() : count; + public Integer getCount() { + return count; } @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v3/ODataEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v3/ODataEntitySetImpl.java index 5fd14d5cd..ee2eedab0 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v3/ODataEntitySetImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v3/ODataEntitySetImpl.java @@ -36,11 +36,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE super(next); } - @Override - protected int getEntitiesSize() { - return entities.size(); - } - @Override public List getEntities() { return entities; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEntitySetImpl.java index e9798692c..eda164e0d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEntitySetImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEntitySetImpl.java @@ -43,11 +43,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE super(next); } - @Override - protected int getEntitiesSize() { - return entities.size(); - } - @Override public List getEntities() { return entities; diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java index 1fc503a19..d079dd07b 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java @@ -40,7 +40,6 @@ import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceEntitySet; import org.apache.olingo.server.tecsvc.data.DataProvider; -import java.net.URI; import java.util.List; public class TechnicalProcessor implements CollectionProcessor, EntityProcessor { @@ -112,7 +111,7 @@ public class TechnicalProcessor implements CollectionProcessor, EntityProcessor private EntitySet readEntitySetInternal(final EdmEntitySet edmEntitySet, final String serviceRoot) throws DataProvider.DataProviderException { EntitySet entitySet = dataProvider.readAll(edmEntitySet); - entitySet.setNext(URI.create(serviceRoot + "/" + edmEntitySet.getEntityType().getName())); + // TODO: set count and next link return entitySet; } 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 08c37de32..7e85dc617 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 @@ -134,12 +134,11 @@ public class ODataJsonSerializerTest { ContextURL.Builder.create().entitySet(edmEntitySet).build()); final String resultString = IOUtils.toString(result); - Assert.assertTrue(resultString.matches("\\{" - + "\"@odata\\.context\":\"\\$metadata#ESAllPrim\"," - + "\"@odata\\.count\":3," - + "\"value\":\\[.*\\]," - + "\"@odata\\.nextLink\":\"/next\"" - + "\\}")); + Assert.assertThat(resultString, CoreMatchers.startsWith("{" + + "\"@odata.context\":\"$metadata#ESAllPrim\"," + + "\"@odata.count\":3,\"value\":[")); + Assert.assertThat(resultString, CoreMatchers.endsWith("]," + + "\"@odata.nextLink\":\"/next\"}")); int count = 0; int index = -1;