[OLINGO-377] Merge branch 'master' into OLINGO-377-FIT
Conflicts: fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
This commit is contained in:
commit
45a46f86e9
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,21 +18,35 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.fit.tecsvc.client;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
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.CommonODataClient;
|
||||||
import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
|
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.request.retrieve.ODataServiceDocumentRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.client.api.v4.ODataClient;
|
import org.apache.olingo.client.api.v4.ODataClient;
|
||||||
import org.apache.olingo.client.core.ODataClientFactory;
|
import org.apache.olingo.client.core.ODataClientFactory;
|
||||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
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.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
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.format.ODataFormat;
|
||||||
import org.apache.olingo.fit.AbstractBaseTestITCase;
|
import org.apache.olingo.fit.AbstractBaseTestITCase;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -52,20 +66,18 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readServiceDocument() {
|
public void readServiceDocument() {
|
||||||
ODataServiceDocumentRequest request =
|
ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
|
||||||
odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
|
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
|
||||||
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
|
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
|
||||||
|
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
||||||
assertEquals(200, response.getStatusCode());
|
|
||||||
|
|
||||||
ODataServiceDocument serviceDocument = response.getBody();
|
ODataServiceDocument serviceDocument = response.getBody();
|
||||||
assertNotNull(serviceDocument);
|
assertNotNull(serviceDocument);
|
||||||
|
|
||||||
assertTrue(serviceDocument.getEntitySetNames().contains("ESAllPrim"));
|
assertThat(serviceDocument.getEntitySetNames(), hasItem("ESAllPrim"));
|
||||||
assertTrue(serviceDocument.getFunctionImportNames().contains("FICRTCollCTTwoPrim"));
|
assertThat(serviceDocument.getFunctionImportNames(), hasItem("FICRTCollCTTwoPrim"));
|
||||||
assertTrue(serviceDocument.getSingletonNames().contains("SIMedia"));
|
assertThat(serviceDocument.getSingletonNames(), hasItem("SIMedia"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -74,7 +86,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
|
||||||
ODataRetrieveResponse<Edm> response = request.execute();
|
ODataRetrieveResponse<Edm> response = request.execute();
|
||||||
assertEquals(200, response.getStatusCode());
|
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
||||||
|
|
||||||
Edm edm = response.getBody();
|
Edm edm = response.getBody();
|
||||||
|
|
||||||
|
@ -85,6 +97,35 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
assertEquals(2, edm.getSchemas().size());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
@Override protected CommonODataClient getClient() {
|
@Override protected CommonODataClient getClient() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||||
|
|
||||||
final ODataEntitySet entitySet = res.getBody();
|
final ODataEntitySet entitySet = res.getBody();
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
assertEquals(2, entitySet.getCount());
|
assertEquals(2, entitySet.getEntities().size());
|
||||||
|
|
||||||
for (ODataEntity entity : entitySet.getEntities()) {
|
for (ODataEntity entity : entitySet.getEntities()) {
|
||||||
final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
|
final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
|
||||||
assertNotNull(res);
|
assertNotNull(res);
|
||||||
|
|
||||||
final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
|
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) {
|
private void rawRequest(final ODataFormat format) {
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
|
||||||
ODataEntitySet employees = getClient().getRetrieveRequestFactory().
|
ODataEntitySet employees = getClient().getRetrieveRequestFactory().
|
||||||
getEntitySetRequest(employeesURI).execute().getBody();
|
getEntitySetRequest(employeesURI).execute().getBody();
|
||||||
assertFalse(employees.getEntities().isEmpty());
|
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()) {
|
for (ODataEntity employee : employees.getEntities()) {
|
||||||
preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class),
|
preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class),
|
||||||
employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
|
employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
||||||
req.setFormat(ODataFormat.ATOM);
|
req.setFormat(ODataFormat.ATOM);
|
||||||
final ODataEntitySet feed = req.execute().getBody();
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
assertEquals(feed.getEntities().size(), feed.getCount());
|
assertEquals(Integer.valueOf(feed.getEntities().size()), feed.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||||
getProductDetailsReq.setFormat(format);
|
getProductDetailsReq.setFormat(format);
|
||||||
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
||||||
assertNotNull(getProductDetailsRes);
|
assertNotNull(getProductDetailsRes);
|
||||||
assertEquals(1, getProductDetailsRes.getCount());
|
assertEquals(1, getProductDetailsRes.getEntities().size());
|
||||||
|
|
||||||
// GetRelatedProduct
|
// GetRelatedProduct
|
||||||
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
|
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
|
||||||
|
@ -202,7 +202,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||||
Collections.<String, ODataValue> singletonMap("count", count));
|
Collections.<String, ODataValue> singletonMap("count", count));
|
||||||
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
||||||
assertNotNull(getProductDetailsRes);
|
assertNotNull(getProductDetailsRes);
|
||||||
assertEquals(1, getProductDetailsRes.getCount());
|
assertEquals(1, getProductDetailsRes.getEntities().size());
|
||||||
|
|
||||||
// GetRelatedProduct
|
// GetRelatedProduct
|
||||||
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
|
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
|
||||||
assertNotNull(res);
|
assertNotNull(res);
|
||||||
|
|
||||||
final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
|
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",
|
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address",
|
||||||
entitySet.getPayload().getEntities().get(2).getProperty("HomeAddress").getComplexValue().getTypeName());
|
entitySet.getPayload().getEntities().get(2).getProperty("HomeAddress").getComplexValue().getTypeName());
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
||||||
productsReq.setFormat(format);
|
productsReq.setFormat(format);
|
||||||
final ODataEntitySet products = productsReq.execute().getBody();
|
final ODataEntitySet products = productsReq.execute().getBody();
|
||||||
assertNotNull(products);
|
assertNotNull(products);
|
||||||
assertEquals(5, products.getCount());
|
assertEquals(5, products.getEntities().size());
|
||||||
|
|
||||||
// GetProductsByAccessLevel
|
// GetProductsByAccessLevel
|
||||||
final ODataEnumValue accessLevel = getClient().getObjectFactory().
|
final ODataEnumValue accessLevel = getClient().getObjectFactory().
|
||||||
|
@ -165,7 +165,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
||||||
getFunctionImportInvokeRequest("GetAllProducts");
|
getFunctionImportInvokeRequest("GetAllProducts");
|
||||||
final ODataEntitySet products = productsReq.execute().getBody();
|
final ODataEntitySet products = productsReq.execute().getBody();
|
||||||
assertNotNull(products);
|
assertNotNull(products);
|
||||||
assertEquals(5, products.getCount());
|
assertEquals(5, products.getEntities().size());
|
||||||
|
|
||||||
// GetProductsByAccessLevel
|
// GetProductsByAccessLevel
|
||||||
final ODataEnumValue accessLevel = getClient().getObjectFactory().
|
final ODataEnumValue accessLevel = getClient().getObjectFactory().
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
||||||
|
|
||||||
final ODataEntitySet feed = req.execute().getBody();
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
assertEquals(feed.getEntities().size(), feed.getCount());
|
assertEquals(Integer.valueOf(feed.getEntities().size()), feed.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,7 +45,7 @@ public interface CommonODataEntitySet extends ODataInvokeResult {
|
||||||
*
|
*
|
||||||
* @return in-line count value.
|
* @return in-line count value.
|
||||||
*/
|
*/
|
||||||
int getCount();
|
Integer getCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets in-line count.
|
* Sets in-line count.
|
||||||
|
|
|
@ -59,11 +59,9 @@ public abstract class AbstractODataEntitySet extends AbstractODataPayload implem
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getEntitiesSize();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public Integer getCount() {
|
||||||
return count == null ? getEntitiesSize() : count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,11 +36,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE
|
||||||
super(next);
|
super(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getEntitiesSize() {
|
|
||||||
return entities.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ODataEntity> getEntities() {
|
public List<ODataEntity> getEntities() {
|
||||||
return entities;
|
return entities;
|
||||||
|
|
|
@ -43,11 +43,6 @@ public class ODataEntitySetImpl extends AbstractODataEntitySet implements ODataE
|
||||||
super(next);
|
super(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getEntitiesSize() {
|
|
||||||
return entities.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ODataEntity> getEntities() {
|
public List<ODataEntity> getEntities() {
|
||||||
return entities;
|
return entities;
|
||||||
|
|
|
@ -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.api.uri.UriResourceEntitySet;
|
||||||
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TechnicalProcessor implements CollectionProcessor, EntityProcessor {
|
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)
|
private EntitySet readEntitySetInternal(final EdmEntitySet edmEntitySet, final String serviceRoot)
|
||||||
throws DataProvider.DataProviderException {
|
throws DataProvider.DataProviderException {
|
||||||
EntitySet entitySet = dataProvider.readAll(edmEntitySet);
|
EntitySet entitySet = dataProvider.readAll(edmEntitySet);
|
||||||
entitySet.setNext(URI.create(serviceRoot + "/" + edmEntitySet.getEntityType().getName()));
|
// TODO: set count and next link
|
||||||
return entitySet;
|
return entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,12 +134,11 @@ public class ODataJsonSerializerTest {
|
||||||
ContextURL.Builder.create().entitySet(edmEntitySet).build());
|
ContextURL.Builder.create().entitySet(edmEntitySet).build());
|
||||||
final String resultString = IOUtils.toString(result);
|
final String resultString = IOUtils.toString(result);
|
||||||
|
|
||||||
Assert.assertTrue(resultString.matches("\\{"
|
Assert.assertThat(resultString, CoreMatchers.startsWith("{"
|
||||||
+ "\"@odata\\.context\":\"\\$metadata#ESAllPrim\","
|
+ "\"@odata.context\":\"$metadata#ESAllPrim\","
|
||||||
+ "\"@odata\\.count\":3,"
|
+ "\"@odata.count\":3,\"value\":["));
|
||||||
+ "\"value\":\\[.*\\],"
|
Assert.assertThat(resultString, CoreMatchers.endsWith("],"
|
||||||
+ "\"@odata\\.nextLink\":\"/next\""
|
+ "\"@odata.nextLink\":\"/next\"}"));
|
||||||
+ "\\}"));
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
|
|
Loading…
Reference in New Issue