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