Search in sources :

Example 1 with MultiSteps

use of org.apache.camel.examples.MultiSteps in project camel by apache.

the class JpaWithNativeQueryWithResultClassTest method assertReceivedResult.

/**
     * We receive a MultiSteps object, because we call entityManager.createNativeQuery(nativeQuery, MultiSteps.class)
     */
@Override
protected void assertReceivedResult(Exchange exchange) {
    assertNotNull(exchange);
    MultiSteps result = (MultiSteps) exchange.getIn().getBody();
    assertNotNull("Received an object array", result);
    assertEquals("address property", "foo@bar.com", result.getAddress());
}
Also used : MultiSteps(org.apache.camel.examples.MultiSteps)

Example 2 with MultiSteps

use of org.apache.camel.examples.MultiSteps in project camel by apache.

the class JpaProducerWithQueryTest method testProducerWithQuery.

@Test
public void testProducerWithQuery() throws Exception {
    template.sendBody("direct:deleteMultiSteps", "");
    MultiSteps m1 = new MultiSteps();
    m1.setStep(1);
    template.sendBody("direct:addMultiSteps", m1);
    MultiSteps m2 = new MultiSteps();
    m2.setStep(2);
    template.sendBody("direct:addMultiSteps", m2);
    Object answer = template.requestBody("direct:query", "");
    List list = (List) answer;
    assertEquals(1, list.size());
    assertEquals(1, ((MultiSteps) list.get(0)).getStep());
    answer = template.requestBody("direct:deleteMultiSteps", "");
    assertEquals(2, ((Integer) answer).intValue());
}
Also used : MultiSteps(org.apache.camel.examples.MultiSteps) List(java.util.List) Test(org.junit.Test)

Example 3 with MultiSteps

use of org.apache.camel.examples.MultiSteps in project camel by apache.

the class JpaProducerWithQueryTest method testProducerWithNativeQueryAndResultClass.

@Test
public void testProducerWithNativeQueryAndResultClass() throws Exception {
    template.sendBody("direct:deleteMultiSteps", "");
    MultiSteps m1 = new MultiSteps();
    m1.setStep(1);
    template.sendBody("direct:addMultiSteps", m1);
    MultiSteps m2 = new MultiSteps();
    m2.setStep(2);
    template.sendBody("direct:addMultiSteps", m2);
    Object answer = template.requestBody("direct:nativeQueryWithResultClass", "");
    List list = (List) answer;
    assertEquals(1, list.size());
    assertEquals(1, ((MultiSteps) list.get(0)).getStep());
    answer = template.requestBody("direct:deleteMultiSteps", "");
    assertEquals(2, ((Integer) answer).intValue());
}
Also used : MultiSteps(org.apache.camel.examples.MultiSteps) List(java.util.List) Test(org.junit.Test)

Example 4 with MultiSteps

use of org.apache.camel.examples.MultiSteps in project camel by apache.

the class JpaProducerWithQueryTest method setUp.

@Before
public void setUp() throws Exception {
    camelContext = new DefaultCamelContext();
    SimpleRegistry registry = new SimpleRegistry();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("custName", "${body}");
    // bind the params
    registry.put("params", params);
    camelContext.setRegistry(registry);
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:query").to("jpa://" + MultiSteps.class.getName() + "?query=select o from " + MultiSteps.class.getName() + " o where o.step = 1");
            from("direct:namedQuery").to("jpa://" + Customer.class.getName() + "?namedQuery=findAllCustomersWithName&parameters=#params");
            from("direct:nativeQuery").to("jpa://" + MultiSteps.class.getName() + "?nativeQuery=select * from MultiSteps where step = 1");
            from("direct:nativeQueryWithResultClass").to("jpa://" + MultiSteps.class.getName() + "?resultClass=org.apache.camel.examples.MultiSteps&nativeQuery=select * from MultiSteps where step = 1");
            from("direct:addCustomer").to("jpa://" + Customer.class.getName());
            from("direct:deleteCustomers").to("jpa://" + Customer.class.getName() + "?query=delete from " + Customer.class.getName());
            from("direct:addMultiSteps").to("jpa://" + MultiSteps.class.getName());
            from("direct:deleteMultiSteps").to("jpa://" + MultiSteps.class.getName() + "?nativeQuery=delete from MultiSteps");
        }
    });
    template = camelContext.createProducerTemplate();
    ServiceHelper.startServices(template, camelContext);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) Customer(org.apache.camel.examples.Customer) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) MultiSteps(org.apache.camel.examples.MultiSteps) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

Example 5 with MultiSteps

use of org.apache.camel.examples.MultiSteps in project camel by apache.

the class JpaProducerWithQueryTest method testProducerWithNativeQuery.

@Test
public void testProducerWithNativeQuery() throws Exception {
    template.sendBody("direct:deleteMultiSteps", "");
    MultiSteps m1 = new MultiSteps();
    m1.setStep(1);
    template.sendBody("direct:addMultiSteps", m1);
    MultiSteps m2 = new MultiSteps();
    m2.setStep(2);
    template.sendBody("direct:addMultiSteps", m2);
    Object answer = template.requestBody("direct:nativeQuery", "");
    List list = (List) answer;
    assertEquals(1, list.size());
    assertEquals(1, ((Object[]) list.get(0))[2]);
    answer = template.requestBody("direct:deleteMultiSteps", "");
    assertEquals(2, ((Integer) answer).intValue());
}
Also used : MultiSteps(org.apache.camel.examples.MultiSteps) List(java.util.List) Test(org.junit.Test)

Aggregations

MultiSteps (org.apache.camel.examples.MultiSteps)7 List (java.util.List)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)1 EntityManager (javax.persistence.EntityManager)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 Customer (org.apache.camel.examples.Customer)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)1 Before (org.junit.Before)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1