http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/AbstractMiloServerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/AbstractMiloServerTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/AbstractMiloServerTest.java index a904de4..40115d2 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/AbstractMiloServerTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/AbstractMiloServerTest.java @@ -28,63 +28,62 @@ import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; public abstract class AbstractMiloServerTest extends CamelTestSupport { - public static void testBody(final AssertionClause clause, final Consumer<DataValue> valueConsumer) { - testBody(clause, DataValue.class, valueConsumer); - } + public static void testBody(final AssertionClause clause, final Consumer<DataValue> valueConsumer) { + testBody(clause, DataValue.class, valueConsumer); + } - public static <T> void testBody(final AssertionClause clause, final Class<T> bodyClass, - final Consumer<T> valueConsumer) { - clause.predicate(exchange -> { - final T body = exchange.getIn().getBody(bodyClass); - valueConsumer.accept(body); - return true; - }); - } + public static <T> void testBody(final AssertionClause clause, final Class<T> bodyClass, final Consumer<T> valueConsumer) { + clause.predicate(exchange -> { + final T body = exchange.getIn().getBody(bodyClass); + valueConsumer.accept(body); + return true; + }); + } - public static Consumer<DataValue> assertGoodValue(final Object expectedValue) { - return value -> { - assertNotNull(value); - assertEquals(expectedValue, value.getValue().getValue()); - assertTrue(value.getStatusCode().isGood()); - assertFalse(value.getStatusCode().isBad()); - }; - } + public static Consumer<DataValue> assertGoodValue(final Object expectedValue) { + return value -> { + assertNotNull(value); + assertEquals(expectedValue, value.getValue().getValue()); + assertTrue(value.getStatusCode().isGood()); + assertFalse(value.getStatusCode().isBad()); + }; + } - @Override - protected CamelContext createCamelContext() throws Exception { - final CamelContext context = super.createCamelContext(); - configureContext(context); - return context; - } + @Override + protected CamelContext createCamelContext() throws Exception { + final CamelContext context = super.createCamelContext(); + configureContext(context); + return context; + } - protected void configureContext(final CamelContext context) throws Exception { - final MiloServerComponent server = context.getComponent("milo-server", MiloServerComponent.class); - configureMiloServer(server); - } + protected void configureContext(final CamelContext context) throws Exception { + final MiloServerComponent server = context.getComponent("milo-server", MiloServerComponent.class); + configureMiloServer(server); + } - protected void configureMiloServer(final MiloServerComponent server) throws Exception { - server.setBindAddresses("localhost"); - server.setBindPort(12685); - server.setUserAuthenticationCredentials("foo:bar,foo2:bar2"); - } + protected void configureMiloServer(final MiloServerComponent server) throws Exception { + server.setBindAddresses("localhost"); + server.setBindPort(12685); + server.setUserAuthenticationCredentials("foo:bar,foo2:bar2"); + } - /** - * Create a default key store for testing - * - * @return always returns a key store - */ - protected KeyStoreLoader.Result loadDefaultTestKey() { - try { + /** + * Create a default key store for testing + * + * @return always returns a key store + */ + protected KeyStoreLoader.Result loadDefaultTestKey() { + try { - final KeyStoreLoader loader = new KeyStoreLoader(); - loader.setUrl("file:src/test/resources/cert/cert.p12"); - loader.setKeyStorePassword("pwd1"); - loader.setKeyPassword("pwd1"); - return loader.load(); - } catch (final GeneralSecurityException | IOException e) { - throw new RuntimeException(e); - } + final KeyStoreLoader loader = new KeyStoreLoader(); + loader.setUrl("file:src/test/resources/cert/cert.p12"); + loader.setKeyStorePassword("pwd1"); + loader.setKeyPassword("pwd1"); + return loader.load(); + } catch (final GeneralSecurityException | IOException e) { + throw new RuntimeException(e); + } - } + } -} \ No newline at end of file +}
http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsCertTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsCertTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsCertTest.java index 3328902..e397520 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsCertTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsCertTest.java @@ -36,89 +36,88 @@ import org.junit.Test; */ public class MonitorItemMultiConnectionsCertTest extends AbstractMiloServerTest { - private static final String DIRECT_START_1 = "direct:start1"; - - private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; - - // with key - private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" - + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1") - + "&keyStoreUrl=file:src/test/resources/cert/cert.p12&keyStorePassword=pwd1&keyPassword=pwd1"; - - // with wrong password - private static final String MILO_CLIENT_ITEM_C2_1 = "milo-client:tcp://foo:bar2@localhost:12685?node=" - + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - - // without key, clientId=1 - private static final String MILO_CLIENT_ITEM_C3_1 = "milo-client:tcp://foo:bar@localhost:12685?clientId=1&node=" - + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - - private static final String MOCK_TEST_1 = "mock:test1"; - private static final String MOCK_TEST_2 = "mock:test2"; - private static final String MOCK_TEST_3 = "mock:test3"; - - @EndpointInject(uri = MOCK_TEST_1) - protected MockEndpoint test1Endpoint; - - @EndpointInject(uri = MOCK_TEST_2) - protected MockEndpoint test2Endpoint; - - @EndpointInject(uri = MOCK_TEST_3) - protected MockEndpoint test3Endpoint; - - @Produce(uri = DIRECT_START_1) - protected ProducerTemplate producer1; - - @Override - protected void configureMiloServer(final MiloServerComponent server) throws Exception { - super.configureMiloServer(server); - - final Path baseDir = Paths.get("target/testing/cert/default"); - final Path trusted = baseDir.resolve("trusted"); - - Files.createDirectories(trusted); - Files.copy(Paths.get("src/test/resources/cert/certificate.der"), trusted.resolve("certificate.der"), - REPLACE_EXISTING); - - server.setServerCertificate(loadDefaultTestKey()); - server.setDefaultCertificateValidator(baseDir.toFile()); - } - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); - - from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); - from(MILO_CLIENT_ITEM_C2_1).to(MOCK_TEST_2); - from(MILO_CLIENT_ITEM_C3_1).to(MOCK_TEST_3); - } - }; - } - - /** - * Monitor multiple connections, but only one has the correct credentials - */ - @Test - public void testMonitorItem1() throws Exception { - // set server value - this.producer1.sendBody("Foo"); - - // item 1 ... only this one receives - this.test1Endpoint.setExpectedCount(1); - this.test1Endpoint.setSleepForEmptyTest(5_000); - - // item 2 - this.test2Endpoint.setExpectedCount(0); - this.test2Endpoint.setSleepForEmptyTest(5_000); - - // item 3 - this.test3Endpoint.setExpectedCount(0); - this.test3Endpoint.setSleepForEmptyTest(5_000); - - // assert - this.assertMockEndpointsSatisfied(); - } + private static final String DIRECT_START_1 = "direct:start1"; + + private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; + + // with key + private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1") + + "&keyStoreUrl=file:src/test/resources/cert/cert.p12&keyStorePassword=pwd1&keyPassword=pwd1"; + + // with wrong password + private static final String MILO_CLIENT_ITEM_C2_1 = "milo-client:tcp://foo:bar2@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + + // without key, clientId=1 + private static final String MILO_CLIENT_ITEM_C3_1 = "milo-client:tcp://foo:bar@localhost:12685?clientId=1&node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + + private static final String MOCK_TEST_1 = "mock:test1"; + private static final String MOCK_TEST_2 = "mock:test2"; + private static final String MOCK_TEST_3 = "mock:test3"; + + @EndpointInject(uri = MOCK_TEST_1) + protected MockEndpoint test1Endpoint; + + @EndpointInject(uri = MOCK_TEST_2) + protected MockEndpoint test2Endpoint; + + @EndpointInject(uri = MOCK_TEST_3) + protected MockEndpoint test3Endpoint; + + @Produce(uri = DIRECT_START_1) + protected ProducerTemplate producer1; + + @Override + protected void configureMiloServer(final MiloServerComponent server) throws Exception { + super.configureMiloServer(server); + + final Path baseDir = Paths.get("target/testing/cert/default"); + final Path trusted = baseDir.resolve("trusted"); + + Files.createDirectories(trusted); + Files.copy(Paths.get("src/test/resources/cert/certificate.der"), trusted.resolve("certificate.der"), REPLACE_EXISTING); + + server.setServerCertificate(loadDefaultTestKey()); + server.setDefaultCertificateValidator(baseDir.toFile()); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); + + from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); + from(MILO_CLIENT_ITEM_C2_1).to(MOCK_TEST_2); + from(MILO_CLIENT_ITEM_C3_1).to(MOCK_TEST_3); + } + }; + } + + /** + * Monitor multiple connections, but only one has the correct credentials + */ + @Test + public void testMonitorItem1() throws Exception { + // set server value + this.producer1.sendBody("Foo"); + + // item 1 ... only this one receives + this.test1Endpoint.setExpectedCount(1); + this.test1Endpoint.setSleepForEmptyTest(5_000); + + // item 2 + this.test2Endpoint.setExpectedCount(0); + this.test2Endpoint.setSleepForEmptyTest(5_000); + + // item 3 + this.test3Endpoint.setExpectedCount(0); + this.test3Endpoint.setSleepForEmptyTest(5_000); + + // assert + this.assertMockEndpointsSatisfied(); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsTest.java index 791e4e4..bb5463c 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemMultiConnectionsTest.java @@ -30,67 +30,70 @@ import org.junit.Test; */ public class MonitorItemMultiConnectionsTest extends AbstractMiloServerTest { - private static final String DIRECT_START_1 = "direct:start1"; + private static final String DIRECT_START_1 = "direct:start1"; - private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; + private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; - private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MILO_CLIENT_ITEM_C2_1 = "milo-client:tcp://foo:bar2@localhost:12685?node=" + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C2_1 = "milo-client:tcp://foo:bar2@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MILO_CLIENT_ITEM_C3_1 = "milo-client:tcp://foo2:bar@localhost:12685?node=" + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C3_1 = "milo-client:tcp://foo2:bar@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MOCK_TEST_1 = "mock:test1"; - private static final String MOCK_TEST_2 = "mock:test2"; - private static final String MOCK_TEST_3 = "mock:test3"; + private static final String MOCK_TEST_1 = "mock:test1"; + private static final String MOCK_TEST_2 = "mock:test2"; + private static final String MOCK_TEST_3 = "mock:test3"; - @EndpointInject(uri = MOCK_TEST_1) - protected MockEndpoint test1Endpoint; + @EndpointInject(uri = MOCK_TEST_1) + protected MockEndpoint test1Endpoint; - @EndpointInject(uri = MOCK_TEST_2) - protected MockEndpoint test2Endpoint; + @EndpointInject(uri = MOCK_TEST_2) + protected MockEndpoint test2Endpoint; - @EndpointInject(uri = MOCK_TEST_3) - protected MockEndpoint test3Endpoint; + @EndpointInject(uri = MOCK_TEST_3) + protected MockEndpoint test3Endpoint; - @Produce(uri = DIRECT_START_1) - protected ProducerTemplate producer1; + @Produce(uri = DIRECT_START_1) + protected ProducerTemplate producer1; - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); - from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); - from(MILO_CLIENT_ITEM_C2_1).to(MOCK_TEST_2); - from(MILO_CLIENT_ITEM_C3_1).to(MOCK_TEST_3); - } - }; - } + from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); + from(MILO_CLIENT_ITEM_C2_1).to(MOCK_TEST_2); + from(MILO_CLIENT_ITEM_C3_1).to(MOCK_TEST_3); + } + }; + } - /** - * Monitor multiple connections, but only one has the correct credentials - */ - @Test - public void testMonitorItem1() throws Exception { - // set server value - this.producer1.sendBody("Foo"); + /** + * Monitor multiple connections, but only one has the correct credentials + */ + @Test + public void testMonitorItem1() throws Exception { + // set server value + this.producer1.sendBody("Foo"); - // item 1 ... only this one receives - this.test1Endpoint.setExpectedCount(1); - this.test1Endpoint.setSleepForEmptyTest(5_000); + // item 1 ... only this one receives + this.test1Endpoint.setExpectedCount(1); + this.test1Endpoint.setSleepForEmptyTest(5_000); - // item 2 - this.test2Endpoint.setExpectedCount(0); - this.test2Endpoint.setSleepForEmptyTest(5_000); + // item 2 + this.test2Endpoint.setExpectedCount(0); + this.test2Endpoint.setSleepForEmptyTest(5_000); - // item 3 - this.test3Endpoint.setExpectedCount(0); - this.test3Endpoint.setSleepForEmptyTest(5_000); + // item 3 + this.test3Endpoint.setExpectedCount(0); + this.test3Endpoint.setSleepForEmptyTest(5_000); - // assert - this.assertMockEndpointsSatisfied(); - } + // assert + this.assertMockEndpointsSatisfied(); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemTest.java index 6c11b64..bca304c 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/MonitorItemTest.java @@ -30,59 +30,60 @@ import org.junit.Test; */ public class MonitorItemTest extends AbstractMiloServerTest { - private static final String DIRECT_START_1 = "direct:start1"; + private static final String DIRECT_START_1 = "direct:start1"; - private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; + private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; - private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C1_1 = "milo-client:tcp://foo:bar@localhost:12685?node=" + + NodeIds.nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MOCK_TEST_1 = "mock:test1"; + private static final String MOCK_TEST_1 = "mock:test1"; - @EndpointInject(uri = MOCK_TEST_1) - protected MockEndpoint test1Endpoint; + @EndpointInject(uri = MOCK_TEST_1) + protected MockEndpoint test1Endpoint; - @Produce(uri = DIRECT_START_1) - protected ProducerTemplate producer1; + @Produce(uri = DIRECT_START_1) + protected ProducerTemplate producer1; - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(DIRECT_START_1).to(MILO_SERVER_ITEM_1); - from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); - } - }; - } + from(MILO_CLIENT_ITEM_C1_1).to(MOCK_TEST_1); + } + }; + } - /** - * Monitor multiple events - */ - @Test - public void testMonitorItem1() throws Exception { - /* - * we will wait 2 * 1_000 milliseconds between server updates since the - * default server update rate is 1_000 milliseconds - */ + /** + * Monitor multiple events + */ + @Test + public void testMonitorItem1() throws Exception { + /* + * we will wait 2 * 1_000 milliseconds between server updates since the + * default server update rate is 1_000 milliseconds + */ - // set server values - this.producer1.sendBody("Foo"); - Thread.sleep(2_000); - this.producer1.sendBody("Bar"); - Thread.sleep(2_000); - this.producer1.sendBody("Baz"); - Thread.sleep(2_000); + // set server values + this.producer1.sendBody("Foo"); + Thread.sleep(2_000); + this.producer1.sendBody("Bar"); + Thread.sleep(2_000); + this.producer1.sendBody("Baz"); + Thread.sleep(2_000); - // item 1 ... only this one receives - this.test1Endpoint.setExpectedCount(3); + // item 1 ... only this one receives + this.test1Endpoint.setExpectedCount(3); - // tests - testBody(this.test1Endpoint.message(0), assertGoodValue("Foo")); - testBody(this.test1Endpoint.message(1), assertGoodValue("Bar")); - testBody(this.test1Endpoint.message(2), assertGoodValue("Baz")); + // tests + testBody(this.test1Endpoint.message(0), assertGoodValue("Foo")); + testBody(this.test1Endpoint.message(1), assertGoodValue("Bar")); + testBody(this.test1Endpoint.message(2), assertGoodValue("Baz")); - // assert - this.assertMockEndpointsSatisfied(); - } + // assert + this.assertMockEndpointsSatisfied(); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/NodeIdTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/NodeIdTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/NodeIdTest.java index a832f87..857d7a0 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/NodeIdTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/NodeIdTest.java @@ -32,61 +32,55 @@ import org.junit.Test; */ public class NodeIdTest extends AbstractMiloServerTest { - @Test - public void testFull1() { - final String s = String.format("nsu=%s;s=%s", DEFAULT_NAMESPACE_URI, "item-1"); - testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", - DEFAULT_NAMESPACE_URI, "item-1"); - } - - @Test - public void testFull2() { - final String s = String.format("ns=%s;s=%s", 1, "item-1"); - testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", ushort(1), - "item-1"); - } - - @Test - public void testFull3() { - final String s = String.format("ns=%s;i=%s", 1, 2); - testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", ushort(1), - uint(2)); - } - - @Test - public void testFull1NonRaw() { - final String s = String.format("ns=%s;i=%s", 1, 2); - testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=" - + urlFormParameterEscaper().escape(s), ushort(1), uint(2)); - } - - @Test - public void testDocURL() { - testUri("milo-client://user:password@localhost:12345?node=RAW(nsu=http://foo.bar;s=foo/bar)", "http://foo.bar", - "foo/bar"); - } - - @Test(expected = ResolveEndpointFailedException.class) - public void testMixed() { - // This must fail since "node" is incomplete - testUri("milo-client:tcp://foo:bar@localhost:12685?node=foo&namespaceUri=" + DEFAULT_NAMESPACE_URI, null, null); - } - - private void testUri(final String uri, final Serializable namespace, final Serializable partialNodeId) { - assertNodeId(getMandatoryEndpoint(uri, MiloClientEndpoint.class), namespace, partialNodeId); - } - - private void assertNodeId(final MiloClientEndpoint endpoint, final Serializable namespace, - final Serializable partialNodeId) { - - final NamespaceId ns = endpoint.makeNamespaceId(); - final PartialNodeId pn = endpoint.makePartialNodeId(); - - assertNotNull(ns); - assertNotNull(pn); - - assertEquals(namespace, ns.getValue()); - assertEquals(partialNodeId, pn.getValue()); - } + @Test + public void testFull1() { + final String s = String.format("nsu=%s;s=%s", DEFAULT_NAMESPACE_URI, "item-1"); + testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", DEFAULT_NAMESPACE_URI, "item-1"); + } + + @Test + public void testFull2() { + final String s = String.format("ns=%s;s=%s", 1, "item-1"); + testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", ushort(1), "item-1"); + } + + @Test + public void testFull3() { + final String s = String.format("ns=%s;i=%s", 1, 2); + testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=RAW(" + s + ")", ushort(1), uint(2)); + } + + @Test + public void testFull1NonRaw() { + final String s = String.format("ns=%s;i=%s", 1, 2); + testUri("milo-client:tcp://foo:bar@localhost:12685?samplingInterval=1000&node=" + urlFormParameterEscaper().escape(s), ushort(1), uint(2)); + } + + @Test + public void testDocURL() { + testUri("milo-client://user:password@localhost:12345?node=RAW(nsu=http://foo.bar;s=foo/bar)", "http://foo.bar", "foo/bar"); + } + + @Test(expected = ResolveEndpointFailedException.class) + public void testMixed() { + // This must fail since "node" is incomplete + testUri("milo-client:tcp://foo:bar@localhost:12685?node=foo&namespaceUri=" + DEFAULT_NAMESPACE_URI, null, null); + } + + private void testUri(final String uri, final Serializable namespace, final Serializable partialNodeId) { + assertNodeId(getMandatoryEndpoint(uri, MiloClientEndpoint.class), namespace, partialNodeId); + } + + private void assertNodeId(final MiloClientEndpoint endpoint, final Serializable namespace, final Serializable partialNodeId) { + + final NamespaceId ns = endpoint.makeNamespaceId(); + final PartialNodeId pn = endpoint.makePartialNodeId(); + + assertNotNull(ns); + assertNotNull(pn); + + assertEquals(namespace, ns.getValue()); + assertEquals(partialNodeId, pn.getValue()); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/WriteClientTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/WriteClientTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/WriteClientTest.java index 4216038..abf675d 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/WriteClientTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/WriteClientTest.java @@ -33,122 +33,122 @@ import org.junit.Test; */ public class WriteClientTest extends AbstractMiloServerTest { - private static final String DIRECT_START_1 = "direct:start1"; - private static final String DIRECT_START_2 = "direct:start2"; - private static final String DIRECT_START_3 = "direct:start3"; - private static final String DIRECT_START_4 = "direct:start4"; - - private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; - private static final String MILO_SERVER_ITEM_2 = "milo-server:myitem2"; - - private static final String MILO_CLIENT_BASE_C1 = "milo-client:tcp://foo:bar@localhost:12685"; - private static final String MILO_CLIENT_BASE_C2 = "milo-client:tcp://foo2:bar2@localhost:12685"; - - private static final String MILO_CLIENT_ITEM_C1_1 = MILO_CLIENT_BASE_C1 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MILO_CLIENT_ITEM_C1_2 = MILO_CLIENT_BASE_C1 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem2"); - - private static final String MILO_CLIENT_ITEM_C2_1 = MILO_CLIENT_BASE_C2 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); - private static final String MILO_CLIENT_ITEM_C2_2 = MILO_CLIENT_BASE_C2 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem2"); - - private static final String MOCK_TEST_1 = "mock:test1"; - private static final String MOCK_TEST_2 = "mock:test2"; - - @EndpointInject(uri = MOCK_TEST_1) - protected MockEndpoint test1Endpoint; - - @EndpointInject(uri = MOCK_TEST_2) - protected MockEndpoint test2Endpoint; - - @Produce(uri = DIRECT_START_1) - protected ProducerTemplate producer1; - - @Produce(uri = DIRECT_START_2) - protected ProducerTemplate producer2; - - @Produce(uri = DIRECT_START_3) - protected ProducerTemplate producer3; - - @Produce(uri = DIRECT_START_4) - protected ProducerTemplate producer4; - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - - from(MILO_SERVER_ITEM_1).to(MOCK_TEST_1); - from(MILO_SERVER_ITEM_2).to(MOCK_TEST_2); - - from(DIRECT_START_1).to(MILO_CLIENT_ITEM_C1_1); - from(DIRECT_START_2).to(MILO_CLIENT_ITEM_C1_2); - - from(DIRECT_START_3).to(MILO_CLIENT_ITEM_C2_1); - from(DIRECT_START_4).to(MILO_CLIENT_ITEM_C2_2); - } - }; - } - - @Test - public void testWrite1() throws Exception { - // item 1 - this.test1Endpoint.setExpectedCount(2); - testBody(this.test1Endpoint.message(0), assertGoodValue("Foo1")); - testBody(this.test1Endpoint.message(1), assertGoodValue("Foo2")); - - // item 2 - this.test2Endpoint.setExpectedCount(0); - - // send - sendValue(this.producer1, new Variant("Foo1")); - sendValue(this.producer1, new Variant("Foo2")); - - // assert - this.assertMockEndpointsSatisfied(); - } - - @Test - public void testWrite2() throws Exception { - // item 1 - this.test1Endpoint.setExpectedCount(0); - - // item 2 - this.test2Endpoint.setExpectedCount(2); - testBody(this.test2Endpoint.message(0), assertGoodValue("Foo1")); - testBody(this.test2Endpoint.message(1), assertGoodValue("Foo2")); - - // send - sendValue(this.producer2, new Variant("Foo1")); - sendValue(this.producer2, new Variant("Foo2")); - - // assert - this.assertMockEndpointsSatisfied(); - } - - @Test - public void testWrite3() throws Exception { - // item 1 - this.test1Endpoint.setExpectedCount(2); - testBody(this.test1Endpoint.message(0), assertGoodValue("Foo1")); - testBody(this.test1Endpoint.message(1), assertGoodValue("Foo3")); - - // item 1 - this.test2Endpoint.setExpectedCount(2); - testBody(this.test2Endpoint.message(0), assertGoodValue("Foo2")); - testBody(this.test2Endpoint.message(1), assertGoodValue("Foo4")); - - // send - sendValue(this.producer1, new Variant("Foo1")); - sendValue(this.producer2, new Variant("Foo2")); - sendValue(this.producer3, new Variant("Foo3")); - sendValue(this.producer4, new Variant("Foo4")); - - // assert - assertMockEndpointsSatisfied(); - } - - private static void sendValue(final ProducerTemplate producerTemplate, final Variant variant) { - // we always write synchronously since we do need the message order - producerTemplate.sendBodyAndHeader(variant, "await", true); - } + private static final String DIRECT_START_1 = "direct:start1"; + private static final String DIRECT_START_2 = "direct:start2"; + private static final String DIRECT_START_3 = "direct:start3"; + private static final String DIRECT_START_4 = "direct:start4"; + + private static final String MILO_SERVER_ITEM_1 = "milo-server:myitem1"; + private static final String MILO_SERVER_ITEM_2 = "milo-server:myitem2"; + + private static final String MILO_CLIENT_BASE_C1 = "milo-client:tcp://foo:bar@localhost:12685"; + private static final String MILO_CLIENT_BASE_C2 = "milo-client:tcp://foo2:bar2@localhost:12685"; + + private static final String MILO_CLIENT_ITEM_C1_1 = MILO_CLIENT_BASE_C1 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C1_2 = MILO_CLIENT_BASE_C1 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem2"); + + private static final String MILO_CLIENT_ITEM_C2_1 = MILO_CLIENT_BASE_C2 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem1"); + private static final String MILO_CLIENT_ITEM_C2_2 = MILO_CLIENT_BASE_C2 + "?node=" + nodeValue(MiloServerComponent.DEFAULT_NAMESPACE_URI, "items-myitem2"); + + private static final String MOCK_TEST_1 = "mock:test1"; + private static final String MOCK_TEST_2 = "mock:test2"; + + @EndpointInject(uri = MOCK_TEST_1) + protected MockEndpoint test1Endpoint; + + @EndpointInject(uri = MOCK_TEST_2) + protected MockEndpoint test2Endpoint; + + @Produce(uri = DIRECT_START_1) + protected ProducerTemplate producer1; + + @Produce(uri = DIRECT_START_2) + protected ProducerTemplate producer2; + + @Produce(uri = DIRECT_START_3) + protected ProducerTemplate producer3; + + @Produce(uri = DIRECT_START_4) + protected ProducerTemplate producer4; + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + + from(MILO_SERVER_ITEM_1).to(MOCK_TEST_1); + from(MILO_SERVER_ITEM_2).to(MOCK_TEST_2); + + from(DIRECT_START_1).to(MILO_CLIENT_ITEM_C1_1); + from(DIRECT_START_2).to(MILO_CLIENT_ITEM_C1_2); + + from(DIRECT_START_3).to(MILO_CLIENT_ITEM_C2_1); + from(DIRECT_START_4).to(MILO_CLIENT_ITEM_C2_2); + } + }; + } + + @Test + public void testWrite1() throws Exception { + // item 1 + this.test1Endpoint.setExpectedCount(2); + testBody(this.test1Endpoint.message(0), assertGoodValue("Foo1")); + testBody(this.test1Endpoint.message(1), assertGoodValue("Foo2")); + + // item 2 + this.test2Endpoint.setExpectedCount(0); + + // send + sendValue(this.producer1, new Variant("Foo1")); + sendValue(this.producer1, new Variant("Foo2")); + + // assert + this.assertMockEndpointsSatisfied(); + } + + @Test + public void testWrite2() throws Exception { + // item 1 + this.test1Endpoint.setExpectedCount(0); + + // item 2 + this.test2Endpoint.setExpectedCount(2); + testBody(this.test2Endpoint.message(0), assertGoodValue("Foo1")); + testBody(this.test2Endpoint.message(1), assertGoodValue("Foo2")); + + // send + sendValue(this.producer2, new Variant("Foo1")); + sendValue(this.producer2, new Variant("Foo2")); + + // assert + this.assertMockEndpointsSatisfied(); + } + + @Test + public void testWrite3() throws Exception { + // item 1 + this.test1Endpoint.setExpectedCount(2); + testBody(this.test1Endpoint.message(0), assertGoodValue("Foo1")); + testBody(this.test1Endpoint.message(1), assertGoodValue("Foo3")); + + // item 1 + this.test2Endpoint.setExpectedCount(2); + testBody(this.test2Endpoint.message(0), assertGoodValue("Foo2")); + testBody(this.test2Endpoint.message(1), assertGoodValue("Foo4")); + + // send + sendValue(this.producer1, new Variant("Foo1")); + sendValue(this.producer2, new Variant("Foo2")); + sendValue(this.producer3, new Variant("Foo3")); + sendValue(this.producer4, new Variant("Foo4")); + + // assert + assertMockEndpointsSatisfied(); + } + + private static void sendValue(final ProducerTemplate producerTemplate, final Variant variant) { + // we always write synchronously since we do need the message order + producerTemplate.sendBodyAndHeader(variant, "await", true); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/converter/ConverterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/converter/ConverterTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/converter/ConverterTest.java index 5d00ae3..93a8f78 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/converter/ConverterTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/converter/ConverterTest.java @@ -24,26 +24,26 @@ import org.junit.Test; public class ConverterTest extends CamelTestSupport { - @Test - public void testDataValueToVariant() { - final Variant value = testConvertDataValue("Foo", Variant.class); - Assert.assertNotNull(value); - Assert.assertEquals("Foo", value.getValue()); - } + @Test + public void testDataValueToVariant() { + final Variant value = testConvertDataValue("Foo", Variant.class); + Assert.assertNotNull(value); + Assert.assertEquals("Foo", value.getValue()); + } - @Test - public void testVariantToDataValue() { - final DataValue value = testConvert(new Variant("Foo"), DataValue.class); - Assert.assertNotNull(value); - Assert.assertEquals("Foo", value.getValue().getValue()); - Assert.assertTrue(value.getStatusCode().isGood()); - } + @Test + public void testVariantToDataValue() { + final DataValue value = testConvert(new Variant("Foo"), DataValue.class); + Assert.assertNotNull(value); + Assert.assertEquals("Foo", value.getValue().getValue()); + Assert.assertTrue(value.getStatusCode().isGood()); + } - private <T> T testConvert(final Object value, final Class<T> clazz) { - return this.context.getTypeConverter().convertTo(clazz, value); - } + private <T> T testConvert(final Object value, final Class<T> clazz) { + return this.context.getTypeConverter().convertTo(clazz, value); + } - private <T> T testConvertDataValue(final Object value, final Class<T> clazz) { - return this.context.getTypeConverter().convertTo(clazz, new DataValue(new Variant(value))); - } + private <T> T testConvertDataValue(final Object value, final Class<T> clazz) { + return this.context.getTypeConverter().convertTo(clazz, new DataValue(new Variant(value))); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java index 53b66ec..3195e18 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java @@ -30,54 +30,54 @@ import org.junit.Test; */ public class ServerLocalTest extends CamelTestSupport { - private static final String MILO_ITEM_1 = "milo-server:myitem1"; + private static final String MILO_ITEM_1 = "milo-server:myitem1"; - private static final String MOCK_TEST = "mock:test"; + private static final String MOCK_TEST = "mock:test"; - @EndpointInject(uri = MOCK_TEST) - protected MockEndpoint testEndpoint; + @EndpointInject(uri = MOCK_TEST) + protected MockEndpoint testEndpoint; - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from(MILO_ITEM_1).to(MOCK_TEST); - } - }; - } + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(MILO_ITEM_1).to(MOCK_TEST); + } + }; + } - @Test - public void shouldStartComponent() { - } + @Test + public void shouldStartComponent() { + } - @Test - public void testAcceptVariantString() { - sendBody(MILO_ITEM_1, new Variant("Foo")); - } + @Test + public void testAcceptVariantString() { + sendBody(MILO_ITEM_1, new Variant("Foo")); + } - @Test - public void testAcceptVariantDouble() { - sendBody(MILO_ITEM_1, new Variant(0.0)); - } + @Test + public void testAcceptVariantDouble() { + sendBody(MILO_ITEM_1, new Variant(0.0)); + } - @Test - public void testAcceptString() { - sendBody(MILO_ITEM_1, "Foo"); - } + @Test + public void testAcceptString() { + sendBody(MILO_ITEM_1, "Foo"); + } - @Test - public void testAcceptDouble() { - sendBody(MILO_ITEM_1, 0.0); - } + @Test + public void testAcceptDouble() { + sendBody(MILO_ITEM_1, 0.0); + } - @Test - public void testAcceptDataValueString() { - sendBody(MILO_ITEM_1, new DataValue(new Variant("Foo"))); - } + @Test + public void testAcceptDataValueString() { + sendBody(MILO_ITEM_1, new DataValue(new Variant("Foo"))); + } - @Test - public void testAcceptDataValueDouble() { - sendBody(MILO_ITEM_1, new DataValue(new Variant(0.0))); - } + @Test + public void testAcceptDataValueDouble() { + sendBody(MILO_ITEM_1, new DataValue(new Variant(0.0))); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetCertificateManagerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetCertificateManagerTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetCertificateManagerTest.java index 35f31d6..979451b 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetCertificateManagerTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetCertificateManagerTest.java @@ -30,22 +30,21 @@ import org.junit.Test; */ public class ServerSetCertificateManagerTest extends AbstractMiloServerTest { - @Override - protected void configureMiloServer(final MiloServerComponent server) throws Exception { - super.configureMiloServer(server); + @Override + protected void configureMiloServer(final MiloServerComponent server) throws Exception { + super.configureMiloServer(server); - final Path baseDir = Paths.get("target/testing/cert/default"); - final Path trusted = baseDir.resolve("trusted"); + final Path baseDir = Paths.get("target/testing/cert/default"); + final Path trusted = baseDir.resolve("trusted"); - Files.createDirectories(trusted); - Files.copy(Paths.get("src/test/resources/cert/certificate.der"), trusted.resolve("certificate.der"), - REPLACE_EXISTING); + Files.createDirectories(trusted); + Files.copy(Paths.get("src/test/resources/cert/certificate.der"), trusted.resolve("certificate.der"), REPLACE_EXISTING); - server.setServerCertificate(loadDefaultTestKey()); - server.setDefaultCertificateValidator(baseDir.toFile()); - } + server.setServerCertificate(loadDefaultTestKey()); + server.setDefaultCertificateValidator(baseDir.toFile()); + } - @Test - public void shouldStart() { - } + @Test + public void shouldStart() { + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java index 75e3457..92148aa 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java @@ -24,27 +24,27 @@ import org.junit.Test; */ public class ServerSetSecurityPoliciesTest extends CamelTestSupport { - @Test - public void testSetSecurityPolicies1() { - final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("None"); - } + @Test + public void testSetSecurityPolicies1() { + final MiloServerComponent component = new MiloServerComponent(); + component.setSecurityPoliciesById("None"); + } - @Test - public void testSetSecurityPolicies2() { - final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); - } + @Test + public void testSetSecurityPolicies2() { + final MiloServerComponent component = new MiloServerComponent(); + component.setSecurityPoliciesById("http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); + } - @Test - public void testSetSecurityPolicies3() { - final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("None", "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); - } + @Test + public void testSetSecurityPolicies3() { + final MiloServerComponent component = new MiloServerComponent(); + component.setSecurityPoliciesById("None", "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); + } - @Test(expected = IllegalArgumentException.class) - public void testSetSecurityPolicies4() { - final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("I just made that up"); - } + @Test(expected = IllegalArgumentException.class) + public void testSetSecurityPolicies4() { + final MiloServerComponent component = new MiloServerComponent(); + component.setSecurityPoliciesById("I just made that up"); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application.java index 1fa5df6..e49fea9 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application.java @@ -21,52 +21,49 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; public class Application { - public static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - // camel conext + // camel conext - final CamelContext context = new DefaultCamelContext(); + final CamelContext context = new DefaultCamelContext(); - // add paho + // add paho - // no need to register, gets auto detected - // context.addComponent("paho", new PahoComponent()); + // no need to register, gets auto detected + // context.addComponent("paho", new PahoComponent()); - // no need to register, gets auto detected - // context.addComponent("milo-server", new MiloClientComponent()); - // context.addComponent("milo-client", new MiloClientComponent()); + // no need to register, gets auto detected + // context.addComponent("milo-server", new MiloClientComponent()); + // context.addComponent("milo-client", new MiloClientComponent()); - // add routes + // add routes - context.addRoutes(new RouteBuilder() { + context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("paho:javaonedemo/eclipse-greenhouse-9home/sensors/temperature?brokerUrl=tcp://iot.eclipse.org:1883") - .log("Temp update: ${body}").convertBodyTo(String.class).to("milo-server:MyItem"); + @Override + public void configure() throws Exception { + from("paho:javaonedemo/eclipse-greenhouse-9home/sensors/temperature?brokerUrl=tcp://iot.eclipse.org:1883").log("Temp update: ${body}").convertBodyTo(String.class) + .to("milo-server:MyItem"); - from("milo-server:MyItem").log("MyItem: ${body}"); + from("milo-server:MyItem").log("MyItem: ${body}"); - from("milo-server:MyItem2").log("MyItem2 : ${body}") - .to("paho:de/dentrassi/camel/milo/test1?brokerUrl=tcp://iot.eclipse.org:1883"); + from("milo-server:MyItem2").log("MyItem2 : ${body}").to("paho:de/dentrassi/camel/milo/test1?brokerUrl=tcp://iot.eclipse.org:1883"); - from("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem&namespaceUri=urn:camel") - .log("From OPC UA: ${body}") - .to("milo-client:tcp://localhost:12685?nodeId=items-MyItem2&namespaceUri=urn:camel"); + from("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem&namespaceUri=urn:camel").log("From OPC UA: ${body}") + .to("milo-client:tcp://localhost:12685?nodeId=items-MyItem2&namespaceUri=urn:camel"); - from("paho:de/dentrassi/camel/milo/test1?brokerUrl=tcp://iot.eclipse.org:1883") - .log("Back from MQTT: ${body}"); - } - }); + from("paho:de/dentrassi/camel/milo/test1?brokerUrl=tcp://iot.eclipse.org:1883").log("Back from MQTT: ${body}"); + } + }); - // start + // start - context.start(); + context.start(); - // sleep + // sleep - while (true) { - Thread.sleep(Long.MAX_VALUE); - } - } + while (true) { + Thread.sleep(Long.MAX_VALUE); + } + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Client.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Client.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Client.java index 4d76b38..3f03789 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Client.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Client.java @@ -21,39 +21,38 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; public class Application2Client { - public static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - // camel conext + // camel conext - final CamelContext context = new DefaultCamelContext(); + final CamelContext context = new DefaultCamelContext(); - // add paho + // add paho - // no need to register, gets auto detected - // context.addComponent("paho", new PahoComponent()); + // no need to register, gets auto detected + // context.addComponent("paho", new PahoComponent()); - // add OPC UA + // add OPC UA - // add routes + // add routes - context.addRoutes(new RouteBuilder() { + context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem&namespaceUri=urn:org:apache:camel") - .log("From OPC UA: ${body}") - .to("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem2&namespaceUri=urn:org:apache:camel"); - } - }); + @Override + public void configure() throws Exception { + from("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem&namespaceUri=urn:org:apache:camel").log("From OPC UA: ${body}") + .to("milo-client:tcp://foo:bar@localhost:12685?nodeId=items-MyItem2&namespaceUri=urn:org:apache:camel"); + } + }); - // start + // start - context.start(); + context.start(); - // sleep + // sleep - while (true) { - Thread.sleep(Long.MAX_VALUE); - } - } + while (true) { + Thread.sleep(Long.MAX_VALUE); + } + } } http://git-wip-us.apache.org/repos/asf/camel/blob/19db14d7/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Server.java ---------------------------------------------------------------------- diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Server.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Server.java index af596cf..21d955e 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Server.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/testing/Application2Server.java @@ -22,51 +22,48 @@ import org.apache.camel.component.milo.server.MiloServerComponent; import org.apache.camel.impl.DefaultCamelContext; public class Application2Server { - public static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - // camel conext + // camel conext - final CamelContext context = new DefaultCamelContext(); + final CamelContext context = new DefaultCamelContext(); - // add paho + // add paho - // no need to register, gets auto detected - // context.addComponent("paho", new PahoComponent()); - ((MiloServerComponent) context.getComponent("milo-server")).setUserAuthenticationCredentials("foo:bar"); + // no need to register, gets auto detected + // context.addComponent("paho", new PahoComponent()); + ((MiloServerComponent)context.getComponent("milo-server")).setUserAuthenticationCredentials("foo:bar"); - // add routes + // add routes - context.addRoutes(new RouteBuilder() { + context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - /* - * from( - * "paho:javaonedemo/eclipse-greenhouse-9home/sensors/temperature?brokerUrl=tcp://iot.eclipse.org:1883") - * .log("Temp update: ${body}").convertBodyTo(String.class).to( - * "milo-server:MyItem"); - */ + @Override + public void configure() throws Exception { + /* + * from( + * "paho:javaonedemo/eclipse-greenhouse-9home/sensors/temperature?brokerUrl=tcp://iot.eclipse.org:1883") + * .log("Temp update: ${body}").convertBodyTo(String.class).to( + * "milo-server:MyItem"); + */ - from("paho:my/foo/bar?brokerUrl=tcp://iot.eclipse.org:1883").log("Temp update: ${body}") - .convertBodyTo(String.class).to("milo-server:MyItem"); + from("paho:my/foo/bar?brokerUrl=tcp://iot.eclipse.org:1883").log("Temp update: ${body}").convertBodyTo(String.class).to("milo-server:MyItem"); - from("milo-server:MyItem").log("MyItem: ${body}"); - from("milo-server:MyItem2").log("MyItem2: ${body}").convertBodyTo(String.class) - .to("paho:de/dentrassi/camel/milo/temperature?brokerUrl=tcp://iot.eclipse.org:1883"); + from("milo-server:MyItem").log("MyItem: ${body}"); + from("milo-server:MyItem2").log("MyItem2: ${body}").convertBodyTo(String.class).to("paho:de/dentrassi/camel/milo/temperature?brokerUrl=tcp://iot.eclipse.org:1883"); - from("paho:de/dentrassi/camel/milo/temperature?brokerUrl=tcp://iot.eclipse.org:1883") - .log("Back from MQTT: ${body}"); - } - }); + from("paho:de/dentrassi/camel/milo/temperature?brokerUrl=tcp://iot.eclipse.org:1883").log("Back from MQTT: ${body}"); + } + }); - // start + // start - context.start(); + context.start(); - // sleep + // sleep - while (true) { - Thread.sleep(Long.MAX_VALUE); - } - } + while (true) { + Thread.sleep(Long.MAX_VALUE); + } + } }