http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mail/MailRouteTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mail/MailRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mail/MailRouteTest.java deleted file mode 100644 index 8f075b5..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mail/MailRouteTest.java +++ /dev/null @@ -1,146 +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.itest.osgi.mail; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -import javax.mail.Address; -import javax.mail.Message; -import javax.mail.Message.RecipientType; - - -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.converter.IOConverter; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.jvnet.mock_javamail.Mailbox; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.workingDirectory; -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -@Ignore("Does not work anymore as the mock javamail does not kick in as mail provider") -public class MailRouteTest extends OSGiIntegrationTestSupport { - - @Test - public void testSendAndReceiveMails() throws Exception { - Mailbox.clearAll(); - - MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); - resultEndpoint.expectedBodiesReceived("hello world!"); - - Map<String, Object> headers = new HashMap<String, Object>(); - headers.put("reply-to", "route-test-reply@localhost"); - template.sendBodyAndHeaders("smtp://route-test-james@localhost", "hello world!", headers); - - // lets test the first sent worked - assertMailboxReceivedMessages("route-test-james@localhost"); - - // lets sleep to check that the mail poll does not redeliver duplicate mails - Thread.sleep(3000); - - // lets test the receive worked - resultEndpoint.assertIsSatisfied(); - - // Validate that the headers were preserved. - Exchange exchange = resultEndpoint.getReceivedExchanges().get(0); - String replyTo = (String)exchange.getIn().getHeader("reply-to"); - assertEquals("route-test-reply@localhost", replyTo); - - assertMailboxReceivedMessages("route-test-copy@localhost"); - } - - protected void assertMailboxReceivedMessages(String name) throws Exception { - Mailbox mailbox = Mailbox.get(name); - assertEquals(name + " should have received 1 mail", 1, mailbox.size()); - - Message message = mailbox.get(0); - assertNotNull(name + " should have received at least one mail!", message); - Object content = message.getContent(); - assertNotNull("The content should not be null!", content); - if (content instanceof InputStream) { - assertEquals("hello world!", IOConverter.toString((InputStream)content, null)); - } else { - assertEquals("hello world!", message.getContent()); - } - assertEquals("camel@localhost", message.getFrom()[0].toString()); - boolean found = false; - for (Address adr : message.getRecipients(RecipientType.TO)) { - if (name.equals(adr.toString())) { - found = true; - } - } - assertTrue("Should have found the recipient to in the mail: " + name, found); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("pop3://route-test-james@localhost?consumer.delay=1000") - .to("direct:a"); - - // must use fixed to option to send the mail to the given receiver, as we have polled - // a mail from a mailbox where it already has the 'old' To as header value - // here we send the mail to 2 receivers. notice we can use a plain string with semi colon - // to separate the mail addresses - from("direct:a") - .setHeader("to", constant("route-test-result@localhost; route-test-copy@localhost")) - .to("smtp://localhost"); - - from("pop3://route-test-result@localhost?consumer.delay=1000") - .convertBodyTo(String.class).to("mock:result"); - } - }; - } - - @Configuration - public static Option[] configure() throws Exception { - Option[] options = combine( - - getDefaultCamelKarafOptions(), - // using the features to install the camel components - loadCamelFeatures("jetty"), - - // using the java mail API bundle - mavenBundle().groupId("org.apache.servicemix.specs").artifactId("org.apache.servicemix.specs.javamail-api-1.4").version("1.3.0"), - - mavenBundle().groupId("org.apache.camel").artifactId("camel-mail").versionAsInProject(), - - // Added the mock_java_mail bundle for testing - // just using the mock_java_mail version for testing - mavenBundle().groupId("org.apache.camel.tests").artifactId("org.apache.camel.tests.mock-javamail_1.7").version("2.8.3"), - - workingDirectory("target/paxrunner/"), - - // does not work in felix - equinox()); - - return options; - } - -}
http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mina/MinaTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mina/MinaTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mina/MinaTest.java deleted file mode 100644 index 810fd44..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mina/MinaTest.java +++ /dev/null @@ -1,62 +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.itest.osgi.mina; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class MinaTest extends OSGiIntegrationTestSupport { - - @Test - public void testMina() throws Exception { - getMockEndpoint("mock:result").expectedBodiesReceived("World"); - - String reply = template.requestBody("mina:tcp://localhost:8877?textline=true", "World", String.class); - assertEquals("Bye World", reply); - - assertMockEndpointsSatisfied(); - } - - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("mina:tcp://localhost:8877?textline=true") - .to("mock:result") - .transform(body().prepend("Bye ")); - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-mina")); - - return options; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mvel/MvelTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mvel/MvelTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mvel/MvelTest.java deleted file mode 100644 index 1101395..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mvel/MvelTest.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.itest.osgi.mvel; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.apache.camel.itest.osgi.core.bean.MyFooBean; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - - -@RunWith(PaxExam.class) -public class MvelTest extends OSGiIntegrationTestSupport { - - @Test - public void testMvelLanguage() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodyReceived(); - - template.sendBody("direct:testmvel", new MyFooBean()); - - } - - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("direct:testmvel").choice().when().mvel("request.body instanceof org.apache.camel.itest.osgi.core.bean.MyFooBean").to("mock:result"); - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - loadCamelFeatures("camel-mvel")); - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java deleted file mode 100644 index 2c9089f..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java +++ /dev/null @@ -1,65 +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.itest.osgi.mybatis; - -/** - * @version - */ -public class Account { - private int id; - private String firstName; - private String lastName; - private String emailAddress; - - @Override - public String toString() { - return "Account[id: " + id + " name: " + firstName + " " + lastName + " email: " + emailAddress + "]"; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java deleted file mode 100644 index d7449d0..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java +++ /dev/null @@ -1,116 +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.itest.osgi.mybatis; - -import java.sql.Connection; -import java.sql.Statement; - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mybatis.MyBatisComponent; -import org.apache.camel.component.mybatis.MyBatisEndpoint; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.OptionUtils.combine; - -/** - * @version - */ -@RunWith(PaxExam.class) -@Ignore("Loading OSGi driver in OSGi is ***** hard") -public class MyBatisTest extends OSGiIntegrationTestSupport { - - @Test - public void testMina() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(1); - - Account account = new Account(); - account.setId(444); - account.setFirstName("Willem"); - account.setLastName("Jiang"); - account.setEmailAddress("fara...@gmail.com"); - - template.sendBody("mybatis:insertAccount?statementType=Insert", account); - - assertMockEndpointsSatisfied(); - - dropTable(); - } - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - context.disableJMX(); - return context; - } - - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() throws Exception { - MyBatisComponent myBatis = context.getComponent("mybatis", MyBatisComponent.class); - myBatis.setConfigurationUri("org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml"); - - // create table before we start using mybatis - createTable(); - - from("mybatis:selectAllAccounts").to("mock:result"); - } - }; - } - - private void createTable() throws Exception { - // lets create the database... - Connection connection = createConnection(); - Statement statement = connection.createStatement(); - statement.execute("create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255) )"); - connection.close(); - } - - private void dropTable() throws Exception { - Connection connection = createConnection(); - Statement statement = connection.createStatement(); - statement.execute("drop table ACCOUNT"); - connection.close(); - } - - private Connection createConnection() throws Exception { - MyBatisEndpoint endpoint = resolveMandatoryEndpoint("mybatis:Account", MyBatisEndpoint.class); - return endpoint.getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource().getConnection(); - } - - @Configuration - public static Option[] configure() throws Exception { - Option[] options = combine( - - getDefaultCamelKarafOptions(), - // using the features to install the camel components - loadCamelFeatures("jetty", "camel-mybatis"), - - // use derby as the database - mavenBundle().groupId("org.apache.derby").artifactId("derby").version("10.4.2.0")); - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java deleted file mode 100644 index 32c179e..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java +++ /dev/null @@ -1,62 +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.itest.osgi.netty; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class NettyTest extends OSGiIntegrationTestSupport { - - @Test - public void testNetty() throws Exception { - getMockEndpoint("mock:result").expectedBodiesReceived("World"); - - String reply = template.requestBody("netty:tcp://localhost:8876?textline=true", "World", String.class); - assertEquals("Bye World", reply); - - assertMockEndpointsSatisfied(); - } - - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("netty:tcp://localhost:8876?textline=true") - .to("mock:result") - .transform(body().prepend("Bye ")); - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-netty")); - - return options; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java deleted file mode 100644 index b2ac9eb..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java +++ /dev/null @@ -1,116 +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.itest.osgi.protobuf; - -import org.apache.camel.CamelException; -import org.apache.camel.FailedToCreateRouteException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.dataformat.protobuf.ProtobufDataFormat; -import org.apache.camel.dataformat.protobuf.generated.AddressBookProtos; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class ProtobufRouteTest extends OSGiIntegrationTestSupport { - - @Test - public void testMarshalAndUnmarshalWithDataFormat() throws Exception { - marshalAndUnmarshal("direct:in", "direct:back"); - } - - @Test - public void testMarshalAndUnmarshalWithDSL1() throws Exception { - marshalAndUnmarshal("direct:marshal", "direct:unmarshalA"); - } - - @Test - public void testMarshalAndUnmarshalWithDSL2() throws Exception { - marshalAndUnmarshal("direct:marshal", "direct:unmarshalB"); - } - - @Test - public void testMarshalAndUnmashalWithDSL3() throws Exception { - try { - context.addRoutes(new RouteBuilder() { - public void configure() throws Exception { - from("direct:unmarshalC").unmarshal().protobuf(new CamelException("wrong instance")) - .to("mock:reverse"); - } - }); - fail("Expect the exception here"); - } catch (Exception ex) { - assertTrue("Expect FailedToCreateRouteException", ex instanceof FailedToCreateRouteException); - assertTrue("Get a wrong reason", ex.getCause() instanceof IllegalArgumentException); - } - } - - private void marshalAndUnmarshal(String inURI, String outURI) throws Exception { - AddressBookProtos.Person input = AddressBookProtos.Person - .newBuilder().setName("Martin").setId(1234).build(); - - MockEndpoint mock = getMockEndpoint("mock:reverse"); - mock.expectedMessageCount(1); - mock.message(0).body().isInstanceOf(org.apache.camel.dataformat.protobuf.generated.AddressBookProtos.Person.class); - mock.message(0).body().isEqualTo(input); - - Object marshalled = template.requestBody(inURI, input); - - template.sendBody(outURI, marshalled); - - mock.assertIsSatisfied(); - - AddressBookProtos.Person output = mock.getReceivedExchanges().get(0).getIn().getBody(AddressBookProtos.Person.class); - assertEquals("Martin", output.getName()); - } - - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - ProtobufDataFormat format = new ProtobufDataFormat(AddressBookProtos.Person.getDefaultInstance()); - - from("direct:in").marshal(format); - from("direct:back").unmarshal(format).to("mock:reverse"); - - from("direct:marshal").marshal().protobuf(); - from("direct:unmarshalA").unmarshal().protobuf("org.apache.camel.dataformat.protobuf.generated.AddressBookProtos$Person").to("mock:reverse"); - - from("direct:unmarshalB").unmarshal().protobuf(AddressBookProtos.Person.getDefaultInstance()).to("mock:reverse"); - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-protobuf")); - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java deleted file mode 100644 index 174a763..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java +++ /dev/null @@ -1,62 +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.itest.osgi.quartz; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class QuartzCronRouteTest extends OSGiIntegrationTestSupport { - - @Test - public void testQuartzCronRoute() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMinimumMessageCount(3); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("quartz://myGroup/myTimerName?cron=0/2+*+*+*+*+?").to("mock:result"); - } - }; - } - - @Configuration - public static Option[] configure() throws Exception { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-quartz")); - - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java deleted file mode 100644 index 51f0ff1..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.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.itest.osgi.restlet; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class RestletTest extends OSGiIntegrationTestSupport { - - @Test - public void testRestletProducer() throws Exception { - Map<String, Object> headers = new HashMap<String, Object>(); - headers.put("username", "homer"); - String response = (String)template.requestBodyAndHeaders("restlet:http://localhost:9080/users/{username}?restletMethod=POST", "<request>message</request>", headers); - assertEquals("The response is wrong ", response, "{homer}"); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("restlet:http://localhost:9080/users/{username}?restletMethod=POST").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String userName = exchange.getIn().getHeader("username", String.class); - assertNotNull("userName should not be null", userName); - exchange.getOut().setBody("{" + userName + "}"); - exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/JSON"); - } - }); - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-restlet")); - - return options; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityRestResponse.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityRestResponse.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityRestResponse.java deleted file mode 100644 index bd758cc..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityRestResponse.java +++ /dev/null @@ -1,42 +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.itest.osgi.restlet.example; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "CheckDomainResponse") -public class CheckDomainAvailabilityRestResponse { - private String requestId; - private String responseBody; - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResponseBody() { - return responseBody; - } - - public void setResponseBody(String responseBody) { - this.responseBody = responseBody; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityResult.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityResult.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityResult.java deleted file mode 100644 index 35a42be..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainAvailabilityResult.java +++ /dev/null @@ -1,42 +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.itest.osgi.restlet.example; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "CheckDomainAvailabilityResult") -public class CheckDomainAvailabilityResult { - private String requestId; - private String responseBody; - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResponseBody() { - return responseBody; - } - - public void setResponseBody(String responseBody) { - this.responseBody = responseBody; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainRequest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainRequest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainRequest.java deleted file mode 100755 index af821e37..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/CheckDomainRequest.java +++ /dev/null @@ -1,59 +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.itest.osgi.restlet.example; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "checkDomainRequest") -public class CheckDomainRequest { - private long id; - private String name; - private String username; - private String password; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/DomainService.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/DomainService.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/DomainService.java deleted file mode 100755 index d192e41..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/DomainService.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.itest.osgi.restlet.example; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -@Path("/domainservice/") -public class DomainService { - - public DomainService() { - } - - @GET - @Path("/domains/{id}/") - @Produces("application/json") - public String getDomain(@PathParam("id") String id) { - return "{www.google.com}"; - } - - @PUT - @Path("/domains/") - @Produces("application/json") - public Response updateDomain(String domain) { - return Response.ok().build(); - } - - @POST - @Path("/domains/") - @Produces("application/xml") - public CheckDomainAvailabilityRestResponse addDomain(CheckDomainRequest request) { - CheckDomainAvailabilityRestResponse response = new CheckDomainAvailabilityRestResponse(); - - response.setRequestId(String.valueOf(request.getId())); - response.setResponseBody("OK"); - - return response; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Order.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Order.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Order.java deleted file mode 100755 index 93eec76..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Order.java +++ /dev/null @@ -1,73 +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.itest.osgi.restlet.example; - -import java.util.HashMap; -import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.xml.bind.annotation.XmlRootElement; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@XmlRootElement(name = "Order") -public class Order { - - private static final Logger LOG = LoggerFactory.getLogger(Order.class); - private long id; - private String description; - private Map<Long, Product> products = new HashMap<Long, Product>(); - - public Order() { - init(); - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String d) { - this.description = d; - } - - @GET - @Path("products/{productId}/") - @Produces("application/xml") - public Product getProduct(@PathParam("productId")int productId) { - LOG.info("----invoking getProduct with id: " + productId); - Product p = products.get(new Long(productId)); - return p; - } - - final void init() { - Product p = new Product(); - p.setId(323); - p.setDescription("product 323"); - products.put(p.getId(), p); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Product.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Product.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Product.java deleted file mode 100755 index 712c566..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/Product.java +++ /dev/null @@ -1,41 +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.itest.osgi.restlet.example; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "Product") -public class Product { - private long id; - private String description; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String d) { - this.description = d; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/RestletDomainServiceTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/RestletDomainServiceTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/RestletDomainServiceTest.java deleted file mode 100644 index 0516628..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/example/RestletDomainServiceTest.java +++ /dev/null @@ -1,75 +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.itest.osgi.restlet.example; - -import org.apache.camel.Exchange; -import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -/** - * @version - */ -@RunWith(PaxExam.class) -@Ignore("PaxExam hang on shutdown of this test") -public class RestletDomainServiceTest extends OSGiIntegrationSpringTestSupport { - - @Override - protected OsgiBundleXmlApplicationContext createApplicationContext() { - return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/restlet/example/camel-context.xml"}); - } - - @Test - public void testAddDomain() throws Exception { - String input = "<checkDomainRequest><id>123</id><name>www.google.com</name><username>test</username><password>test</password></checkDomainRequest>"; - - String response = template.requestBodyAndHeader("restlet:http://localhost:9000/domainservice/domains?restletMethod=POST", - input, Exchange.CONTENT_TYPE, "application/xml", String.class); - - log.info("Response: " + response); - - assertNotNull(response); - assertTrue("Should contains response", response.endsWith("<CheckDomainResponse><requestId>123</requestId><responseBody>OK</responseBody></CheckDomainResponse>")); - } - - @Test - public void testGetDomain() throws Exception { - String response = template.requestBody("restlet:http://localhost:9000/domainservice/domains/123?restletMethod=GET", null, String.class); - log.info("Response: " + response); - - assertEquals("{www.google.com}", response); - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-cxf", "camel-restlet")); - - return options; - } - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/rss/RssPollingConsumerTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/rss/RssPollingConsumerTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/rss/RssPollingConsumerTest.java deleted file mode 100644 index 680b722..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/rss/RssPollingConsumerTest.java +++ /dev/null @@ -1,85 +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.itest.osgi.rss; - -import java.net.URL; - -import com.sun.syndication.feed.synd.SyndFeed; -import org.apache.camel.CamelException; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.rss.RssConstants; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -@Ignore("abdera-core bundle has a wrong stax api dependency") -public class RssPollingConsumerTest extends OSGiIntegrationTestSupport { - - @Test - public void testGrabbingListOfEntries() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - mock.assertIsSatisfied(); - - Exchange exchange = mock.getExchanges().get(0); - Message in = exchange.getIn(); - assertNotNull(in); - assertTrue(in.getBody() instanceof SyndFeed); - assertTrue(in.getHeader(RssConstants.RSS_FEED) instanceof SyndFeed); - - SyndFeed feed = in.getHeader(RssConstants.RSS_FEED, SyndFeed.class); - assertTrue(feed.getAuthor().contains("Jonathan Anstey")); - - SyndFeed body = in.getBody(SyndFeed.class); - assertEquals(10, body.getEntries().size()); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - // load the resource first - URL url = this.getClass().getResource("/org/apache/camel/itest/osgi/rss/rss20.xml"); - if (url != null) { - from("rss:" + url.toString() + "?splitEntries=false&consumer.delay=100").to("mock:result"); - } else { - throw new CamelException("Can't find the right rss file"); - } - } - }; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-rss")); - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltRouteTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltRouteTest.java deleted file mode 100644 index ef5731f..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltRouteTest.java +++ /dev/null @@ -1,70 +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.itest.osgi.saxon; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - - -@RunWith(PaxExam.class) -public class SaxonXsltRouteTest extends OSGiIntegrationTestSupport { - - @Test - public void testSaxonXsltRoute() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedBodiesReceived("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>"); - mock.message(0).body().isInstanceOf(String.class); - - template.sendBody("direct:start", "<hello>world!</hello>"); - - assertMockEndpointsSatisfied(); - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-saxon")); - - return options; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start") - .to("xslt:org/apache/camel/itest/osgi/core/xslt/example.xsl?saxon=true") - .to("log:result") - .to("mock:result"); - } - }; - } - - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java deleted file mode 100644 index 8521c73..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java +++ /dev/null @@ -1,103 +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.itest.osgi.saxon; - -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - - -@RunWith(PaxExam.class) -public class SaxonXsltTerminateRouteTest extends OSGiIntegrationTestSupport { - - private String data = "<staff>\n" - + "\n" - + " <programmer>\n" - + " <name>Bugs Bunny</name>\n" - + " <dob>03/21/1970</dob>\n" - + " <age>31</age>\n" - + " <address>4895 Wabbit Hole Road</address>\n" - + " <phone>865-111-1111</phone>\n" - + " </programmer>\n" - + "\n" - + " <programmer>\n" - + " <name>Daisy Duck</name>\n" - + " <dob></dob>\n" - + " <age></age>\n" - + " <address>748 Golden Pond</address>\n" - + " <phone>865-222-2222</phone>\n" - + " </programmer>\n" - + "\n" - + "</staff>"; - - @Test - public void testXsltTerminate() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:dead").expectedMessageCount(1); - - template.sendBody("direct:start", data); - - assertMockEndpointsSatisfied(); - - Exchange out = getMockEndpoint("mock:dead").getReceivedExchanges().get(0); - assertNotNull(out); - // this exception is just a generic xslt error - Exception cause = out.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); - assertNotNull(cause); - - // we have the xsl termination message as a error property on the exchange as we set terminate=true - Exception error = out.getProperty(Exchange.XSLT_ERROR, Exception.class); - assertNotNull(error); - assertEquals("Error: DOB is an empty string!", error.getMessage()); - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-saxon")); - - return options; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - errorHandler(deadLetterChannel("mock:dead")); - - from("direct:start") - .to("xslt:org/apache/camel/itest/osgi/core/xslt/terminate.xsl?saxon=true") - .to("log:foo") - .to("mock:result"); - - } - }; - } - - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/GroovyScriptOsgiTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/GroovyScriptOsgiTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/GroovyScriptOsgiTest.java deleted file mode 100644 index ab1535f..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/GroovyScriptOsgiTest.java +++ /dev/null @@ -1,70 +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.itest.osgi.script; - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -/** - * Test camel-script for groovy expressions in OSGi - */ -@RunWith(PaxExam.class) -public class GroovyScriptOsgiTest extends OSGiIntegrationTestSupport { - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("direct:start").setBody().groovy("request.body * 2").to("mock:result"); - } - }; - } - - @Test - public void testLanguage() throws Exception { - getMockEndpoint("mock:result").expectedBodiesReceived(6); - - template.sendBody("direct:start", 3); - - assertMockEndpointsSatisfied(); - } - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - // without this, "groovy.lang.*" classes will be loaded by classloader of camel-spring bundle - context.setApplicationContextClassLoader(this.getClass().getClassLoader()); - return context; - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - loadCamelFeatures("camel-script", "camel-groovy")); - return options; - } - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/RubyOsgiTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/RubyOsgiTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/RubyOsgiTest.java deleted file mode 100644 index 1173e4d..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/script/RubyOsgiTest.java +++ /dev/null @@ -1,65 +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.itest.osgi.script; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - - -/** - * Test camel-script for Ruby expressions in OSGi - */ -@RunWith(PaxExam.class) -public class RubyOsgiTest extends OSGiIntegrationTestSupport { - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("direct:start").setBody().ruby("$request.body + $request.body").to("mock:finish"); - } - }; - } - - @Test - public void testSendMessage() throws Exception { - MockEndpoint mock = getMandatoryEndpoint("mock:finish", MockEndpoint.class); - assertNotNull("The mock endpoint should not be null", mock); - - mock.expectedBodiesReceived("HelloHello"); - template.sendBody("direct:start", "Hello"); - assertMockEndpointsSatisfied(); - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-script", "camel-ruby") - ); - - return options; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java deleted file mode 100644 index d225e64..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java +++ /dev/null @@ -1,65 +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.itest.osgi.servlet; - -import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; -import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class ServletComponentTest extends OSGiIntegrationSpringTestSupport { - - private static final String CONTEXT_PATH = "/org/apache/camel/itest/osgi/servlet/ServletComponentTest-context.xml"; - - @Test - public void testSendMessage() { - String endpointURI = "http://localhost:9080/camel/services/hello"; - String response = template.requestBody(endpointURI, "Hello World", String.class); - assertEquals("Echo Hello World", response); - } - - @Configuration - public static Option[] configure() throws Exception { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // install the war features first - scanFeatures(getKarafFeatureUrl(), "war"), - // set the system property for pax web - KarafDistributionOption.editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", "9080"), - - // using the features to install the camel components - loadCamelFeatures("camel-blueprint", "camel-http", "camel-servlet") - - ); - return options; - } - - @Override - protected OsgiBundleXmlApplicationContext createApplicationContext() { - return new OsgiBundleXmlApplicationContext(new String[] {CONTEXT_PATH}); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java deleted file mode 100644 index 1931287..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java +++ /dev/null @@ -1,33 +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.itest.osgi.servlet; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ServletProcessor implements Processor { - private static final Logger LOG = LoggerFactory.getLogger(ServletProcessor.class); - - public void process(Exchange exchange) throws Exception { - String request = exchange.getIn().getBody(String.class); - LOG.info("*** get the request is " + request); - exchange.getOut().setBody("Echo " + request); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java deleted file mode 100644 index b87d176..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java +++ /dev/null @@ -1,65 +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.itest.osgi.servlet; - -import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; -import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; - -import static org.ops4j.pax.exam.OptionUtils.combine; - -@RunWith(PaxExam.class) -public class ServletServicesTest extends OSGiIntegrationSpringTestSupport { - - @Test - public void testSendMessage() { - String endpointURI = "http://localhost:9080/camel/services/hello"; - String response = template.requestBody(endpointURI, "Hello World", String.class); - assertEquals("Echo Hello World", response); - } - - @Configuration - public static Option[] configure() throws Exception { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // install the war features first - scanFeatures(getKarafFeatureUrl(), "war"), - // set the system property for pax web - KarafDistributionOption.editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", "9080"), - // using the features to install the camel components - scanFeatures(getCamelKarafFeatureUrl(), - "camel-blueprint", "camel-http", "camel-servlet") - - ); - - return options; - } - - @Override - protected OsgiBundleXmlApplicationContext createApplicationContext() { - return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml", - "org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml"}); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java deleted file mode 100644 index 2c9567d..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java +++ /dev/null @@ -1,91 +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.itest.osgi.servlet.support; - -// START SNIPPET: activator -import java.util.Dictionary; -import java.util.Hashtable; - -import org.apache.camel.component.servlet.CamelHttpTransportServlet; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.osgi.context.BundleContextAware; - -public final class ServletActivator implements BundleActivator, BundleContextAware { - private static final Logger LOG = LoggerFactory.getLogger(ServletActivator.class); - private static boolean registerService; - - /** - * HttpService reference. - */ - private ServiceReference<?> httpServiceRef; - - /** - * Called when the OSGi framework starts our bundle - */ - public void start(BundleContext bc) throws Exception { - registerServlet(bc); - } - - /** - * Called when the OSGi framework stops our bundle - */ - public void stop(BundleContext bc) throws Exception { - if (httpServiceRef != null) { - bc.ungetService(httpServiceRef); - httpServiceRef = null; - } - } - - protected void registerServlet(BundleContext bundleContext) throws Exception { - httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName()); - - if (httpServiceRef != null && !registerService) { - LOG.info("Register the servlet service"); - final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef); - if (httpService != null) { - // create a default context to share between registrations - final HttpContext httpContext = httpService.createDefaultHttpContext(); - // register the hello world servlet - final Dictionary<String, String> initParams = new Hashtable<String, String>(); - initParams.put("matchOnUriPrefix", "false"); - initParams.put("servlet-name", "CamelServlet"); - httpService.registerServlet("/camel/services", // alias - new CamelHttpTransportServlet(), // register servlet - initParams, // init params - httpContext // http context - ); - registerService = true; - } - } - } - - public void setBundleContext(BundleContext bc) { - try { - registerServlet(bc); - } catch (Exception e) { - LOG.error("Cannot register the servlet, the reason is " + e); - } - } - -} -// END SNIPPET: activator http://git-wip-us.apache.org/repos/asf/camel/blob/6b77d012/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/shiro/ShiroAuthenticationTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/shiro/ShiroAuthenticationTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/shiro/ShiroAuthenticationTest.java deleted file mode 100644 index 900dc1c2..0000000 --- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/shiro/ShiroAuthenticationTest.java +++ /dev/null @@ -1,133 +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.itest.osgi.shiro; - -import javax.naming.AuthenticationException; - -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.shiro.security.ShiroSecurityPolicy; -import org.apache.camel.component.shiro.security.ShiroSecurityToken; -import org.apache.camel.component.shiro.security.ShiroSecurityTokenInjector; -import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; -import org.apache.shiro.authc.IncorrectCredentialsException; -import org.apache.shiro.authc.LockedAccountException; -import org.apache.shiro.authc.UnknownAccountException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.ops4j.pax.exam.OptionUtils.combine; - - -@RunWith(PaxExam.class) -public class ShiroAuthenticationTest extends OSGiIntegrationTestSupport { - - @EndpointInject(uri = "mock:success") - protected MockEndpoint successEndpoint; - - @EndpointInject(uri = "mock:authenticationException") - protected MockEndpoint failureEndpoint; - - private byte[] passPhrase = { - (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B, - (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F, - (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, - (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17}; - - @Test - public void testShiroAuthenticationFailure() throws Exception { - //Incorrect password - ShiroSecurityToken shiroSecurityToken = new ShiroSecurityToken("ringo", "stirr"); - TestShiroSecurityTokenInjector shiroSecurityTokenInjector = new TestShiroSecurityTokenInjector(shiroSecurityToken, passPhrase); - - successEndpoint.expectedMessageCount(0); - failureEndpoint.expectedMessageCount(1); - - template.send("direct:secureEndpoint", shiroSecurityTokenInjector); - - successEndpoint.assertIsSatisfied(); - failureEndpoint.assertIsSatisfied(); - } - - @Test - public void testSuccessfulShiroAuthenticationWithNoAuthorization() throws Exception { - //Incorrect password - ShiroSecurityToken shiroSecurityToken = new ShiroSecurityToken("ringo", "starr"); - TestShiroSecurityTokenInjector shiroSecurityTokenInjector = new TestShiroSecurityTokenInjector(shiroSecurityToken, passPhrase); - - successEndpoint.expectedMessageCount(1); - failureEndpoint.expectedMessageCount(0); - - template.send("direct:secureEndpoint", shiroSecurityTokenInjector); - - successEndpoint.assertIsSatisfied(); - failureEndpoint.assertIsSatisfied(); - } - - @Configuration - public static Option[] configure() { - Option[] options = combine( - getDefaultCamelKarafOptions(), - // using the features to install the other camel components - loadCamelFeatures("camel-shiro")); - - return options; - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - - final ShiroSecurityPolicy securityPolicy = new ShiroSecurityPolicy("classpath:/org/apache/camel/itest/osgi/shiro/securityconfig.ini", passPhrase); - - onException(UnknownAccountException.class). - to("mock:authenticationException"); - onException(IncorrectCredentialsException.class). - to("mock:authenticationException"); - onException(LockedAccountException.class). - to("mock:authenticationException"); - onException(AuthenticationException.class). - to("mock:authenticationException"); - - from("direct:secureEndpoint"). - to("log:incoming payload"). - policy(securityPolicy). - to("mock:success"); - } - }; - } - - - private static class TestShiroSecurityTokenInjector extends ShiroSecurityTokenInjector { - - public TestShiroSecurityTokenInjector( - ShiroSecurityToken shiroSecurityToken, byte[] bytes) { - super(shiroSecurityToken, bytes); - } - - public void process(Exchange exchange) throws Exception { - exchange.getIn().setHeader("SHIRO_SECURITY_TOKEN", encrypt()); - exchange.getIn().setBody("Beatle Mania"); - } - } - -}