Skip to content

Commit

Permalink
update tests that were using HornetQ API to Artemis
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesnil committed Jun 26, 2015
1 parent e65201a commit 774d512
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 110 deletions.
Expand Up @@ -86,7 +86,7 @@ public void setup() throws Exception {
ejbJar.addPackage(BEAN_PACKAGE); ejbJar.addPackage(BEAN_PACKAGE);
ejbJar.setManifest(new StringAsset( ejbJar.setManifest(new StringAsset(
Descriptors.create(ManifestDescriptor.class) Descriptors.create(ManifestDescriptor.class)
.attribute("Dependencies", "org.hornetq.ra") .attribute("Dependencies", "org.apache.activemq.artemis.ra")
.exportAsString())); .exportAsString()));
EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, DEPLOYMENT_NAME); EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, DEPLOYMENT_NAME);
earArchive.addAsModule(ejbJar); earArchive.addAsModule(ejbJar);
Expand Down
Expand Up @@ -84,13 +84,7 @@ public void testWriteDiscoveryGroupAttributeWhenConnectorIsAlreadyDefined() thro
e.printStackTrace(); e.printStackTrace();
assertEquals(FAILED, e.getResult().get(OUTCOME).asString()); assertEquals(FAILED, e.getResult().get(OUTCOME).asString());
assertEquals(true, e.getResult().get(ROLLED_BACK).asBoolean()); assertEquals(true, e.getResult().get(ROLLED_BACK).asBoolean());
final String errorCode; assertTrue(e.getResult().get(FAILURE_DESCRIPTION).asString().contains("WFLYMSGAMQ0019"));
if ("hornetq".equals(jmsOperations.getProviderName())) {
errorCode = "WFLYMSG0019";
} else {
errorCode = "WFLYMSGAMQ0019";
}
assertTrue(e.getResult().get(FAILURE_DESCRIPTION).asString().contains(errorCode));
} }


jmsOperations.removeJmsConnectionFactory(CF_NAME); jmsOperations.removeJmsConnectionFactory(CF_NAME);
Expand Down
Expand Up @@ -32,33 +32,30 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;


import org.hornetq.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.hornetq.api.core.client.ClientProducer; import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.hornetq.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.hornetq.api.core.client.HornetQClient; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.hornetq.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.hornetq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType; import org.jboss.dmr.ModelType;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


