add broker nd webconsole round trip itest

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1441459 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2013-02-01 14:27:56 +00:00
parent e20234e2cb
commit 964f8ca375
4 changed files with 117 additions and 10 deletions

View File

@ -157,10 +157,18 @@ public abstract class AbstractFeatureTest {
}
public static Option[] configureBrokerStart(Option[] existingOptions) {
existingOptions = append(
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg")),
existingOptions);
return append(
replaceConfigurationFile("etc/activemq.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq.xml")),
existingOptions);
}
public static Option[] append(Option toAdd, Option[] existingOptions) {
ArrayList<Option> newOptions = new ArrayList<Option>();
newOptions.addAll(Arrays.asList(existingOptions));
newOptions.add(replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg")));
newOptions.add(replaceConfigurationFile("etc/activemq.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq.xml")));
newOptions.add(toAdd);
return newOptions.toArray(new Option[]{});
}

View File

@ -41,8 +41,6 @@ public class ActiveMQBrokerFeatureTest extends AbstractFeatureTest {
@Test
public void test() throws Throwable {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
factory.getBrokerURL();
withinReason(new Callable<Boolean>() {
@Override
@ -63,15 +61,29 @@ public class ActiveMQBrokerFeatureTest extends AbstractFeatureTest {
// produce and consume
final String nameAndPayload = String.valueOf(System.currentTimeMillis());
produceMessage(nameAndPayload);
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));
MessageConsumer consumer = session.createConsumer(session.createQueue(nameAndPayload));
TextMessage message = (TextMessage) consumer.receive(4000);
System.err.println("message: " + message);
assertEquals("got our message", nameAndPayload, message.getText());
connection.close();
}
}

View File

@ -0,0 +1,87 @@
/**
* 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.util.concurrent.TimeUnit;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
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;
@RunWith(JUnit4TestRunner.class)
public class ActiveMQBrokerNdWebConsoleFeatureTest extends ActiveMQBrokerFeatureTest {
static final String WEB_CONSOLE_URL = "http://localhost:8181/activemqweb/";
@Configuration
public static Option[] configure() {
return append(CoreOptions.mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
append(CoreOptions.mavenBundle("commons-httpclient", "commons-httpclient").versionAsInProject(),
configureBrokerStart(configure("activemq-broker", "activemq-web-console"))));
}
@Override
protected void produceMessage(String nameAndPayload) throws Exception {
HttpClient client = new HttpClient();
System.err.println("attempting publish via web console..");
// set credentials
client.getState().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(USER, PASSWORD)
);
// need to first get the secret
GetMethod get = new GetMethod(WEB_CONSOLE_URL + "send.jsp");
get.setDoAuthentication(true);
// Give console some time to start
for (int i=0; i<20; i++) {
TimeUnit.SECONDS.sleep(1);
try {
i = client.executeMethod(get);
} catch (java.net.ConnectException ignored) {}
}
assertEquals("get succeeded on " + get, 200, get.getStatusCode());
String response = get.getResponseBodyAsString();
final String secretMarker = "<input type=\"hidden\" name=\"secret\" value=\"";
String secret = response.substring(response.indexOf(secretMarker) + secretMarker.length());
secret = secret.substring(0, secret.indexOf("\"/>"));
PostMethod post = new PostMethod(WEB_CONSOLE_URL + "sendMessage.action");
post.setDoAuthentication(true);
post.addParameter("secret", secret);
post.addParameter("JMSText", nameAndPayload);
post.addParameter("JMSDestination", nameAndPayload);
post.addParameter("JMSDestinationType", "queue");
// execute the send
assertEquals("post succeeded, " + post, 302, client.executeMethod(post));
}
}

View File

@ -73,7 +73,7 @@ public class OsgiConfiguration extends AbstractConfiguration implements ManagedS
@Override
public void updated(Dictionary dictionary) throws ConfigurationException {
jmxUrl = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_URL);
jmxUrl = dictionary != null ? (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_URL) : null;
if (jmxUrl == null) {
throw new IllegalArgumentException("A JMS-url must be specified (system property " + SystemPropertiesConfiguration.PROPERTY_JMX_URL);
}