Search in sources :

Example 1 with ClientComplexValue

use of org.apache.olingo.client.api.domain.ClientComplexValue 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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) ClientPrimitiveValue(org.apache.olingo.client.api.domain.ClientPrimitiveValue) ClientEntity(org.apache.olingo.client.api.domain.ClientEntity) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) ClientComplexValue(org.apache.olingo.client.api.domain.ClientComplexValue) Edm(org.apache.olingo.commons.api.edm.Edm) ClientServiceDocument(org.apache.olingo.client.api.domain.ClientServiceDocument) ClientEntitySet(org.apache.olingo.client.api.domain.ClientEntitySet) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ClientComplexValue (org.apache.olingo.client.api.domain.ClientComplexValue)1 ClientEntity (org.apache.olingo.client.api.domain.ClientEntity)1 ClientEntitySet (org.apache.olingo.client.api.domain.ClientEntitySet)1 ClientPrimitiveValue (org.apache.olingo.client.api.domain.ClientPrimitiveValue)1 ClientServiceDocument (org.apache.olingo.client.api.domain.ClientServiceDocument)1 Edm (org.apache.olingo.commons.api.edm.Edm)1 Test (org.junit.Test)1