Search in sources :

Example 1 with Result

use of io.fabric8.insight.metrics.model.Result 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 2 with Result

use of io.fabric8.insight.metrics.model.Result 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 3 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesServicesProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<Service> result = template.requestBody("direct:list", "", List.class);
    boolean fabric8Exists = false;
    Iterator<Service> it = result.iterator();
    while (it.hasNext()) {
        Service service = it.next();
        if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
            fabric8Exists = true;
        }
    }
    assertTrue(fabric8Exists);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Example 4 with Result

use of io.fabric8.insight.metrics.model.Result 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)

Example 5 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesNamespacesConsumerTest method createAndDeletePod.

@Test
public void createAndDeletePod() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    mockResultEndpoint.expectedMessageCount(5);
    mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "MODIFIED", "MODIFIED", "MODIFIED", "DELETED");
    Exchange ex = template.request("direct:createNamespace", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
        }
    });
    Namespace ns = ex.getOut().getBody(Namespace.class);
    assertEquals(ns.getMetadata().getName(), "test");
    ex = template.request("direct:listByLabels", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
        }
    });
    List<Namespace> result = ex.getOut().getBody(List.class);
    boolean testExists = false;
    Iterator<Namespace> it = result.iterator();
    while (it.hasNext()) {
        Namespace namespace = it.next();
        if ("test".equalsIgnoreCase(namespace.getMetadata().getName())) {
            testExists = true;
        }
    }
    assertTrue(testExists);
    ex = template.request("direct:deleteNamespace", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
        }
    });
    boolean nsDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(nsDeleted);
    Thread.sleep(3000);
    mockResultEndpoint.assertIsSatisfied();
}
Also used : Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Namespace(io.fabric8.kubernetes.api.model.Namespace) Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10