use of java.util.List 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());
}
use of java.util.List in project camel by apache.
the class KafkaProducerFullTest method producedStringMessageIsReceivedByKafka.
@Test
public void producedStringMessageIsReceivedByKafka() throws InterruptedException, IOException {
int messageInTopic = 10;
int messageInOtherTopic = 5;
CountDownLatch messagesLatch = new CountDownLatch(messageInTopic + messageInOtherTopic);
sendMessagesInRoute(messageInTopic, stringsTemplate, "IT test message", KafkaConstants.PARTITION_KEY, "1");
sendMessagesInRoute(messageInOtherTopic, stringsTemplate, "IT test message in other topic", KafkaConstants.PARTITION_KEY, "1", KafkaConstants.TOPIC, TOPIC_STRINGS_IN_HEADER);
createKafkaMessageConsumer(stringsConsumerConn, TOPIC_STRINGS, TOPIC_STRINGS_IN_HEADER, messagesLatch);
boolean allMessagesReceived = messagesLatch.await(200, TimeUnit.MILLISECONDS);
assertTrue("Not all messages were published to the kafka topics. Not received: " + messagesLatch.getCount(), allMessagesReceived);
List<Exchange> exchangeList = mockEndpoint.getExchanges();
assertEquals("Fifteen Exchanges are expected", exchangeList.size(), 15);
for (Exchange exchange : exchangeList) {
@SuppressWarnings("unchecked") List<RecordMetadata> recordMetaData1 = (List<RecordMetadata>) (exchange.getIn().getHeader(KafkaConstants.KAFKA_RECORDMETA));
assertEquals("One RecordMetadata is expected.", recordMetaData1.size(), 1);
assertTrue("Offset is positive", recordMetaData1.get(0).offset() >= 0);
assertTrue("Topic Name start with 'test'", recordMetaData1.get(0).topic().startsWith("test"));
}
}
use of java.util.List in project camel by apache.
the class KafkaProducerFullTest method producedString2MessageIsReceivedByKafka.
@Test
public void producedString2MessageIsReceivedByKafka() throws InterruptedException, IOException {
int messageInTopic = 10;
int messageInOtherTopic = 5;
CountDownLatch messagesLatch = new CountDownLatch(messageInTopic + messageInOtherTopic);
sendMessagesInRoute(messageInTopic, stringsTemplate2, "IT test message", (String[]) null);
sendMessagesInRoute(messageInOtherTopic, stringsTemplate2, "IT test message in other topic", KafkaConstants.PARTITION_KEY, "1", KafkaConstants.TOPIC, TOPIC_STRINGS_IN_HEADER);
createKafkaMessageConsumer(stringsConsumerConn, TOPIC_STRINGS, TOPIC_STRINGS_IN_HEADER, messagesLatch);
boolean allMessagesReceived = messagesLatch.await(200, TimeUnit.MILLISECONDS);
assertTrue("Not all messages were published to the kafka topics. Not received: " + messagesLatch.getCount(), allMessagesReceived);
List<Exchange> exchangeList = mockEndpoint.getExchanges();
assertEquals("Fifteen Exchanges are expected", exchangeList.size(), 15);
for (Exchange exchange : exchangeList) {
@SuppressWarnings("unchecked") List<RecordMetadata> recordMetaData1 = (List<RecordMetadata>) (exchange.getIn().getHeader(KafkaConstants.KAFKA_RECORDMETA));
assertEquals("One RecordMetadata is expected.", recordMetaData1.size(), 1);
assertTrue("Offset is positive", recordMetaData1.get(0).offset() >= 0);
assertTrue("Topic Name start with 'test'", recordMetaData1.get(0).topic().startsWith("test"));
}
}
use of java.util.List in project camel by apache.
the class KubernetesPodsConsumerTest method createAndDeletePod.
@Test
public void createAndDeletePod() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
mockResultEndpoint.expectedMessageCount(3);
mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "MODIFIED", "MODIFIED");
Exchange ex = template.request("direct:createPod", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
PodSpec podSpec = new PodSpec();
podSpec.setHostname("localhost");
Container cont = new Container();
cont.setImage("docker.io/jboss/wildfly:latest");
cont.setName("pippo");
List<ContainerPort> containerPort = new ArrayList<ContainerPort>();
ContainerPort port = new ContainerPort();
port.setHostIP("0.0.0.0");
port.setHostPort(8080);
port.setContainerPort(8080);
containerPort.add(port);
cont.setPorts(containerPort);
List<Container> list = new ArrayList<Container>();
list.add(cont);
podSpec.setContainers(list);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_SPEC, podSpec);
}
});
ex = template.request("direct:deletePod", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "test");
}
});
boolean podDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(podDeleted);
Thread.sleep(3000);
mockResultEndpoint.assertIsSatisfied();
}
use of java.util.List in project camel by apache.
the class KubernetesServicesConsumerTest method createAndDeleteService.
@Test
public void createAndDeleteService() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
mockResultEndpoint.expectedMessageCount(2);
mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED");
Exchange ex = template.request("direct:createService", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, labels);
ServiceSpec serviceSpec = new ServiceSpec();
List<ServicePort> lsp = new ArrayList<ServicePort>();
ServicePort sp = new ServicePort();
sp.setPort(8080);
sp.setTargetPort(new IntOrString(8080));
sp.setProtocol("TCP");
lsp.add(sp);
serviceSpec.setPorts(lsp);
Map<String, String> selectorMap = new HashMap<String, String>();
selectorMap.put("containter", "test");
serviceSpec.setSelector(selectorMap);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_SPEC, serviceSpec);
}
});
Service serv = ex.getOut().getBody(Service.class);
assertEquals(serv.getMetadata().getName(), "test");
ex = template.request("direct:deleteService", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
}
});
boolean servDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(servDeleted);
Thread.sleep(3000);
mockResultEndpoint.assertIsSatisfied();
}
Aggregations