camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [3/7] camel git commit: CAMEL-9085 Create a Camel-Kubernetes/Openshift v3 Component
Date Sun, 18 Oct 2015 08:18:55 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
new file mode 100644
index 0000000..eab26d0
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kubernetes.producer;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.EditablePodTemplateSpec;
+import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
+import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.ReplicationControllerSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesReplicationControllersProducerTest extends
+        KubernetesTestSupport {
+
+    @Test
+    public void listTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        List<ReplicationController> result = template.requestBody(
+                "direct:list", "", List.class);
+
+        boolean fabric8Exists = false;
+
+        Iterator<ReplicationController> it = result.iterator();
+        while (it.hasNext()) {
+            ReplicationController rc = (ReplicationController) it.next();
+            if ("fabric8".equalsIgnoreCase(rc.getMetadata().getName())) {
+                fabric8Exists = true;
+            }
+        }
+
+        assertTrue(fabric8Exists);
+    }
+
+    @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_REPLICATION_CONTROLLERS_LABELS,
+                                labels);
+            }
+        });
+
+        List<ReplicationController> result = ex.getOut().getBody(List.class);
+
+        boolean rcExists = false;
+        Iterator<ReplicationController> it = result.iterator();
+        while (it.hasNext()) {
+            ReplicationController rc = (ReplicationController) it.next();
+            if ("elasticsearch".equalsIgnoreCase(rc.getMetadata().getName())) {
+                rcExists = true;
+            }
+        }
+
+        assertFalse(rcExists);
+    }
+
+    @Test
+    public void getReplicationControllerTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:getReplicationController",
+                new Processor() {
+
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setHeader(
+                                KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                                "default");
+                        exchange.getIn()
+                                .setHeader(
+                                        KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+                                        "elasticsearch");
+                    }
+                });
+
+        ReplicationController result = ex.getOut().getBody(
+                ReplicationController.class);
+
+        assertNull(result);
+    }
+
+    @Test
+    public void createAndDeleteService() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:createReplicationController",
+                new Processor() {
+
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setHeader(
+                                KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                                "default");
+                        exchange.getIn()
+                                .setHeader(
+                                        KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+                                        "test");
+                        Map<String, String> labels = new HashMap<String, String>();
+                        labels.put("this", "rocks");
+                        exchange.getIn()
+                                .setHeader(
+                                        KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS,
+                                        labels);
+                        ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
+                        rcSpec.setReplicas(2);
+                        PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
+                        EditablePodTemplateSpec t = builder.withNewMetadata()
+                                .withName("nginx-template")
+                                .addToLabels("server", "nginx").endMetadata()
+                                .withNewSpec().addNewContainer()
+                                .withName("wildfly").withImage("jboss/wildfly")
+                                .addNewPort().withContainerPort(80).endPort()
+                                .endContainer().endSpec().build();
+                        rcSpec.setTemplate(t);
+                        Map<String, String> selectorMap = new HashMap<String, String>();
+                        selectorMap.put("server", "nginx");
+                        rcSpec.setSelector(selectorMap);
+                        exchange.getIn()
+                                .setHeader(
+                                        KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC,
+                                        rcSpec);
+                    }
+                });
+
+        ReplicationController rc = ex.getOut().getBody(
+                ReplicationController.class);
+
+        assertEquals(rc.getMetadata().getName(), "test");
+
+        ex = template.request("direct:deleteReplicationController",
+                new Processor() {
+
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setHeader(
+                                KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                                "default");
+                        exchange.getIn()
+                                .setHeader(
+                                        KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+                                        "test");
+                    }
+                });
+
+        boolean rcDeleted = ex.getOut().getBody(Boolean.class);
+
+        assertTrue(rcDeleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:list")
+                        .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllers",
+                                host, authToken);
+                from("direct:listByLabels")
+                        .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllersByLabels",
+                                host, authToken);
+                from("direct:getReplicationController")
+                        .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=getReplicationController",
+                                host, authToken);
+                from("direct:createReplicationController")
+                        .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=createReplicationController",
+                                host, authToken);
+                from("direct:deleteReplicationController")
+                        .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=deleteReplicationController",
+                                host, authToken);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
new file mode 100644
index 0000000..b0fc639
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kubernetes.producer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.ResourceQuota;
+import io.fabric8.kubernetes.api.model.ResourceQuotaSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesResourcesQuotaProducerTest extends KubernetesTestSupport {
+
+    @Test
+    public void listTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        List<ResourceQuota> result = template.requestBody("direct:list", "",
+                List.class);
+
+        assertTrue(result.size() == 0);
+    }
+
+    @Test
+    public void createAndDeleteResourceQuota() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:create", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+                        "test");
+                Map<String, String> labels = new HashMap<String, String>();
+                labels.put("this", "rocks");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS,
+                        labels);
+                ResourceQuotaSpec rsSpec = new ResourceQuotaSpec();
+                Map<String, Quantity> mp = new HashMap<String, Quantity>();
+                mp.put("pods", new Quantity("100"));
+                rsSpec.setHard(mp);
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC,
+                        rsSpec);
+            }
+        });
+
+        ResourceQuota rs = ex.getOut().getBody(ResourceQuota.class);
+
+        assertEquals(rs.getMetadata().getName(), "test");
+        
+        ex = template.request("direct:get", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+                        "test");
+            }
+        });
+        
+        ResourceQuota rsGet = ex.getOut().getBody(ResourceQuota.class);
+        
+        assertEquals(rsGet.getMetadata().getName(), "test");
+        assertEquals(rsGet.getSpec().getHard().get("pods"), new Quantity("100"));
+
+        ex = template.request("direct:delete", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+                        "test");
+            }
+        });
+
+        boolean rqDeleted = ex.getOut().getBody(Boolean.class);
+
+        assertTrue(rqDeleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:list")
+                        .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=listResourcesQuota",
+                                host, authToken);
+                from("direct:listByLabels")
+                        .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=listResourcesQuotaByLabels",
+                                host, authToken);
+                from("direct:get")
+                        .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=getResourceQuota",
+                                host, authToken);
+                from("direct:create")
+                        .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=createResourceQuota",
+                                host, authToken);
+                from("direct:delete")
+                        .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=deleteResourceQuota",
+                                host, authToken);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
new file mode 100644
index 0000000..9e3ff96
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
@@ -0,0 +1,170 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kubernetes.producer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.ning.http.util.Base64;
+
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.Secret;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesSecretsProducerTest extends KubernetesTestSupport {
+
+    @Test
+    public void listTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        List<Secret> result = template.requestBody("direct:list", "",
+                List.class);
+
+        assertTrue(result.size() != 0);
+    }
+
+    @Test
+    public void listByLabelsTest() throws Exception {
+        if (authToken == null) {
+            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_SECRETS_LABELS, labels);
+            }
+        });
+
+        List<Secret> result = ex.getOut().getBody(List.class);
+    }
+
+    @Test
+    public void getSecretTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:get", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SECRET_NAME,
+                        "builder-token-191oc");
+            }
+        });
+
+        Secret result = ex.getOut().getBody(Secret.class);
+    }
+
+    @Test
+    public void createAndDeleteSecret() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:create", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+                Map<String, String> labels = new HashMap<String, String>();
+                labels.put("this", "rocks");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SECRETS_LABELS, labels);
+                Secret s = new Secret();
+                s.setKind("Secret");
+                Map<String, String> mp = new HashMap<String, String>();
+                mp.put("username", Base64.encode("pippo".getBytes()));
+                mp.put("password", Base64.encode("password".getBytes()));
+                s.setData(mp);
+
+                ObjectMeta meta = new ObjectMeta();
+                meta.setName("test");
+                s.setMetadata(meta);
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SECRET, s);
+            }
+        });
+
+        Secret sec = ex.getOut().getBody(Secret.class);
+
+        assertEquals(sec.getMetadata().getName(), "test");
+
+        ex = template.request("direct:delete", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+            }
+        });
+
+        boolean secDeleted = ex.getOut().getBody(Boolean.class);
+
+        assertTrue(secDeleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:list")
+                        .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecrets",
+                                host, authToken);
+                from("direct:listByLabels")
+                        .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecretsByLabels",
+                                host, authToken);
+                from("direct:get")
+                        .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=getSecret",
+                                host, authToken);
+                from("direct:create")
+                        .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=createSecret",
+                                host, authToken);
+                from("direct:delete")
+                        .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=deleteSecret",
+                                host, authToken);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
new file mode 100644
index 0000000..6def15d
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
@@ -0,0 +1,161 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kubernetes.producer;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.ning.http.util.Base64;
+
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.ServiceAccount;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesServiceAccountsProducerTest extends KubernetesTestSupport {
+
+    @Test
+    public void listTest() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        List<ServiceAccount> result = template.requestBody("direct:list", "",
+                List.class);
+
+        boolean fabric8Exists = false;
+
+        Iterator<ServiceAccount> it = result.iterator();
+        while (it.hasNext()) {
+            ServiceAccount service = (ServiceAccount) it.next();
+            if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
+                fabric8Exists = true;
+            }
+        }
+
+        assertTrue(fabric8Exists);
+    }
+
+    @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);
+    }
+
+    @Test
+    public void createAndDeleteServiceAccount() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+        Exchange ex = template.request("direct:create", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
+                Map<String, String> labels = new HashMap<String, String>();
+                labels.put("this", "rocks");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, labels);
+                ServiceAccount s = new ServiceAccount();
+                s.setKind("ServiceAccount");
+                Map<String, String> mp = new HashMap<String, String>();
+                mp.put("username", Base64.encode("pippo".getBytes()));
+                mp.put("password", Base64.encode("password".getBytes()));
+
+                ObjectMeta meta = new ObjectMeta();
+                meta.setName("test");
+                s.setMetadata(meta);
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, s);
+            }
+        });
+
+        ServiceAccount sec = ex.getOut().getBody(ServiceAccount.class);
+
+        assertEquals(sec.getMetadata().getName(), "test");
+
+        ex = template.request("direct:delete", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+                        "default");
+                exchange.getIn().setHeader(
+                        KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
+            }
+        });
+
+        boolean secDeleted = ex.getOut().getBody(Boolean.class);
+
+        assertTrue(secDeleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:list")
+                        .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=listServiceAccounts",
+                                host, authToken);
+                from("direct:listByLabels")
+                        .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=listServiceAccountsByLabels",
+                                host, authToken);
+                from("direct:getServices")
+                        .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=getServiceAccount",
+                                host, authToken);
+                from("direct:create")
+                        .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=createServiceAccount",
+                                host, authToken);
+                from("direct:delete")
+                        .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=deleteServiceAccount",
+                                host, authToken);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
new file mode 100644
index 0000000..375ab91
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
@@ -0,0 +1,198 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kubernetes.producer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.IntOrString;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServicePort;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesServicesProducerTest extends KubernetesTestSupport {
+
+    @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 = (Service) it.next();
+            if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
+                fabric8Exists = true;
+            }
+        }
+
+        assertTrue(fabric8Exists);
+    }
+
+    @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 = (Service) it.next();
+            if ("elasticsearch".equalsIgnoreCase(service.getMetadata()
+                    .getName())) {
+                serviceExists = true;
+            }
+        }
+
+        assertFalse(serviceExists);
+    }
+
+    @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);
+    }
+
+    @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);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:list")
+                        .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServices",
+                                host, authToken);
+                from("direct:listByLabels")
+                        .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServicesByLabels",
+                                host, authToken);
+                from("direct:getServices")
+                        .toF("kubernetes://%s?oauthToken=%s&category=services&operation=getService",
+                                host, authToken);
+                from("direct:createService")
+                        .toF("kubernetes://%s?oauthToken=%s&category=services&operation=createService",
+                                host, authToken);
+                from("direct:deleteService")
+                        .toF("kubernetes://%s?oauthToken=%s&category=services&operation=deleteService",
+                                host, authToken);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/resources/log4j.properties b/components/camel-kubernetes/src/test/resources/log4j.properties
new file mode 100644
index 0000000..255fe5c
--- /dev/null
+++ b/components/camel-kubernetes/src/test/resources/log4j.properties
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, file
+
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-kubernetes-test.log
+log4j.appender.file.append=true
+


Mime
View raw message