use of org.apache.olingo.commons.api.edm.Edm in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method testRead.
@Test
public void testRead() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.addRoutes(new RouteBuilder() {
public void configure() {
// test routes for read
from("direct://readmetadata").to("olingo4://read/$metadata");
from("direct://readdocument").to("olingo4://read/");
from("direct://readentities").to("olingo4://read/People?$top=5&$orderby=FirstName asc");
from("direct://readcount").to("olingo4://read/People/$count");
from("direct://readvalue").to("olingo4://read/People('russellwhyte')/Gender/$value");
from("direct://readsingleprop").to("olingo4://read/Airports('KSFO')/Name");
from("direct://readcomplexprop").to("olingo4://read/Airports('KSFO')/Location");
from("direct://readentitybyid").to("olingo4://read/People('russellwhyte')");
from("direct://callunboundfunction").to("olingo4://read/GetNearestAirport(lat=33,lon=-118)");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
final Map<String, Object> headers = new HashMap<String, Object>();
// Read metadata ($metadata) object
final Edm metadata = (Edm) template.requestBodyAndHeaders("direct://readmetadata", null, headers);
Assert.assertNotNull(metadata);
Assert.assertEquals(1, metadata.getSchemas().size());
// Read service document object
final ClientServiceDocument document = (ClientServiceDocument) template.requestBodyAndHeaders("direct://readdocument", null, headers);
Assert.assertNotNull(document);
Assert.assertTrue(document.getEntitySets().size() > 1);
LOG.info("Service document has {} entity sets", document.getEntitySets().size());
// Read entity set of the People object
final ClientEntitySet entities = (ClientEntitySet) template.requestBodyAndHeaders("direct://readentities", null, headers);
Assert.assertNotNull(entities);
Assert.assertEquals(5, entities.getEntities().size());
// Read object count with query options passed through header
final Long count = (Long) template.requestBodyAndHeaders("direct://readcount", null, headers);
Assert.assertEquals(20, count.intValue());
final ClientPrimitiveValue value = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readvalue", null, headers);
LOG.info("Client value \"{}\" has type {}", value.toString(), value.getTypeName());
Assert.assertEquals("Male", value.asPrimitive().toString());
final ClientPrimitiveValue singleProperty = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readsingleprop", null, headers);
Assert.assertTrue(singleProperty.isPrimitive());
Assert.assertEquals("San Francisco International Airport", singleProperty.toString());
final ClientComplexValue complexProperty = (ClientComplexValue) template.requestBodyAndHeaders("direct://readcomplexprop", null, headers);
Assert.assertTrue(complexProperty.isComplex());
Assert.assertEquals("San Francisco", complexProperty.get("City").getComplexValue().get("Name").getValue().toString());
final ClientEntity entity = (ClientEntity) template.requestBodyAndHeaders("direct://readentitybyid", null, headers);
Assert.assertNotNull(entity);
Assert.assertEquals("Russell", entity.getProperty("FirstName").getValue().toString());
final ClientEntity unbFuncReturn = (ClientEntity) template.requestBodyAndHeaders("direct://callunboundfunction", null, headers);
Assert.assertNotNull(unbFuncReturn);
} finally {
camelctx.stop();
}
}
Aggregations