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));
}
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());
}
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);
}
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);
}
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));
}
Aggregations