/** /**
* Tests the management API for HornetQ core queues. * Tests the management API for Artemis core queues.
* *
* @author Brian Stansberry (c) 2011 Red Hat Inc. * @author Brian Stansberry (c) 2011 Red Hat Inc.
*/ */
Expand All @@ -78,9 +75,6 @@ public class CoreQueueManagementTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {


JMSOperations jmsOperations = JMSOperationsProvider.getInstance(managementClient);
Assume.assumeTrue("Test is relevant only when the messaging subsystem with HornetQ is setup", "hornetq".equals(jmsOperations.getProviderName()));

count++; count++;


HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, Object> map = new HashMap<String, Object>();
Expand All @@ -90,7 +84,7 @@ public void setup() throws Exception {
map.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor"); map.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor");
TransportConfiguration transportConfiguration = TransportConfiguration transportConfiguration =
new TransportConfiguration(NettyConnectorFactory.class.getName(), map); new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(transportConfiguration); ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
locator.setBlockOnDurableSend(true); locator.setBlockOnDurableSend(true);
locator.setBlockOnNonDurableSend(true); locator.setBlockOnNonDurableSend(true);
sessionFactory = locator.createSessionFactory(); sessionFactory = locator.createSessionFactory();
Expand Down Expand Up @@ -370,16 +364,16 @@ public void testListConsumers() throws Exception {


private ModelNode getQueueOperation(String operationName, String queueName) { private ModelNode getQueueOperation(String operationName, String queueName) {
final ModelNode address = new ModelNode(); final ModelNode address = new ModelNode();
address.add("subsystem", "messaging"); address.add("subsystem", "messaging-activemq");
address.add("hornetq-server", "default"); address.add("server", "default");
address.add("queue", queueName); address.add("queue", queueName);
return org.jboss.as.controller.operations.common.Util.getEmptyOperation(operationName, address); return org.jboss.as.controller.operations.common.Util.getEmptyOperation(operationName, address);
} }


private ModelNode getRuntimeQueueOperation(String operationName, String queueName) { private ModelNode getRuntimeQueueOperation(String operationName, String queueName) {
final ModelNode address = new ModelNode(); final ModelNode address = new ModelNode();
address.add("subsystem", "messaging"); address.add("subsystem", "messaging-activemq");
address.add("hornetq-server", "default"); address.add("server", "default");
address.add("runtime-queue", queueName); address.add("runtime-queue", queueName);
return org.jboss.as.controller.operations.common.Util.getEmptyOperation(operationName, address); return org.jboss.as.controller.operations.common.Util.getEmptyOperation(operationName, address);
} }
Expand Down
Expand Up @@ -27,32 +27,24 @@
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;


import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.hornetq.api.config.HornetQDefaultConfiguration; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.hornetq.api.core.HornetQException; import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.hornetq.api.core.HornetQExceptionType; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
import org.hornetq.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientConsumer; import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.hornetq.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.hornetq.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.hornetq.api.core.client.HornetQClient; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.hornetq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.hornetq.core.security.CheckType; import org.apache.activemq.artemis.core.security.CheckType;
import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.dmr.ModelNode;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


Expand All @@ -68,21 +60,15 @@ public class SecurityTestCase {
@ContainerResource @ContainerResource
private ManagementClient managementClient; private ManagementClient managementClient;


@Before
public void setUp() {
JMSOperations jmsOperations = JMSOperationsProvider.getInstance(managementClient);
Assume.assumeTrue("Test is relevant only when the messaging subsystem with HornetQ is setup", "hornetq".equals(jmsOperations.getProviderName()));
}

@Test @Test
public void testFailedAuthenticationBadUserPass() throws Exception { public void testFailedAuthenticationBadUserPass() throws Exception {
final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort()); final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort());
try { try {
sf.createSession("fail", "epicfail", false, true, true, false, 1); sf.createSession("fail", "epicfail", false, true, true, false, 1);
fail("must not allow to create a session with bad authentication"); fail("must not allow to create a session with bad authentication");
} catch (HornetQException e) { } catch (ActiveMQException e) {
assertEquals(HornetQExceptionType.SECURITY_EXCEPTION, e.getType()); assertEquals(ActiveMQExceptionType.SECURITY_EXCEPTION, e.getType());
assertTrue(e.getMessage().startsWith("HQ119031")); assertTrue(e.getMessage(), e.getMessage().startsWith("AMQ119031"));
} finally { } finally {
if (sf != null) { if (sf != null) {
sf.close(); sf.close();
Expand All @@ -96,9 +82,9 @@ public void testFailedAuthenticationBlankUserPass() throws Exception {
try { try {
sf.createSession(); sf.createSession();
fail("must not allow to create a session without any authentication"); fail("must not allow to create a session without any authentication");
} catch (HornetQException e) { } catch (ActiveMQException e) {
assertEquals(HornetQExceptionType.SECURITY_EXCEPTION, e.getType()); assertEquals(ActiveMQExceptionType.SECURITY_EXCEPTION, e.getType());
assertTrue(e.getMessage().startsWith("HQ119031")); assertTrue(e.getMessage(), e.getMessage().startsWith("AMQ119031"));
} finally { } finally {
if (sf != null) { if (sf != null) {
sf.close(); sf.close();
Expand All @@ -110,11 +96,11 @@ public void testFailedAuthenticationBlankUserPass() throws Exception {
public void testDefaultClusterUser() throws Exception { public void testDefaultClusterUser() throws Exception {
final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort()); final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort());
try { try {
sf.createSession(HornetQDefaultConfiguration.getDefaultClusterUser(), HornetQDefaultConfiguration.getDefaultClusterPassword(), false, true, true, false, 1); sf.createSession(ActiveMQDefaultConfiguration.getDefaultClusterUser(), ActiveMQDefaultConfiguration.getDefaultClusterPassword(), false, true, true, false, 1);
fail("must not allow to create a session with the default cluster user credentials"); fail("must not allow to create a session with the default cluster user credentials");
} catch (HornetQException e) { } catch (ActiveMQException e) {
assertEquals(HornetQExceptionType.CLUSTER_SECURITY_EXCEPTION, e.getType()); assertEquals(ActiveMQExceptionType.CLUSTER_SECURITY_EXCEPTION, e.getType());
assertTrue(e.getMessage().startsWith("HQ119099")); assertTrue(e.getMessage(), e.getMessage().startsWith("AMQ119099"));
} finally { } finally {
if (sf != null) { if (sf != null) {
sf.close(); sf.close();
Expand Down Expand Up @@ -168,9 +154,9 @@ public void testUnsuccessfulAuthorization() throws Exception {
session = sf.createSession("guest", "guest", false, true, true, false, 1); session = sf.createSession("guest", "guest", false, true, true, false, 1);
session.createQueue(queueName, queueName, true); session.createQueue(queueName, queueName, true);
fail("Must not create a durable queue without the CREATE_DURABLE_QUEUE permission"); fail("Must not create a durable queue without the CREATE_DURABLE_QUEUE permission");
} catch (HornetQException e) { } catch (ActiveMQException e) {
assertEquals(HornetQExceptionType.SECURITY_EXCEPTION, e.getType()); assertEquals(ActiveMQExceptionType.SECURITY_EXCEPTION, e.getType());
assertTrue(e.getMessage().startsWith("HQ119032")); assertTrue(e.getMessage().startsWith("AMQ119032"));
assertTrue(e.getMessage().contains(CheckType.CREATE_DURABLE_QUEUE.toString())); assertTrue(e.getMessage().contains(CheckType.CREATE_DURABLE_QUEUE.toString()));
} finally { } finally {
if (session != null) { if (session != null) {
Expand All @@ -179,26 +165,13 @@ public void testUnsuccessfulAuthorization() throws Exception {
} }
} }


static void applyUpdate(ModelNode update, final ModelControllerClient client) throws IOException {
ModelNode result = client.execute(new OperationBuilder(update).build());
if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
if (result.hasDefined("result")) {
System.out.println(result.get("result"));
}
} else if (result.hasDefined("failure-description")) {
throw new RuntimeException(result.get("failure-description").toString());
} else {
throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
}
}

static ClientSessionFactory createClientSessionFactory(String host, int port) throws Exception { static ClientSessionFactory createClientSessionFactory(String host, int port) throws Exception {
final Map<String, Object> properties = new HashMap<String, Object>(); final Map<String, Object> properties = new HashMap<String, Object>();
properties.put("host", host); properties.put("host", host);
properties.put("port", port); properties.put("port", port);
properties.put(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME, true); properties.put(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME, true);
properties.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor"); properties.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor");
final TransportConfiguration configuration = new TransportConfiguration(NettyConnectorFactory.class.getName(), properties); final TransportConfiguration configuration = new TransportConfiguration(NettyConnectorFactory.class.getName(), properties);
return HornetQClient.createServerLocatorWithoutHA(configuration).createSessionFactory(); return ActiveMQClient.createServerLocatorWithoutHA(configuration).createSessionFactory();
} }
} }
Expand Up @@ -24,34 +24,31 @@


import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;


import javax.resource.spi.IllegalStateException;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.hornetq.api.core.HornetQException; import javax.resource.spi.IllegalStateException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.hornetq.api.core.client.ClientConsumer; import org.apache.activemq.artemis.api.core.SimpleString;
import org.hornetq.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientProducer; import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.hornetq.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.hornetq.api.core.client.ClientSession.QueueQuery; import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.hornetq.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.hornetq.api.core.client.HornetQClient; import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.hornetq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
Expand All @@ -69,12 +66,6 @@ public class MessagingClientTestCase {
@ContainerResource @ContainerResource
private ManagementClient managementClient; private ManagementClient managementClient;


@Before
public void before() {
Assume.assumeTrue("Test is relevant only when the messaging subsystem with HornetQ is setup",
"hornetq".equals(JMSOperationsProvider.getInstance(managementClient).getProviderName()));
}

@Ignore @Ignore
@Test @Test
public void testMessagingClientUsingMessagingPort() throws Exception { public void testMessagingClientUsingMessagingPort() throws Exception {
Expand Down Expand Up @@ -110,8 +101,8 @@ private void doMessagingClient(ClientSessionFactory sf) throws Exception {
// Create a new core queue using the standalone client // Create a new core queue using the standalone client
ModelNode op = new ModelNode(); ModelNode op = new ModelNode();
op.get("operation").set("add"); op.get("operation").set("add");
op.get("address").add("subsystem", "messaging"); op.get("address").add("subsystem", "messaging-activemq");
op.get("address").add("hornetq-server", "default"); op.get("address").add("server", "default");
op.get("address").add("queue", queueName); op.get("address").add("queue", queueName);
op.get("queue-address").set(queueName); op.get("queue-address").set(queueName);
applyUpdate(op, client); applyUpdate(op, client);
Expand Down Expand Up @@ -144,8 +135,8 @@ private void doMessagingClient(ClientSessionFactory sf) throws Exception {


op = new ModelNode(); op = new ModelNode();
op.get("operation").set("remove"); op.get("operation").set("remove");
op.get("address").add("subsystem", "messaging"); op.get("address").add("subsystem", "messaging-activemq");
op.get("address").add("hornetq-server", "default"); op.get("address").add("server", "default");
op.get("address").add("queue", queueName); op.get("address").add("queue", queueName);
applyUpdate(op, client); applyUpdate(op, client);


Expand All @@ -168,10 +159,10 @@ static void applyUpdate(ModelNode update, final ModelControllerClient client) th
} }
} }


static boolean queueExists(final String queueName, final ClientSessionFactory sf) throws HornetQException { static boolean queueExists(final String queueName, final ClientSessionFactory sf) throws ActiveMQException {
final ClientSession session = sf.createSession("guest", "guest", false, false, false, false, 1); final ClientSession session = sf.createSession("guest", "guest", false, false, false, false, 1);
try { try {
final QueueQuery query = session.queueQuery(new SimpleString(queueName)); final ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
return query.isExists(); return query.isExists();
} finally { } finally {
session.close(); session.close();
Expand All @@ -187,7 +178,7 @@ static ClientSessionFactory createClientSessionFactory(String host, int port, bo
properties.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor"); properties.put(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, "http-acceptor");
} }
final TransportConfiguration configuration = new TransportConfiguration(NettyConnectorFactory.class.getName(), properties); final TransportConfiguration configuration = new TransportConfiguration(NettyConnectorFactory.class.getName(), properties);
return HornetQClient.createServerLocatorWithoutHA(configuration).createSessionFactory(); return ActiveMQClient.createServerLocatorWithoutHA(configuration).createSessionFactory();
} }


} }

0 comments on commit 774d512

Please sign in to comment.