[OLINGO-1004] Delete some EntityRetrieve Tests

They are duplicated in BasicITCase and ExpandWithSystemQueryOptionsITCase
This commit is contained in:
Christian Amend 2016-08-12 12:00:00 +02:00
parent 507e4deb5a
commit 5f11f5b1d2
1 changed files with 0 additions and 279 deletions

View File

@ -20,33 +20,17 @@ package org.apache.olingo.fit.base;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import java.sql.Timestamp;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.EdmEnabledODataClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
import org.apache.olingo.client.api.communication.response.ODataRawResponse;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.data.ResWrap;
import org.apache.olingo.client.api.domain.ClientEntity;
import org.apache.olingo.client.api.domain.ClientEntitySet;
import org.apache.olingo.client.api.domain.ClientInlineEntity;
import org.apache.olingo.client.api.domain.ClientInlineEntitySet;
import org.apache.olingo.client.api.domain.ClientLink;
import org.apache.olingo.client.api.domain.ClientLinkType;
import org.apache.olingo.client.api.domain.ClientProperty;
import org.apache.olingo.client.api.uri.URIBuilder;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ContentType;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -54,269 +38,6 @@ import org.junit.Test;
*/
public class EntityRetrieveTestITCase extends AbstractTestITCase {
private void withInlineEntity(final ODataClient client, final ContentType contentType) {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
final ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().
getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
final ClientEntity entity = res.getBody();
assertNotNull(entity);
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
assertTrue(entity.getProperty("Home").hasPrimitiveValue());
assertEquals("Edm.GeographyPoint", entity.getProperty("Home").getPrimitiveValue().getTypeName());
// In JSON with minimal metadata, links are not provided
if (contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)
|| (contentType.isCompatible(ContentType.JSON)
&& ContentType.VALUE_ODATA_METADATA_FULL
.equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA)))) {
assertEquals(testStaticServiceRootURL + "/Customers(1)", entity.getEditLink().toASCIIString());
assertEquals(3, entity.getNavigationLinks().size());
if (ContentType.APPLICATION_ATOM_XML == contentType) {
assertTrue(entity.getAssociationLinks().isEmpty());
// In JSON, association links for each $ref link will exist.
}
boolean found = false;
for (ClientLink link : entity.getNavigationLinks()) {
if (link instanceof ClientInlineEntity) {
final ClientEntity inline = ((ClientInlineEntity) link).getEntity();
assertNotNull(inline);
final List<? extends ClientProperty> properties = inline.getProperties();
assertEquals(5, properties.size());
assertTrue(properties.get(0).getName().equals("CompanyID")
|| properties.get(1).getName().equals("CompanyID")
|| properties.get(2).getName().equals("CompanyID")
|| properties.get(3).getName().equals("CompanyID")
|| properties.get(4).getName().equals("CompanyID"));
assertTrue(properties.get(0).getValue().toString().equals("0")
|| properties.get(1).getValue().toString().equals("0")
|| properties.get(2).getValue().toString().equals("0")
|| properties.get(3).getValue().toString().equals("0")
|| properties.get(4).getValue().toString().equals("0"));
found = true;
}
}
assertTrue(found);
}
}
@Ignore
@Test
public void withInlineEntityFromAtom() {
withInlineEntity(client, ContentType.APPLICATION_ATOM_XML);
}
@Test
public void withInlineEntityFromFullJSON() {
withInlineEntity(client, ContentType.JSON_FULL_METADATA);
}
@Test
public void withInlineEntityFromJSON() {
withInlineEntity(edmClient, ContentType.JSON);
}
private void withInlineEntitySet(final ODataClient client, final ContentType contentType) {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
final ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().
getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
final ClientEntity entity = res.getBody();
assertNotNull(entity);
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
// In JSON with minimal metadata, links are not provided
if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || contentType.equals(ContentType.JSON_FULL_METADATA)) {
boolean found = false;
for (ClientLink link : entity.getNavigationLinks()) {
if (link instanceof ClientInlineEntitySet) {
final ClientEntitySet inline = ((ClientInlineEntitySet) link).getEntitySet();
assertNotNull(inline);
found = true;
}
}
assertTrue(found);
}
}
@Ignore
@Test
public void withInlineEntitySetFromAtom() {
withInlineEntitySet(client, ContentType.APPLICATION_ATOM_XML);
}
@Test
public void withInlineEntitySetFromFullJSON() {
withInlineEntitySet(client, ContentType.JSON_FULL_METADATA);
}
@Test
public void withInlineEntitySetFromJSON() {
withInlineEntitySet(edmClient, ContentType.JSON);
}
private void rawRequest(final ContentType contentType) {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("People").appendKeySegment(5);
final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
req.setFormat(contentType.toContentTypeString());
final ODataRawResponse res = req.execute();
assertNotNull(res);
final ResWrap<ClientEntitySet> entitySet = res.getBodyAs(ClientEntitySet.class);
assertNull(entitySet);
final ResWrap<ClientEntity> entity = res.getBodyAs(ClientEntity.class);
assertTrue(entity.getPayload().getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/People(5)"));
}
@Test
public void rawRequestAsAtom() {
rawRequest(ContentType.APPLICATION_ATOM_XML);
}
@Test
public void rawRequestAsJSON() {
// this needs to be full, otherwise reference will not be provided
rawRequest(ContentType.JSON_FULL_METADATA);
}
private void multiKey(final ContentType contentType) throws EdmPrimitiveTypeException {
final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
multiKey.put("ProductID", "6");
multiKey.put("ProductDetailID", 1);
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("ProductDetails").appendKeySegment(multiKey);
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
final ClientEntity entity = res.getBody();
assertNotNull(entity);
assertEquals(Integer.valueOf(1),
entity.getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class));
}
@Test
public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
multiKey(ContentType.APPLICATION_ATOM_XML);
}
@Test
public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
multiKey(ContentType.JSON_FULL_METADATA);
}
private void checkForETag(final ODataClient client, final ContentType contentType) {
final URIBuilder uriBuilder =
client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
assertEquals(200, res.getStatusCode());
final String etag = res.getETag();
assertTrue(StringUtils.isNotBlank(etag));
final ClientEntity order = res.getBody();
assertEquals(etag, order.getETag());
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Order", order.getTypeName().toString());
assertEquals("Edm.Int32", order.getProperty("OrderID").getPrimitiveValue().getTypeName());
assertEquals("Edm.DateTimeOffset", order.getProperty("OrderDate").getPrimitiveValue().getTypeName());
assertEquals("Edm.Duration", order.getProperty("ShelfLife").getPrimitiveValue().getTypeName());
assertEquals("Collection(Edm.Duration)", order.getProperty("OrderShelfLifes").getCollectionValue().getTypeName());
}
@Test
public void checkForETagAsAtom() {
checkForETag(client, ContentType.APPLICATION_ATOM_XML);
}
@Test
public void checkForETagAsFullJSON() {
checkForETag(client, ContentType.JSON_FULL_METADATA);
}
@Test
public void checkForETagAsJSON() {
checkForETag(edmClient, ContentType.JSON);
}
@Test(expected = IllegalArgumentException.class)
public void issue99() {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ContentType.JSON);
// this statement should cause an IllegalArgumentException bearing JsonParseException
// since we are attempting to parse an EntitySet as if it was an Entity
req.execute().getBody();
}
private void reference(final ContentType contentType) {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
appendRefSegment();
ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
ODataRetrieveResponse<ClientEntity> res = req.execute();
assertNotNull(res);
final ClientEntity entity = res.getBody();
assertNotNull(entity);
assertTrue(entity.getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
final URI referenceURI = client.newURIBuilder(testStaticServiceRootURL).
appendEntityIdSegment(entity.getId().toASCIIString()).build();
req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
req.setFormat(contentType);
res = req.execute();
assertNotNull(res);
assertNotNull(res.getBody());
}
@Test
public void atomReference() {
reference(ContentType.APPLICATION_ATOM_XML);
}
@Test
public void jsonReference() {
reference(ContentType.JSON_FULL_METADATA);
}
private void contained(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException {
final URI uri = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Accounts").appendKeySegment(101).