[OLINGO-1004] Deleted Entity Create Test
Duplicated in BasicITCase
This commit is contained in:
parent
bed8b4d02b
commit
507e4deb5a
|
@ -30,9 +30,6 @@ import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
|
|||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.client.api.domain.ClientEntity;
|
||||
import org.apache.olingo.client.api.domain.ClientEntitySet;
|
||||
import org.apache.olingo.client.api.domain.ClientInlineEntitySet;
|
||||
import org.apache.olingo.client.api.domain.ClientLink;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
|
@ -41,15 +38,13 @@ import org.junit.Test;
|
|||
public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void atomCreateAndDelete() {
|
||||
createAndDeleteOrder(testStaticServiceRootURL, ContentType.APPLICATION_ATOM_XML, 1000);
|
||||
public void atomOnContained() {
|
||||
onContained(ContentType.APPLICATION_ATOM_XML);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonCreateAndDelete() {
|
||||
createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON, 1001);
|
||||
createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON_NO_METADATA, 1001);
|
||||
createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON_FULL_METADATA, 1001);
|
||||
public void jsonOnContained() {
|
||||
onContained(ContentType.JSON);
|
||||
}
|
||||
|
||||
private void onContained(final ContentType contentType) {
|
||||
|
@ -99,93 +94,4 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
|||
final int sizeEnd = instruments.getCount();
|
||||
assertEquals(sizeBefore, sizeEnd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomOnContained() {
|
||||
onContained(ContentType.APPLICATION_ATOM_XML);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonOnContained() {
|
||||
onContained(ContentType.JSON);
|
||||
}
|
||||
|
||||
private void deepInsert(final ContentType contentType, final int productId, final int productDetailId)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final ClientEntity product = getClient().getObjectFactory().
|
||||
newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Product"));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("Latte")));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityPerUnit",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("100g Bag")));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("UnitPrice",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(3.24f)));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityInStock",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(100)));
|
||||
product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Discontinued",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false)));
|
||||
product.getProperties().add(getClient().getObjectFactory().newEnumProperty("UserAccess",
|
||||
getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute")));
|
||||
product.getProperties().add(getClient().getObjectFactory().newEnumProperty("SkinColor",
|
||||
getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
|
||||
product.getProperties().add(getClient().getObjectFactory().newCollectionProperty("CoverColors",
|
||||
getClient().getObjectFactory().
|
||||
newCollectionValue("Microsoft.Test.OData.Services.ODataWCFService.Color")));
|
||||
product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Green"));
|
||||
product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Red"));
|
||||
|
||||
final ClientEntity detail = getClient().getObjectFactory().
|
||||
newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"));
|
||||
detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
|
||||
detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductDetailID",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productDetailId)));
|
||||
detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductName",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("LatteHQ")));
|
||||
detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Description",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("High-Quality Milk")));
|
||||
|
||||
final ClientEntitySet details = getClient().getObjectFactory().newEntitySet();
|
||||
details.getEntities().add(detail);
|
||||
|
||||
final ClientInlineEntitySet inlineDetails = getClient().getObjectFactory().
|
||||
newDeepInsertEntitySet("Details", details);
|
||||
product.addLink(inlineDetails);
|
||||
|
||||
final ODataEntityCreateRequest<ClientEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
|
||||
getClient().newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Products").build(), product);
|
||||
req.setFormat(contentType);
|
||||
final ODataEntityCreateResponse<ClientEntity> res = req.execute();
|
||||
assertEquals(201, res.getStatusCode());
|
||||
|
||||
final ClientEntity createdProduct = res.getBody();
|
||||
assertEquals(productId,
|
||||
createdProduct.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
final ClientLink createdLink = createdProduct.getNavigationLink("Details");
|
||||
assertNotNull(createdLink);
|
||||
|
||||
final ClientEntitySet createdProductDetails =
|
||||
getClient().getRetrieveRequestFactory().getEntitySetRequest(createdLink.getLink()).execute().getBody();
|
||||
assertNotNull(createdProductDetails);
|
||||
assertEquals(productDetailId, createdProductDetails.getEntities().iterator().next().
|
||||
getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomDeepInsert() throws EdmPrimitiveTypeException {
|
||||
deepInsert(ContentType.APPLICATION_ATOM_XML, 10, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonDeepInsert() throws EdmPrimitiveTypeException {
|
||||
deepInsert(ContentType.JSON_FULL_METADATA, 11, 11);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue