camel-commits mailing list archives

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


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

Branch: refs/heads/master
Commit: 994d628cc9deb81c6a8c3693204ff16091198d5d
Parents: 1b95ec6
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Mon May 29 16:08:40 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue May 30 11:01:11 2017 +0200

----------------------------------------------------------------------
 .../DeprecatedKubernetesNodesProducerTest.java  |  2 +
 .../producer/KubernetesNodesProducerTest.java   | 40 ++++++++++++--------
 2 files changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/994d628c/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesNodesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesNodesProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesNodesProducerTest.java
index a8f57c4..fc07218 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesNodesProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/deprecated/DeprecatedKubernetesNodesProducerTest.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.KubernetesNodesProducerTest;
+import org.junit.Ignore;
 
+@Ignore
 @Deprecated
 public class DeprecatedKubernetesNodesProducerTest extends KubernetesNodesProducerTest {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/994d628c/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
index 426e724..5f591f5 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
@@ -21,38 +21,50 @@ import java.util.List;
 import java.util.Map;
 
 import io.fabric8.kubernetes.api.model.Node;
+import io.fabric8.kubernetes.api.model.NodeListBuilder;
+import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
+
 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 KubernetesNodesProducerTest extends KubernetesTestSupport {
 
+    @Rule
+    public KubernetesServer server = new KubernetesServer();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("kubernetesClient", server.getClient());
+        return registry;
+    }
+    
     @Test
     public void listTest() throws Exception {
-        if (ObjectHelper.isEmpty(authToken)) {
-            return;
-        }
+        server.expect().withPath("/api/v1/nodes").andReturn(200, new NodeListBuilder().addNewItem().and().build()).once();
         List<Node> result = template.requestBody("direct:list", "",
                 List.class);
 
-        assertTrue(result.size() == 1);
+        assertEquals(1, result.size());
     }
 
     @Test
     public void listByLabelsTest() throws Exception {
-        if (ObjectHelper.isEmpty(authToken)) {
-            return;
-        }
+        server.expect().withPath("/api/v1/nodes?labelSelector=" + toUrlEncoded("key1=value1,key2=value2"))
+        .andReturn(200, new NodeListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build()).once();
         Exchange 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("kubernetes.io/hostname", "172.28.128.4");
+                labels.put("key1", "value1");
+                labels.put("key2", "value2");
                 exchange.getIn()
                         .setHeader(
                                 KubernetesConstants.KUBERNETES_NODES_LABELS,
@@ -62,9 +74,7 @@ public class KubernetesNodesProducerTest extends KubernetesTestSupport {
 
         List<Node> result = ex.getOut().getBody(List.class);
         
-        Node node = result.get(0);
-        
-        assertTrue(node.getStatus().getCapacity().get("pods").getAmount().equals("110"));
+        assertEquals(3, result.size());
     }
 
     @Override
@@ -73,11 +83,9 @@ public class KubernetesNodesProducerTest extends KubernetesTestSupport
{
             @Override
             public void configure() throws Exception {
                 from("direct:list")
-                        .toF("kubernetes-nodes://%s?oauthToken=%s&operation=listNodes",
-                                host, authToken);
+                        .toF("kubernetes-nodes:///?kubernetesClient=#kubernetesClient&operation=listNodes");
                 from("direct:listByLabels")
-                        .toF("kubernetes-nodes://%s?oauthToken=%s&operation=listNodesByLabels",
-                                host, authToken);
+                        .toF("kubernetes-nodes:///?kubernetesClient=#kubernetesClient&operation=listNodesByLabels");
             }
         };
     }


Mime
View raw message