Search in sources :

Example 71 with List

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());
}
Also used : MultiSteps(org.apache.camel.examples.MultiSteps) List(java.util.List) Test(org.junit.Test)

Example 72 with List

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"));
    }
}
Also used : Exchange(org.apache.camel.Exchange) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) ArrayList(java.util.ArrayList) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 73 with List

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"));
    }
}
Also used : Exchange(org.apache.camel.Exchange) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) ArrayList(java.util.ArrayList) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 74 with List

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();
}
Also used : Processor(org.apache.camel.Processor) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Exchange(org.apache.camel.Exchange) Container(io.fabric8.kubernetes.api.model.Container) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 75 with List

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();
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) Processor(org.apache.camel.Processor) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Exchange(org.apache.camel.Exchange) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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