Rename CDI examples test classes to avoid clashes in IDEs and polish
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5fbf7c5d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5fbf7c5d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5fbf7c5d Branch: refs/heads/master Commit: 5fbf7c5d6e83428cbee7babd227860ce541bb327 Parents: 91d1abe Author: Antonin Stefanutti <anto...@stefanutti.fr> Authored: Tue Feb 23 13:16:38 2016 +0100 Committer: Antonin Stefanutti <anto...@stefanutti.fr> Committed: Tue Feb 23 13:16:38 2016 +0100 ---------------------------------------------------------------------- .../example/cdi/metrics/ApplicationTest.java | 90 ------------------- .../example/cdi/metrics/CdiMetricsTest.java | 94 ++++++++++++++++++++ .../camel/example/cdi/osgi/CdiOsgiIT.java | 6 +- .../example/cdi/properties/ApplicationTest.java | 72 --------------- .../cdi/properties/CdiPropertiesTest.java | 73 +++++++++++++++ .../cdi/rest/servlet/CdiRestServletTest.java | 63 +++++++++++++ .../example/cdi/rest/servlet/RestCdiTest.java | 61 ------------- 7 files changed, 234 insertions(+), 225 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/ApplicationTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/ApplicationTest.java b/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/ApplicationTest.java deleted file mode 100644 index 623c519..0000000 --- a/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/ApplicationTest.java +++ /dev/null @@ -1,90 +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.example.cdi.metrics; - -import javax.inject.Inject; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; -import com.codahale.metrics.annotation.Metric; -import io.astefanutti.metrics.cdi.MetricsExtension; -import org.apache.camel.CamelContext; -import org.apache.camel.cdi.CdiCamelExtension; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -public class ApplicationTest { - - @Inject - private Meter generated; - @Inject - private Meter attempt; - @Inject - private Meter success; - @Inject - private Meter redelivery; - @Inject - private Meter error; - - @Inject - @Metric(name = "success-ratio") - private Gauge<Double> ratio; - - @Inject - private CamelContext context; - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Metrics CDI - .addPackage(MetricsExtension.class.getPackage()) - // Test classes - .addPackage(Application.class.getPackage()) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - public void testContextName() { - assertThat("Context name is incorrect!", context.getName(), is(equalTo("camel-example-metrics-cdi"))); - } - - @Test - public void testMetricsValues() throws Exception { - // Wait a while so that the timer can kick in - Thread.sleep(5000); - - // And stop the Camel context so that inflight exchanges get completed - context.stop(); - - assertThat("Meter counts are not consistent!", attempt.getCount() - redelivery.getCount() - success.getCount() - error.getCount(), is(equalTo(0L))); - - assertThat("Success rate gauge value is incorrect!", ratio.getValue(), is(equalTo(success.getOneMinuteRate() / generated.getOneMinuteRate()))); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/CdiMetricsTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/CdiMetricsTest.java b/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/CdiMetricsTest.java new file mode 100644 index 0000000..ff7665e --- /dev/null +++ b/examples/camel-example-cdi-metrics/src/test/java/org/apache/camel/example/cdi/metrics/CdiMetricsTest.java @@ -0,0 +1,94 @@ +/** + * 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.example.cdi.metrics; + +import javax.inject.Inject; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Meter; +import com.codahale.metrics.annotation.Metric; +import io.astefanutti.metrics.cdi.MetricsExtension; +import org.apache.camel.CamelContext; +import org.apache.camel.cdi.CdiCamelExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(Arquillian.class) +public class CdiMetricsTest { + + @Inject + private Meter generated; + @Inject + private Meter attempt; + @Inject + private Meter success; + @Inject + private Meter redelivery; + @Inject + private Meter error; + + @Inject + @Metric(name = "success-ratio") + private Gauge<Double> ratio; + + @Inject + private CamelContext context; + + @Deployment + public static Archive<?> deployment() { + return ShrinkWrap.create(JavaArchive.class) + // Camel CDI + .addPackage(CdiCamelExtension.class.getPackage()) + // Metrics CDI + .addPackage(MetricsExtension.class.getPackage()) + // Test classes + .addPackage(Application.class.getPackage()) + // Bean archive deployment descriptor + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void testContextName() { + assertThat("Context name is incorrect!", context.getName(), is(equalTo("camel-example-metrics-cdi"))); + } + + @Test + public void testMetricsValues() throws Exception { + // Wait a while so that the timer can kick in + Thread.sleep(5000); + + // And stop the Camel context so that inflight exchanges get completed + context.stop(); + + assertThat("Meter counts are not consistent!", + attempt.getCount() - redelivery.getCount() - success.getCount() - error.getCount(), + is(equalTo(0L))); + + assertThat("Success rate gauge value is incorrect!", + ratio.getValue(), + is(equalTo(success.getOneMinuteRate() / generated.getOneMinuteRate()))); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java index a05b3fd..2d7aaba 100644 --- a/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java +++ b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java @@ -82,13 +82,15 @@ public class CdiOsgiIT { @Test public void testRouteStatus() { - assertThat("Route status is incorrect!", context.getRouteStatus("consumer-route"), equalTo(ServiceStatus.Started)); + assertThat("Route status is incorrect!", + context.getRouteStatus("consumer-route"), equalTo(ServiceStatus.Started)); } @Test public void testExchangesCompleted() throws Exception { ManagedRouteMBean route = context.getManagedRoute(context.getRoute("consumer-route").getId(), ManagedRouteMBean.class); - assertThat("Number of exchanges completed is incorrect!", route.getExchangesCompleted(), equalTo(1L)); + assertThat("Number of exchanges completed is incorrect!", + route.getExchangesCompleted(), equalTo(1L)); } @Test http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/ApplicationTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/ApplicationTest.java b/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/ApplicationTest.java deleted file mode 100644 index c092a43..0000000 --- a/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/ApplicationTest.java +++ /dev/null @@ -1,72 +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.example.cdi.properties; - -import javax.enterprise.event.Observes; - -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.cdi.CdiCamelExtension; -import org.apache.camel.cdi.Uri; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.management.event.CamelContextStartingEvent; -import org.apache.camel.model.ModelCamelContext; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; - -@RunWith(Arquillian.class) -public class ApplicationTest { - - @Deployment - public static Archive deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // DeltaSpike - .addPackages(true, "org.apache.deltaspike.core.impl") - // Test classes - .addPackage(Application.class.getPackage()) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - static void advice(@Observes CamelContextStartingEvent event, ModelCamelContext context) throws Exception { - // Add a mock endpoint to the end of the route - context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { - @Override - public void configure() { - weaveAddLast().to("mock:outbound"); - } - }); - } - - @Test - public void testMessage(@Uri("mock:outbound") MockEndpoint outbound) { - assertThat("Exchange count is incorrect!", outbound.getExchanges(), hasSize(1)); - assertThat("Exchange body is incorrect!", outbound.getExchanges().get(0).getIn().getBody(String.class), is(equalTo("Hello"))); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/CdiPropertiesTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/CdiPropertiesTest.java b/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/CdiPropertiesTest.java new file mode 100644 index 0000000..b7ef16e --- /dev/null +++ b/examples/camel-example-cdi-properties/src/test/java/org/apache/camel/example/cdi/properties/CdiPropertiesTest.java @@ -0,0 +1,73 @@ +/** + * 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.example.cdi.properties; + +import javax.enterprise.event.Observes; + +import org.apache.camel.builder.AdviceWithRouteBuilder; +import org.apache.camel.cdi.CdiCamelExtension; +import org.apache.camel.cdi.Uri; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.management.event.CamelContextStartingEvent; +import org.apache.camel.model.ModelCamelContext; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; + +@RunWith(Arquillian.class) +public class CdiPropertiesTest { + + @Deployment + public static Archive deployment() { + return ShrinkWrap.create(JavaArchive.class) + // Camel CDI + .addPackage(CdiCamelExtension.class.getPackage()) + // DeltaSpike + .addPackages(true, "org.apache.deltaspike.core.impl") + // Test classes + .addPackage(Application.class.getPackage()) + // Bean archive deployment descriptor + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + static void advice(@Observes CamelContextStartingEvent event, ModelCamelContext context) throws Exception { + // Add a mock endpoint to the end of the route + context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { + @Override + public void configure() { + weaveAddLast().to("mock:outbound"); + } + }); + } + + @Test + public void testMessage(@Uri("mock:outbound") MockEndpoint outbound) { + assertThat("Exchange count is incorrect!", outbound.getExchanges(), hasSize(1)); + assertThat("Exchange body is incorrect!", + outbound.getExchanges().get(0).getIn().getBody(String.class), is(equalTo("Hello"))); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/CdiRestServletTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/CdiRestServletTest.java b/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/CdiRestServletTest.java new file mode 100644 index 0000000..e9eb337 --- /dev/null +++ b/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/CdiRestServletTest.java @@ -0,0 +1,63 @@ +/** + * 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.example.cdi.rest.servlet; + +import java.net.URL; +import java.nio.file.Paths; + +import org.apache.camel.util.IOHelper; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +@RunWith(Arquillian.class) +public class CdiRestServletTest { + + @Deployment + public static Archive<?> createTestArchive() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Application.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) + .setWebXML(Paths.get("src/main/webapp/WEB-INF/web.xml").toFile()); + } + + @Test + @RunAsClient + public void testWithPath(@ArquillianResource URL url) throws Exception { + assertThat(IOHelper.loadText(new URL(url, "camel/say/hello").openStream()), + is(equalTo("Hello World!\n"))); + } + + @Test + @RunAsClient + public void testWithUriTemplate(@ArquillianResource URL url) throws Exception { + assertThat(IOHelper.loadText(new URL(url, "camel/say/hello/Antonin").openStream()), + is(equalTo("Hello Antonin, I'm CamelContext(hello)!\n"))); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/5fbf7c5d/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java b/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java deleted file mode 100644 index 3188035..0000000 --- a/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java +++ /dev/null @@ -1,61 +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.example.cdi.rest.servlet; - -import java.net.URL; -import java.nio.file.Paths; - -import org.apache.camel.util.IOHelper; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; - -@RunWith(Arquillian.class) -public class RestCdiTest { - - @Deployment - public static Archive<?> createTestArchive() { - return ShrinkWrap.create(WebArchive.class) - .addClass(Application.class) - .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) - .setWebXML(Paths.get("src/main/webapp/WEB-INF/web.xml").toFile()); - } - - @Test - @RunAsClient - public void testWithPath(@ArquillianResource URL url) throws Exception { - assertThat(IOHelper.loadText(new URL(url, "camel/say/hello").openStream()), is(equalTo("Hello World!\n"))); - } - - @Test - @RunAsClient - public void testWithUriTemplate(@ArquillianResource URL url) throws Exception { - assertThat(IOHelper.loadText(new URL(url, "camel/say/hello/Antonin").openStream()), is(equalTo("Hello Antonin, I'm CamelContext(hello)!\n"))); - } -} \ No newline at end of file