camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [04/12] camel git commit: CAMEL-11356: Camel-Kubernetes: refactoring tests by using Kubernetes-server-mock and Openshift-server-mock - BuildConfigs tests
Date Tue, 30 May 2017 09:04:53 GMT
CAMEL-11356: Camel-Kubernetes: refactoring tests by using Kubernetes-server-mock and Openshift-server-mock
- BuildConfigs tests


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/53e0fd5c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/53e0fd5c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/53e0fd5c

Branch: refs/heads/master
Commit: 53e0fd5ca1636eb1d43244b28df922837dd3feda
Parents: cbbfcf8
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Mon May 29 14:39:08 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue May 30 11:01:10 2017 +0200

----------------------------------------------------------------------
 .../KubernetesBuildConfigsProducer.java         | 10 ++--
 ...catedKubernetesBuildConfigsProducerTest.java |  2 +
 .../KubernetesBuildConfigsProducerTest.java     | 56 +++++++++++---------
 3 files changed, 38 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/53e0fd5c/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/build_configs/KubernetesBuildConfigsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/build_configs/KubernetesBuildConfigsProducer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/build_configs/KubernetesBuildConfigsProducer.java
index 0679224..9fc22a2 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/build_configs/KubernetesBuildConfigsProducer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/build_configs/KubernetesBuildConfigsProducer.java
@@ -18,6 +18,9 @@ package org.apache.camel.component.kubernetes.build_configs;
 
 import java.util.Map;
 
+import io.fabric8.kubernetes.client.Watch;
+import io.fabric8.kubernetes.client.Watcher;
+import io.fabric8.kubernetes.client.dsl.FilterWatchListMultiDeletable;
 import io.fabric8.kubernetes.client.dsl.MixedOperation;
 import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
 import io.fabric8.openshift.api.model.Build;
@@ -81,7 +84,7 @@ public class KubernetesBuildConfigsProducer extends DefaultProducer {
 
     protected void doList(Exchange exchange, String operation) throws Exception {
         BuildConfigList buildConfigsList = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class)
-                .buildConfigs().list();
+                .buildConfigs().inAnyNamespace().list();
         exchange.getOut().setBody(buildConfigsList.getItems());
     }
 
@@ -100,9 +103,8 @@ public class KubernetesBuildConfigsProducer extends DefaultProducer {
             }
             buildConfigsList = buildConfigs.list();
         } else {
-            MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, 
-                BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>>
buildConfigs; 
-            buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
+            FilterWatchListMultiDeletable<BuildConfig, BuildConfigList, Boolean, Watch,
Watcher<BuildConfig>> buildConfigs; 
+            buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inAnyNamespace();
             for (Map.Entry<String, String> entry : labels.entrySet()) {
                 buildConfigs.withLabel(entry.getKey(), entry.getValue());
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/53e0fd5c/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesBuildConfigsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesBuildConfigsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesBuildConfigsProducerTest.java
index 4423c01..699ef73 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesBuildConfigsProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesBuildConfigsProducerTest.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.kubernetes.deprecated;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.kubernetes.producer.KubernetesBuildConfigsProducerTest;
+import org.junit.Ignore;
 
+@Ignore
 @Deprecated
 public class DeprecatedKubernetesBuildConfigsProducerTest extends KubernetesBuildConfigsProducerTest
{
 

http://git-wip-us.apache.org/repos/asf/camel/blob/53e0fd5c/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
index b5567ea..e607a70 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
@@ -21,52 +21,56 @@ import java.util.List;
 import java.util.Map;
 
 import io.fabric8.openshift.api.model.BuildConfig;
+import io.fabric8.openshift.api.model.BuildConfigListBuilder;
+import io.fabric8.openshift.client.server.mock.OpenShiftServer;
 
 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.util.ObjectHelper;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Rule;
 import org.junit.Test;
 
 public class KubernetesBuildConfigsProducerTest extends KubernetesTestSupport {
 
+    @Rule
+    public OpenShiftServer server = new OpenShiftServer();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("client", server.getKubernetesClient());
+        return registry;
+    }
+
     @Test
     public void listTest() throws Exception {
-        if (ObjectHelper.isEmpty(authToken)) {
-            return;
-        }
-        List<BuildConfig> result = template.requestBody("direct:list", "",
-                List.class);
+        server.expect().withPath("/oapi/v1/buildconfigs").andReturn(200, new BuildConfigListBuilder().addNewItem().and().addNewItem().and().build()).once();
+        List<BuildConfig> result = template.requestBody("direct:list", "", List.class);
 
-        assertTrue(result.size() == 0);
+        assertEquals(2, result.size());
     }
 
     @Test
     public void listByLabelsTest() throws Exception {
-        if (ObjectHelper.isEmpty(authToken)) {
-            return;
-        }
+        server.expect().withPath("/oapi/v1/buildconfigs?labelSelector=" + toUrlEncoded("key1=value1,key2=value2"))
+            .andReturn(200, new BuildConfigListBuilder().addNewItem().and().addNewItem().and().build()).once();
         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_BUILD_CONFIGS_LABELS,
-                                labels);
+                labels.put("key1", "value1");
+                labels.put("key2", "value2");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS,
labels);
             }
         });
 
         List<BuildConfig> result = ex.getOut().getBody(List.class);
-        
-        assertTrue(result.size() == 0);
+
+        assertEquals(2, result.size());
     }
 
     @Override
@@ -74,13 +78,13 @@ public class KubernetesBuildConfigsProducerTest extends KubernetesTestSupport
{
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:list")
-                        .toF("kubernetes-build-configs://%s?oauthToken=%s&operation=listBuildConfigs",
-                                host, authToken);
-                from("direct:listByLabels")
-                        .toF("kubernetes-build-configs://%s?oauthToken=%s&operation=listBuildConfigsByLabels",
-                                host, authToken);
+                from("direct:list").to("kubernetes-build-configs:///?operation=listBuildConfigs&kubernetesClient=#client");
+                from("direct:listByLabels").to("kubernetes-build-configs:///?kubernetesClient=#client&operation=listBuildConfigsByLabels");
             }
         };
     }
+
+    private static String toUrlEncoded(String str) {
+        return str.replaceAll("=", "%3D");
+    }
 }


Mime
View raw message