Search in sources :

Example 16 with Edm

use of org.apache.olingo.odata2.api.edm.Edm 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);
}
Also used : ODataFeed(org.apache.olingo.odata2.api.ep.feed.ODataFeed) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Olingo2BatchRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest) Edm(org.apache.olingo.odata2.api.edm.Edm) Olingo2BatchResponse(org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse) ODataEntry(org.apache.olingo.odata2.api.ep.entry.ODataEntry) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)11 Test (org.junit.Test)8 Map (java.util.Map)7 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Olingo2BatchRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest)5 ODataEntry (org.apache.olingo.odata2.api.ep.entry.ODataEntry)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Olingo2BatchResponse (org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse)4 EdmEntitySet (org.apache.olingo.odata2.api.edm.EdmEntitySet)4 ODataFeed (org.apache.olingo.odata2.api.ep.feed.ODataFeed)4 List (java.util.List)3 HttpStatusCodes (org.apache.olingo.odata2.api.commons.HttpStatusCodes)3 Edm (org.apache.olingo.odata2.api.edm.Edm)3 EdmProperty (org.apache.olingo.odata2.api.edm.EdmProperty)3 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)3 ODataResponse (org.apache.olingo.odata2.api.processor.ODataResponse)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Olingo2BatchQueryRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest)2 ContentType (org.apache.http.entity.ContentType)2