You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2018/04/12 20:49:37 UTC
[camel] branch master updated: CAMEL-11905: Added some route level
tests for the camel-ganglia component
This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new deec7bb CAMEL-11905: Added some route level tests for the camel-ganglia component
deec7bb is described below
commit deec7bb4948f14f3b53f678760688813d6839235
Author: aldettinger <al...@gmail.com>
AuthorDate: Thu Apr 12 22:43:43 2018 +0200
CAMEL-11905: Added some route level tests for the camel-ganglia component
---
.../component/ganglia/CamelGangliaTestSupport.java | 34 ++++++++++
.../camel/component/ganglia/GangliaCamelTest.java | 72 ++++++++++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java
new file mode 100644
index 0000000..6cd170e
--- /dev/null
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java
@@ -0,0 +1,34 @@
+/**
+ * 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.ganglia;
+
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.BeforeClass;
+
+public class CamelGangliaTestSupport extends CamelTestSupport {
+ private static int testPort;
+
+ @BeforeClass
+ public static void setup() {
+ testPort = AvailablePortFinder.getNextAvailable();
+ }
+
+ protected int getTestPort() {
+ return testPort;
+ }
+}
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java
new file mode 100644
index 0000000..139ade0
--- /dev/null
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.ganglia;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import info.ganglia.gmetric4j.gmetric.GMetricSlope;
+import info.ganglia.gmetric4j.gmetric.GMetricType;
+
+import org.apache.camel.ResolveEndpointFailedException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * {@code GangliaCamelTest} is not shipped with an embedded gmond agent, as such
+ * datagrams sent by the camel-ganglia component during those tests are simply
+ * dropped at UDP level.
+ */
+public class GangliaCamelTest extends CamelGangliaTestSupport {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private String getTestUri() {
+ return "ganglia:localhost:" + getTestPort() + "?mode=UNICAST&metricName=temperature&type=Double";
+ }
+
+ @Test
+ public void sendShouldNotThrow() {
+ template.sendBody(getTestUri(), 28.0);
+ }
+
+ @Test
+ public void sendUsingWireFormat30xShouldNotThrow() {
+ template.sendBody(getTestUri() + "&wireFormat31x=false", 28.0);
+ }
+
+ @Test
+ public void sendMessageHeadersOverridingEndpointOptionsShouldNotThrow() {
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(GangliaConstants.GROUP_NAME, "sea-mesure");
+ headers.put(GangliaConstants.METRIC_NAME, "depth");
+ headers.put(GangliaConstants.METRIC_TYPE, GMetricType.FLOAT);
+ headers.put(GangliaConstants.METRIC_SLOPE, GMetricSlope.NEGATIVE);
+ headers.put(GangliaConstants.METRIC_UNITS, "cm");
+ headers.put(GangliaConstants.METRIC_TMAX, 100);
+ headers.put(GangliaConstants.METRIC_DMAX, 10);
+ template.sendBodyAndHeaders(getTestUri(), -3.0f, headers);
+ }
+
+ @Test
+ public void sendWithWrongTypeShouldThrow() {
+ thrown.expect(ResolveEndpointFailedException.class);
+ template.sendBody(getTestUri() + "&type=wrong", "");
+ }
+}
--
To stop receiving notification emails like this one, please contact
aldettinger@apache.org.