Search in sources :

Example 11 with Edm

use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.

the class Olingo2AppAPITest method testReadUnparsedFeed.

@Test
public void testReadUnparsedFeed() throws Exception {
    final TestOlingo2ResponseHandler<InputStream> responseHandler = new TestOlingo2ResponseHandler<InputStream>();
    olingoApp.uread(edm, MANUFACTURERS, null, responseHandler);
    final InputStream rawfeed = responseHandler.await();
    assertNotNull("Data feed", rawfeed);
    // for this test, we just let EP to verify the stream data 
    final ODataFeed dataFeed = EntityProvider.readFeed(TEST_FORMAT_STRING, edmEntitySetMap.get(MANUFACTURERS), rawfeed, EntityProviderReadProperties.init().build());
    LOG.info("Entries:  {}", prettyPrint(dataFeed));
}
Also used : ODataFeed(org.apache.olingo.odata2.api.ep.feed.ODataFeed) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 12 with Edm

use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.

the class Olingo2AppAPITest method testReadUpdateProperties.

@Test
public void testReadUpdateProperties() throws Exception {
    // test simple property Manufacturer.Founded
    final TestOlingo2ResponseHandler<Map<String, Object>> propertyHandler = new TestOlingo2ResponseHandler<Map<String, Object>>();
    olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, null, propertyHandler);
    Calendar founded = (Calendar) propertyHandler.await().get(FOUNDED_PROPERTY);
    LOG.info("Founded property {}", founded.toString());
    final TestOlingo2ResponseHandler<Calendar> valueHandler = new TestOlingo2ResponseHandler<Calendar>();
    olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_VALUE, null, valueHandler);
    founded = valueHandler.await();
    LOG.info("Founded property {}", founded.toString());
    final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler = new TestOlingo2ResponseHandler<HttpStatusCodes>();
    final HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put(FOUNDED_PROPERTY, new Date());
    //        olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, properties, statusHandler);
    // requires a plain Date for XML
    olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, new Date(), statusHandler);
    LOG.info("Founded property updated with status {}", statusHandler.await().getStatusCode());
    statusHandler.reset();
    olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_VALUE, new Date(), statusHandler);
    LOG.info("Founded property updated with status {}", statusHandler.await().getStatusCode());
    // test complex property Manufacturer.Address
    propertyHandler.reset();
    olingoApp.read(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, null, propertyHandler);
    final Map<String, Object> address = propertyHandler.await();
    LOG.info("Address property {}", prettyPrint(address, 0));
    statusHandler.reset();
    address.clear();
    // Olingo2 sample server MERGE/PATCH behaves like PUT!!!
    //        address.put("Street", "Main Street");
    address.put("Street", "Star Street 137");
    address.put("City", "Stuttgart");
    address.put("ZipCode", "70173");
    address.put("Country", "Germany");
    //        olingoApp.patch(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, address, statusHandler);
    olingoApp.merge(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, address, statusHandler);
    LOG.info("Address property updated with status {}", statusHandler.await().getStatusCode());
}
Also used : HashMap(java.util.HashMap) HttpStatusCodes(org.apache.olingo.odata2.api.commons.HttpStatusCodes) Calendar(java.util.Calendar) Date(java.util.Date) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with Edm

use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.

the class Olingo2AppAPITest method setupClient.

protected static void setupClient() throws Exception {
    olingoApp = new Olingo2AppImpl(TEST_SERVICE_URL + "/");
    olingoApp.setContentType(TEST_FORMAT_STRING);
    LOG.info("Read Edm ");
    final TestOlingo2ResponseHandler<Edm> responseHandler = new TestOlingo2ResponseHandler<Edm>();
    olingoApp.read(null, Olingo2AppImpl.METADATA, null, responseHandler);
    edm = responseHandler.await();
    LOG.info("Read default EntityContainer:  {}", responseHandler.await().getDefaultEntityContainer().getName());
    edmEntitySetMap = new HashMap<String, EdmEntitySet>();
    for (EdmEntitySet ees : edm.getEntitySets()) {
        edmEntitySetMap.put(ees.getName(), ees);
    }
    // wait for generated data to be registered in server
    Thread.sleep(2000);
}
Also used : Olingo2AppImpl(org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl) EdmEntitySet(org.apache.olingo.odata2.api.edm.EdmEntitySet) Edm(org.apache.olingo.odata2.api.edm.Edm)

Example 14 with Edm

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

Example 15 with Edm

use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.

the class Olingo2AppAPITest method testReadEntry.

@Test
public void testReadEntry() throws Exception {
    final TestOlingo2ResponseHandler<ODataEntry> responseHandler = new TestOlingo2ResponseHandler<ODataEntry>();
    olingoApp.read(edm, TEST_MANUFACTURER, null, responseHandler);
    ODataEntry entry = responseHandler.await();
    LOG.info("Single Entry:  {}", prettyPrint(entry));
    responseHandler.reset();
    olingoApp.read(edm, TEST_CAR, null, responseHandler);
    entry = responseHandler.await();
    LOG.info("Single Entry:  {}", prettyPrint(entry));
    responseHandler.reset();
    final Map<String, String> queryParams = new HashMap<String, String>();
    queryParams.put(SystemQueryOption.$expand.toString(), CARS);
    olingoApp.read(edm, TEST_MANUFACTURER, queryParams, responseHandler);
    ODataEntry entryExpanded = responseHandler.await();
    LOG.info("Single Entry with expanded Cars relation:  {}", prettyPrint(entryExpanded));
}
Also used : HashMap(java.util.HashMap) ODataEntry(org.apache.olingo.odata2.api.ep.entry.ODataEntry) 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