Search in sources :

Example 1 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class KratiProducerTest method testPutAndGetPreserveHeaders.

@Test
public void testPutAndGetPreserveHeaders() throws Exception {
    template.sendBodyAndHeader("direct:put", new ValueObject("TEST1"), KratiConstants.KEY, new KeyObject("1"));
    template.sendBodyAndHeader("direct:put", new ValueObject("TEST2"), KratiConstants.KEY, new KeyObject("2"));
    template.sendBodyAndHeader("direct:put", new ValueObject("TEST3"), KratiConstants.KEY, new KeyObject("3"));
    Exchange out = template.send("direct:get", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("foo", 123);
            exchange.getIn().setHeader(KratiConstants.KEY, new KeyObject("3"));
        }
    });
    assertNotNull(out);
    assertEquals(123, out.getOut().getHeader("foo"));
    assertEquals(new ValueObject("TEST3"), out.getOut().getBody());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Test(org.junit.Test)

Example 2 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class KubernetesServiceAccountsProducerTest method listByLabelsTest.

@Test
public void listByLabelsTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:listByLabels", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("component", "elasticsearch");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, labels);
        }
    });
    List<ServiceAccount> result = ex.getOut().getBody(List.class);
    assertTrue(result.size() == 0);
}
Also used : Exchange(org.apache.camel.Exchange) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class KubernetesServicesProducerTest method getServiceTest.

@Test
public void getServiceTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:getServices", 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, "elasticsearch");
        }
    });
    Service result = ex.getOut().getBody(Service.class);
    assertNull(result);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Example 4 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class KubernetesServicesProducerTest method createAndDeleteService.

@Test
public void createAndDeleteService() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    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);
}
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)

Example 5 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class KubernetesServicesProducerTest method listByLabelsTest.

@Test
public void listByLabelsTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:listByLabels", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("component", "elasticsearch");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, labels);
        }
    });
    List<Service> result = ex.getOut().getBody(List.class);
    boolean serviceExists = false;
    Iterator<Service> it = result.iterator();
    while (it.hasNext()) {
        Service service = it.next();
        if ("elasticsearch".equalsIgnoreCase(service.getMetadata().getName())) {
            serviceExists = true;
        }
    }
    assertFalse(serviceExists);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78