https://issues.apache.org/jira/browse/AMQ-4432 - validate camel spring route to deploy directory

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1464068 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2013-04-03 15:20:06 +00:00
parent ef6beb78fe
commit 14a93811c6
6 changed files with 177 additions and 56 deletions

View File

@ -0,0 +1,47 @@
/**
* 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.activemq.karaf.itest;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public abstract class AbstractJmsFeatureTest extends AbstractFeatureTest {
protected String consumeMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(nameAndPayload));
TextMessage message = (TextMessage) consumer.receive(10000);
System.err.println("message: " + message);
connection.close();
return message.getText();
}
protected void produceMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createProducer(session.createQueue(nameAndPayload)).send(session.createTextMessage(nameAndPayload));
connection.close();
}
}

View File

@ -17,11 +17,6 @@
package org.apache.activemq.karaf.itest;
import java.util.concurrent.Callable;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@ -32,7 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(JUnit4TestRunner.class)
public class ActiveMQBrokerFeatureTest extends AbstractFeatureTest {
public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
@ -68,25 +63,4 @@ public class ActiveMQBrokerFeatureTest extends AbstractFeatureTest {
assertEquals("got our message", nameAndPayload, consumeMessage(nameAndPayload));
}
protected String consumeMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(USER,PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(nameAndPayload));
TextMessage message = (TextMessage) consumer.receive(4000);
System.err.println("message: " + message);
connection.close();
return message.getText();
}
protected void produceMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(USER,PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createProducer(session.createQueue(nameAndPayload)).send(session.createTextMessage(nameAndPayload));
connection.close();
}
}

View File

@ -17,11 +17,6 @@
package org.apache.activemq.karaf.itest;
import java.util.concurrent.Callable;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.MavenUtils;
@ -32,11 +27,10 @@ import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.CoreOptions.scanFeatures;
@RunWith(JUnit4TestRunner.class)
public class ActiveMQBrokerNdCamelFeatureTest extends AbstractFeatureTest {
public class ActiveMQBrokerNdCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
@ -74,26 +68,4 @@ public class ActiveMQBrokerNdCamelFeatureTest extends AbstractFeatureTest {
produceMessage("camel_in");
assertEquals("got our message", "camel_in", consumeMessage("camel_out"));
}
protected String consumeMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(USER,PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(nameAndPayload));
TextMessage message = (TextMessage) consumer.receive(10000);
System.err.println("message: " + message);
connection.close();
return message.getText();
}
protected void produceMessage(String nameAndPayload) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(USER,PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createProducer(session.createQueue(nameAndPayload)).send(session.createTextMessage(nameAndPayload));
connection.close();
}
}

View File

@ -0,0 +1,77 @@
/**
* 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.activemq.karaf.itest;
import java.io.File;
import java.util.concurrent.Callable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import static org.ops4j.pax.exam.CoreOptions.scanFeatures;
@RunWith(JUnit4TestRunner.class)
public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
Option[] baseOptions = append(
replaceConfigurationFile("deploy/camel.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/camel.xml")),
configure("activemq"));
return configureBrokerStart(append(scanFeatures(getCamelFeatureUrl(
MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")
), "activemq-camel"), baseOptions));
}
@Test
public void test() throws Throwable {
System.err.println(executeCommand("features:list").trim());
System.err.println(executeCommand("osgi:ls").trim());
System.err.println(executeCommand("osgi:list").trim());
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
}
});
System.err.println(executeCommand("activemq:bstat").trim());
// produce and consume
final String nameAndPayload = String.valueOf(System.currentTimeMillis());
produceMessage("camel_in");
assertEquals("got our message", "camel_in", consumeMessage("camel_out"));
}
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.karaf.itest;
import javax.jms.Destination;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.MavenUtils;

View File

@ -0,0 +1,50 @@
<!--
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.
-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616?jms.dispatchAsync=false"/>
<property name="userName" value="karaf" />
<property name="password" value="karaf" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.XaPooledConnectionFactory">
<property name="connectionFactory" ref="activemqConnectionFactory"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"
depends-on="pooledConnectionFactory">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="cacheLevel" value="0"/>
</bean>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="queueToDbTransacted">
<from uri="activemq:queue:camel_in"/>
<to uri="activemq:queue:camel_out"/>
</route>
</camelContext>
</beans>