Search in sources :

Example 66 with List

use of java.util.List in project camel by apache.

the class JdbcStatementParametersTest method testMax5Rows.

@SuppressWarnings("rawtypes")
@Test
public void testMax5Rows() throws Exception {
    List rows = template.requestBody("jdbc:testdb?statement.maxRows=5&statement.fetchSize=50", "select * from customer order by id", List.class);
    assertEquals(3, rows.size());
    assertEquals(3, context.getEndpoints().size());
}
Also used : List(java.util.List) Test(org.junit.Test)

Example 67 with List

use of java.util.List in project camel by apache.

the class HttpProducerTwoParametersWithSameKeyTest method testTwoHeadersWithSameKeyHeader.

@Test
public void testTwoHeadersWithSameKeyHeader() throws Exception {
    Exchange out = template.request("http://localhost:{{port}}/myapp", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(null);
            exchange.getIn().setHeader("from", "me");
            List<String> list = new ArrayList<String>();
            list.add("foo");
            list.add("bar");
            exchange.getIn().setHeader("to", list);
        }
    });
    assertNotNull(out);
    assertFalse("Should not fail", out.isFailed());
    assertEquals("OK", out.getOut().getBody(String.class));
    assertEquals("yes", out.getOut().getHeader("bar"));
    List<?> foo = out.getOut().getHeader("foo", List.class);
    assertNotNull(foo);
    assertEquals(2, foo.size());
    assertEquals("123", foo.get(0));
    assertEquals("456", foo.get(1));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 68 with List

use of java.util.List in project camel by apache.

the class RestJettyPostJsonPojoListTest method testPostPojoList.

@Test
public void testPostPojoList() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 456, \"name\": \"John Doe\"} ]";
    template.sendBody("http://localhost:" + getPort() + "/users/new", body);
    assertMockEndpointsSatisfied();
    List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
    assertNotNull(list);
    assertEquals(2, list.size());
    UserPojo user = (UserPojo) list.get(0);
    assertEquals(123, user.getId());
    assertEquals("Donald Duck", user.getName());
    user = (UserPojo) list.get(1);
    assertEquals(456, user.getId());
    assertEquals("John Doe", user.getName());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) List(java.util.List) BaseJettyTest(org.apache.camel.component.jetty.BaseJettyTest) Test(org.junit.Test)

Example 69 with List

use of java.util.List in project camel by apache.

the class JpaPollingConsumer method receive.

@Override
public Exchange receive() {
    // resolve the entity manager before evaluating the expression
    final EntityManager entityManager = getTargetEntityManager(null, entityManagerFactory, getEndpoint().isUsePassedInEntityManager(), getEndpoint().isSharedEntityManager(), true);
    Object out = transactionTemplate.execute(new TransactionCallback<Object>() {

        public Object doInTransaction(TransactionStatus status) {
            if (getEndpoint().isJoinTransaction()) {
                entityManager.joinTransaction();
            }
            Query query = getQueryFactory().createQuery(entityManager);
            configureParameters(query);
            if (getEndpoint().isConsumeLockEntity()) {
                query.setLockMode(getLockModeType());
            }
            LOG.trace("Created query {}", query);
            Object answer;
            try {
                List<?> results = query.getResultList();
                if (results != null && results.size() == 1) {
                    // we only have 1 entity so return that
                    answer = results.get(0);
                } else {
                    // we have more data so return a list
                    answer = results;
                }
                // commit
                LOG.debug("Flushing EntityManager");
                entityManager.flush();
                // must clear after flush
                entityManager.clear();
            } catch (PersistenceException e) {
                LOG.info("Disposing EntityManager {} on {} due to coming transaction rollback", entityManager, this);
                entityManager.close();
                throw e;
            }
            return answer;
        }
    });
    Exchange exchange = createExchange(out, entityManager);
    exchange.getIn().setBody(out);
    return exchange;
}
Also used : Exchange(org.apache.camel.Exchange) EntityManager(javax.persistence.EntityManager) JpaHelper.getTargetEntityManager(org.apache.camel.component.jpa.JpaHelper.getTargetEntityManager) Query(javax.persistence.Query) PersistenceException(javax.persistence.PersistenceException) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List)

Example 70 with List

use of java.util.List 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)

Aggregations

List (java.util.List)19204 ArrayList (java.util.ArrayList)12470 Test (org.junit.Test)4025 HashMap (java.util.HashMap)3622 Map (java.util.Map)3242 IOException (java.io.IOException)1670 Iterator (java.util.Iterator)1563 LinkedList (java.util.LinkedList)1336 HashSet (java.util.HashSet)1189 Set (java.util.Set)1151 File (java.io.File)921 ImmutableList (com.google.common.collect.ImmutableList)826 Collectors (java.util.stream.Collectors)784 LinkedHashMap (java.util.LinkedHashMap)540 Test (org.testng.annotations.Test)527 Session (org.hibernate.Session)521 Collection (java.util.Collection)496 Collections (java.util.Collections)474 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)471 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)453