use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2AppAPITest method testBatchRequest.
@Test
public void testBatchRequest() throws Exception {
final List<Olingo2BatchRequest> batchParts = new ArrayList<Olingo2BatchRequest>();
// Edm query
batchParts.add(Olingo2BatchQueryRequest.resourcePath(Olingo2AppImpl.METADATA).build());
// feed query
batchParts.add(Olingo2BatchQueryRequest.resourcePath(MANUFACTURERS).build());
// read
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).build());
// read with expand
final HashMap<String, String> queryParams = new HashMap<String, String>();
queryParams.put(SystemQueryOption.$expand.toString(), CARS);
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).queryParams(queryParams).build());
// create
final Map<String, Object> data = getEntityData();
batchParts.add(Olingo2BatchChangeRequest.resourcePath(MANUFACTURERS).contentId(TEST_RESOURCE_CONTENT_ID).operation(Operation.CREATE).body(data).build());
// update
final Map<String, Object> updateData = new HashMap<String, Object>(data);
@SuppressWarnings("unchecked") Map<String, Object> address = (Map<String, Object>) updateData.get(ADDRESS);
updateData.put("Name", "MyCarManufacturer Renamed");
address.put("Street", "Main Street");
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.UPDATE).body(updateData).build());
// delete
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.DELETE).build());
final TestOlingo2ResponseHandler<List<Olingo2BatchResponse>> responseHandler = new TestOlingo2ResponseHandler<List<Olingo2BatchResponse>>();
// read to verify delete
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_CREATE_MANUFACTURER).build());
olingoApp.batch(edm, batchParts, responseHandler);
final List<Olingo2BatchResponse> responseParts = responseHandler.await(15, TimeUnit.MINUTES);
assertEquals("Batch responses expected", 8, responseParts.size());
assertNotNull(responseParts.get(0).getBody());
final ODataFeed feed = (ODataFeed) responseParts.get(1).getBody();
assertNotNull(feed);
LOG.info("Batch feed: {}", prettyPrint(feed));
ODataEntry dataEntry = (ODataEntry) responseParts.get(2).getBody();
assertNotNull(dataEntry);
LOG.info("Batch read entry: {}", prettyPrint(dataEntry));
dataEntry = (ODataEntry) responseParts.get(3).getBody();
assertNotNull(dataEntry);
LOG.info("Batch read entry with expand: {}", prettyPrint(dataEntry));
dataEntry = (ODataEntry) responseParts.get(4).getBody();
assertNotNull(dataEntry);
LOG.info("Batch create entry: {}", prettyPrint(dataEntry));
assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), responseParts.get(5).getStatusCode());
assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), responseParts.get(6).getStatusCode());
assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), responseParts.get(7).getStatusCode());
final Exception exception = (Exception) responseParts.get(7).getBody();
assertNotNull(exception);
LOG.info("Batch retrieve deleted entry: {}", exception);
}
use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2ComponentTest method testBatch.
@Test
public void testBatch() throws Exception {
final List<Olingo2BatchRequest> batchParts = new ArrayList<Olingo2BatchRequest>();
// 1. Edm query
batchParts.add(Olingo2BatchQueryRequest.resourcePath(Olingo2AppImpl.METADATA).build());
// 2. feed query
batchParts.add(Olingo2BatchQueryRequest.resourcePath(MANUFACTURERS).build());
// 3. read
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).build());
// 4. read with expand
final HashMap<String, String> queryParams = new HashMap<String, String>();
queryParams.put(SystemQueryOption.$expand.toString(), CARS);
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).queryParams(queryParams).build());
// 5. create
final Map<String, Object> data = getEntityData();
batchParts.add(Olingo2BatchChangeRequest.resourcePath(MANUFACTURERS).contentId(TEST_RESOURCE_CONTENT_ID).operation(Operation.CREATE).body(data).build());
// 6. update address in created entry
final Map<String, Object> updateData = new HashMap<String, Object>(data);
Map<String, Object> address = (Map<String, Object>) updateData.get(ADDRESS);
address.put("Street", "Main Street");
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE_ADDRESS).operation(Operation.UPDATE).body(address).build());
// 7. update
updateData.put("Name", "MyCarManufacturer Renamed");
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.UPDATE).body(updateData).build());
// 8. delete
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.DELETE).build());
// 9. read to verify delete
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_CREATE_MANUFACTURER).build());
// execute batch request
final List<Olingo2BatchResponse> responseParts = requestBody("direct://BATCH", batchParts);
assertNotNull("Batch response", responseParts);
assertEquals("Batch responses expected", 9, responseParts.size());
final Edm edm = (Edm) responseParts.get(0).getBody();
assertNotNull(edm);
LOG.info("Edm entity sets: {}", edm.getEntitySets());
final ODataFeed feed = (ODataFeed) responseParts.get(1).getBody();
assertNotNull(feed);
LOG.info("Read feed: {}", feed.getEntries());
ODataEntry dataEntry = (ODataEntry) responseParts.get(2).getBody();
assertNotNull(dataEntry);
LOG.info("Read entry: {}", dataEntry.getProperties());
dataEntry = (ODataEntry) responseParts.get(3).getBody();
assertNotNull(dataEntry);
LOG.info("Read entry with $expand: {}", dataEntry.getProperties());
dataEntry = (ODataEntry) responseParts.get(4).getBody();
assertNotNull(dataEntry);
LOG.info("Created entry: {}", dataEntry.getProperties());
int statusCode = responseParts.get(5).getStatusCode();
assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
LOG.info("Update address status: {}", statusCode);
statusCode = responseParts.get(6).getStatusCode();
assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
LOG.info("Update entry status: {}", statusCode);
statusCode = responseParts.get(7).getStatusCode();
assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
LOG.info("Delete status: {}", statusCode);
assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), responseParts.get(8).getStatusCode());
final Exception exception = (Exception) responseParts.get(8).getBody();
assertNotNull(exception);
LOG.info("Read deleted entry exception: {}", exception);
}
Aggregations