camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] git commit: CAMEL-7386: camel-openshift component.
Date Wed, 23 Apr 2014 13:11:58 GMT
CAMEL-7386: camel-openshift component.


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

Branch: refs/heads/master
Commit: 7920a773b0047770a4f6d51d5f36d0c1b9dd6b14
Parents: ecdd470
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Apr 23 15:11:53 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Apr 23 15:11:53 2014 +0200

----------------------------------------------------------------------
 .../component/openshift/OpenShiftConsumer.java  | 10 +---
 .../component/openshift/OpenShiftEndpoint.java  | 14 ++---
 .../component/openshift/OpenShiftPollMode.java  | 22 -------
 .../component/openshift/OpenShiftProducer.java  | 18 +++---
 .../OpenShiftConsumerOnChangeTest.java          |  2 +-
 ...penShiftConsumerOnChangeWithInitialTest.java | 58 -------------------
 .../OpenShiftListApplicationsModeJsonTest.java  | 60 ++++++++++++++++++++
 7 files changed, 80 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConsumer.java
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConsumer.java
index 0af8ba1..4e8920b 100644
--- a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConsumer.java
+++ b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConsumer.java
@@ -55,11 +55,7 @@ public class OpenShiftConsumer extends ScheduledPollConsumer {
             return 0;
         }
 
-        if (getEndpoint().getPollMode().equals(OpenShiftPollMode.all.name())) {
-            return doPollAll(domain);
-        } else {
-            return doPollOnChange(domain);
-        }
+        return doPollOnChange(domain);
     }
 
     protected int doPollAll(IDomain domain) {
@@ -119,9 +115,9 @@ public class OpenShiftConsumer extends ScheduledPollConsumer {
             }
         }
 
-        // only emit if needed
+        // only start emitting events after first init poll
         int processed = 0;
-        if (!initialPoll || initialPoll && getEndpoint().getPollMode().equals(OpenShiftPollMode.onChangeWithInitial.name()))
{
+        if (!initialPoll) {
 
             for (ApplicationState add : added.keySet()) {
                 Exchange exchange = getEndpoint().createExchange(add.getApplication());

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftEndpoint.java
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftEndpoint.java
index 2fe6aef..df17818 100644
--- a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftEndpoint.java
+++ b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftEndpoint.java
@@ -46,7 +46,7 @@ public class OpenShiftEndpoint extends ScheduledPollEndpoint {
     @UriParam
     private String application;
     @UriParam
-    private String pollMode = OpenShiftPollMode.all.name();
+    private String mode;
 
     public OpenShiftEndpoint(String endpointUri, Component component) {
         super(endpointUri, component);
@@ -143,15 +143,11 @@ public class OpenShiftEndpoint extends ScheduledPollEndpoint {
         this.application = application;
     }
 
-    public String getPollMode() {
-        return pollMode;
+    public String getMode() {
+        return mode;
     }
 
-    public void setPollMode(String pollMode) {
-        this.pollMode = pollMode;
-    }
-
-    public void setPollMode(OpenShiftPollMode pollMode) {
-        this.pollMode = pollMode.name();
+    public void setMode(String mode) {
+        this.mode = mode;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftPollMode.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftPollMode.java
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftPollMode.java
deleted file mode 100644
index 64f534a..0000000
--- a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftPollMode.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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.openshift;
-
-public enum OpenShiftPollMode {
-
-    all, onChange, onChangeWithInitial
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
index 47714e8..f4ddd68 100644
--- a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
+++ b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
@@ -55,9 +55,6 @@ public class OpenShiftProducer extends DefaultProducer {
         OpenShiftOperation operation = exchange.getIn().getHeader(OpenShiftConstants.OPERATION,
getEndpoint().getOperation(), OpenShiftOperation.class);
 
         switch (operation) {
-        case list:
-            doList(exchange, domain);
-            break;
         case start:
             doStart(exchange, domain);
             break;
@@ -70,18 +67,21 @@ public class OpenShiftProducer extends DefaultProducer {
         case state:
             doState(exchange, domain);
             break;
+        case list:
         default:
             // and do list by default
-            doList(exchange, domain);
+            if (getEndpoint().getMode().equals("json")) {
+                doListJson(exchange, domain);
+            } else {
+                doListPojo(exchange, domain);
+            }
             break;
         }
     }
 
-    protected void doList(Exchange exchange, IDomain domain) {
+    protected void doListJson(Exchange exchange, IDomain domain) {
         StringBuilder sb = new StringBuilder("{\n  \"applications\": [");
 
-        // TODO: option to output as pojo or json
-
         boolean first = true;
         for (IApplication application : domain.getApplications()) {
             if (!first) {
@@ -153,6 +153,10 @@ public class OpenShiftProducer extends DefaultProducer {
         exchange.getIn().setBody(sb.toString());
     }
 
+    protected void doListPojo(Exchange exchange, IDomain domain) {
+        exchange.getIn().setBody(domain.getApplications());
+    }
+
     protected void doStart(Exchange exchange, IDomain domain) throws CamelExchangeException
{
         String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(),
String.class);
         if (name == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeTest.java
index 4b7199c..6f4b213 100644
--- a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeTest.java
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeTest.java
@@ -49,7 +49,7 @@ public class OpenShiftConsumerOnChangeTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                fromF("openshift:myApp?username=%s&password=%s&delay=5s&pollMode=onChange",
username, password)
+                fromF("openshift:myApp?username=%s&password=%s&delay=5s", username,
password)
                     .log("Event ${header.CamelOpenShiftEventType} for app ${body.name}")
                     .to("mock:result");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeWithInitialTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeWithInitialTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeWithInitialTest.java
deleted file mode 100644
index 7502ab9..0000000
--- a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftConsumerOnChangeWithInitialTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.openshift;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class OpenShiftConsumerOnChangeWithInitialTest extends CamelTestSupport {
-
-    private String username;
-    private String password;
-
-    @Override
-    public void setUp() throws Exception {
-        // INSERT credentials here
-        username = null;
-        password = null;
-        super.setUp();
-    }
-
-    @Test
-    public void testConsumer() throws Exception {
-        if (username == null) {
-            return;
-        }
-
-        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                fromF("openshift:myApp?username=%s&password=%s&delay=5s&pollMode=onChangeWithInitial",
username, password)
-                    .log("Event ${header.CamelOpenShiftEventType} for app ${body.name}")
-                    .to("mock:result");
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/7920a773/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftListApplicationsModeJsonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftListApplicationsModeJsonTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftListApplicationsModeJsonTest.java
new file mode 100644
index 0000000..8c020dd
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftListApplicationsModeJsonTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.openshift;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class OpenShiftListApplicationsModeJsonTest extends CamelTestSupport {
+
+    private String username;
+    private String password;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        super.setUp();
+    }
+
+    @Test
+    public void testListApplications() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .toF("openshift:myApp?operation=list&mode=json&username=%s&password=%s",
username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message