[OLINGO-317] Additional integration test and simplified getCount()

This commit is contained in:
Michael Bolz 2014-07-29 14:37:49 +02:00
parent eb1de05a7e
commit 7442b27cd7
15 changed files with 69 additions and 42 deletions

View File

@ -18,19 +18,33 @@
*/
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.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.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Before;
import org.junit.Test;
@ -49,20 +63,18 @@ public class BasicITCase {
@Test
public void readServiceDocument() {
ODataServiceDocumentRequest request =
odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
assertNotNull(request);
ODataRetrieveResponse<ODataServiceDocument> 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
@ -71,7 +83,7 @@ public class BasicITCase {
assertNotNull(request);
ODataRetrieveResponse<Edm> response = request.execute();
assertEquals(200, response.getStatusCode());
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
Edm edm = response.getBody();
@ -81,4 +93,33 @@ public class BasicITCase {
assertNotNull(edm.getTerm(new FullQualifiedName("Core.Description")));
assertEquals(2, edm.getSchemas().size());
}
@Test
public void readEntitySet() {
final ODataEntitySetRequest<ODataEntitySet> request = odata.getRetrieveRequestFactory()
.getEntitySetRequest(URI.create(SERVICE_URI + "/ESMixPrimCollComp"));
assertNotNull(request);
final ODataRetrieveResponse<ODataEntitySet> 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.<ODataAnnotation> emptyList(), entitySet.getAnnotations());
assertNull(entitySet.getDeltaLink());
final List<ODataEntity> 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());
}
}

View File

@ -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);

View File

@ -156,7 +156,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
assertNotNull(res);
final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
assertEquals(10, entitySet.getPayload().getCount());
assertEquals(Integer.valueOf(10), entitySet.getPayload().getCount());
}
private void rawRequest(final ODataFormat format) {

View File

@ -222,7 +222,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
ODataEntitySet employees = getClient().getRetrieveRequestFactory().
getEntitySetRequest(employeesURI).execute().getBody();
assertFalse(employees.getEntities().isEmpty());
final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.getCount());
final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.getEntities().size());
for (ODataEntity employee : employees.getEntities()) {
preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class),
employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));

View File

@ -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());
}
/**

View File

@ -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<String, Object> keyMap = new LinkedHashMap<String, Object>();
@ -202,7 +202,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
Collections.<String, ODataValue> singletonMap("count", count));
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
assertNotNull(getProductDetailsRes);
assertEquals(1, getProductDetailsRes.getCount());
assertEquals(1, getProductDetailsRes.getEntities().size());
// GetRelatedProduct
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();

View File

@ -80,7 +80,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
assertNotNull(res);
final ResWrap<ODataEntitySet> 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());

View File

@ -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().

View File

@ -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());
}
/**

View File

@ -45,7 +45,7 @@ public interface CommonODataEntitySet extends ODataInvokeResult {
*
* @return in-line count value.
*/
int getCount();
Integer getCount();
/**
* Sets in-line count.

View File

@ -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

View File

@ -36,11 +36,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE
super(next);
}
@Override
protected int getEntitiesSize() {
return entities.size();
}
@Override
public List<ODataEntity> getEntities() {
return entities;

View File

@ -43,11 +43,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE
super(next);
}
@Override
protected int getEntitiesSize() {
return entities.size();
}
@Override
public List<ODataEntity> getEntities() {
return entities;

View File

@ -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;
}

View File

@ -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;