CAMEL-8910 Camel-JClouds: Add new operations to JClouds Compute Service Producer, add suspendNode test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85798aac Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85798aac Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85798aac Branch: refs/heads/master Commit: 85798aac50e6d9255022306b42ce23347dccfbcc Parents: 1f0fe61 Author: Andrea Cosentino <anco...@gmail.com> Authored: Sun Jun 28 15:20:06 2015 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Sun Jun 28 15:20:06 2015 +0200 ---------------------------------------------------------------------- .../jclouds/JcloudsSpringComputeTest.java | 57 +++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/85798aac/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsSpringComputeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsSpringComputeTest.java b/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsSpringComputeTest.java index 18fa1cc..7baef0a 100644 --- a/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsSpringComputeTest.java +++ b/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsSpringComputeTest.java @@ -192,7 +192,44 @@ public class JcloudsSpringComputeTest extends CamelSpringTestSupport { } } } - } + } + + @Test + public void testCreateAndSuspendNode() throws InterruptedException { + result.expectedMessageCount(1); + template.sendBodyAndHeaders("direct:start", null, createHeaders("1", "default")); + result.assertIsSatisfied(); + + List<Exchange> exchanges = result.getExchanges(); + if (exchanges != null && !exchanges.isEmpty()) { + for (Exchange exchange : exchanges) { + Set<?> nodeMetadatas = exchange.getIn().getBody(Set.class); + assertEquals("There should be one node running", 1, nodeMetadatas.size()); + + for (Object obj : nodeMetadatas) { + NodeMetadata nodeMetadata = (NodeMetadata) obj; + template.sendBodyAndHeaders("direct:start", null, suspendHeaders(nodeMetadata.getId(), null)); + } + } + } + + resultlist.expectedMessageCount(1); + template.sendBodyAndHeaders("direct:nodelist",null, listNodeHeaders("1", "default", "SUSPENDED")); + resultlist.assertIsSatisfied(); + + List<Exchange> exchangesNodeList = resultlist.getExchanges(); + if (exchangesNodeList != null && !exchangesNodeList.isEmpty()) { + for (Exchange exchange : exchangesNodeList) { + Set<?> nodeMetadatas = exchange.getIn().getBody(Set.class); + assertEquals("There should be one node suspended", 1, nodeMetadatas.size()); + + for (Object obj : nodeMetadatas) { + NodeMetadata nodeMetadata = (NodeMetadata) obj; + assertEquals(nodeMetadata.getId(), "1"); + } + } + } + } @SuppressWarnings("unchecked") @@ -286,4 +323,22 @@ public class JcloudsSpringComputeTest extends CamelSpringTestSupport { } return rebootHeaders; } + + /** + * Returns a {@Map} with the suspend headers. + * + * @param nodeId The id of the node to suspend. + * @param group The group of the node to suspend. + */ + protected Map<String, Object> suspendHeaders(String nodeId, String group) { + Map<String, Object> rebootHeaders = new HashMap<String, Object>(); + rebootHeaders.put(JcloudsConstants.OPERATION, JcloudsConstants.SUSPEND_NODE); + if (nodeId != null) { + rebootHeaders.put(JcloudsConstants.NODE_ID, nodeId); + } + if (group != null) { + rebootHeaders.put(JcloudsConstants.GROUP, group); + } + return rebootHeaders; + } }