NO-JIRA add user/pass as part of junit rule

This commit is contained in:
Mohammad Naghavi 2018-03-29 23:19:46 +02:00 committed by Justin Bertram
parent c2c2ce0a47
commit 407f63cf3a
4 changed files with 83 additions and 13 deletions

View File

@ -37,6 +37,14 @@ public abstract class AbstractActiveMQClientResource extends ExternalResource {
ServerLocator serverLocator; ServerLocator serverLocator;
ClientSessionFactory sessionFactory; ClientSessionFactory sessionFactory;
ClientSession session; ClientSession session;
String username;
String password;
public AbstractActiveMQClientResource(String url, String username, String password) {
this(url);
this.username = username;
this.password = password;
}
public AbstractActiveMQClientResource(String url) { public AbstractActiveMQClientResource(String url) {
if (url == null) { if (url == null) {
@ -50,6 +58,12 @@ public abstract class AbstractActiveMQClientResource extends ExternalResource {
} }
} }
public AbstractActiveMQClientResource(ServerLocator serverLocator, String username, String password) {
this(serverLocator);
this.username = username;
this.password = password;
}
public AbstractActiveMQClientResource(ServerLocator serverLocator) { public AbstractActiveMQClientResource(ServerLocator serverLocator) {
if (serverLocator == null) { if (serverLocator == null) {
throw new IllegalArgumentException(String.format("Error creating %s - ServerLocator cannot be null", this.getClass().getSimpleName())); throw new IllegalArgumentException(String.format("Error creating %s - ServerLocator cannot be null", this.getClass().getSimpleName()));
@ -88,7 +102,7 @@ public abstract class AbstractActiveMQClientResource extends ExternalResource {
log.info("Starting {}", this.getClass().getSimpleName()); log.info("Starting {}", this.getClass().getSimpleName());
try { try {
sessionFactory = serverLocator.createSessionFactory(); sessionFactory = serverLocator.createSessionFactory();
session = sessionFactory.createSession(); session = sessionFactory.createSession(username, password, false, true, true, serverLocator.isPreAcknowledge(), serverLocator.getAckBatchSize());
} catch (RuntimeException runtimeEx) { } catch (RuntimeException runtimeEx) {
throw runtimeEx; throw runtimeEx;
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -50,21 +50,37 @@ public class ActiveMQConsumerResource extends AbstractActiveMQClientResource {
ClientConsumer consumer; ClientConsumer consumer;
public ActiveMQConsumerResource(String url, String queueName) { public ActiveMQConsumerResource(String url, String queueName) {
this(url, SimpleString.toSimpleString(queueName)); this(url, SimpleString.toSimpleString(queueName), null, null);
}
public ActiveMQConsumerResource(String url, String queueName, String username, String password) {
this(url, SimpleString.toSimpleString(queueName), username, password);
}
public ActiveMQConsumerResource(String url, SimpleString queueName, String username, String password) {
super(url, username, password);
this.queueName = queueName;
} }
public ActiveMQConsumerResource(String url, SimpleString queueName) { public ActiveMQConsumerResource(String url, SimpleString queueName) {
super(url); this(url, queueName, null, null);
this.queueName = queueName; }
public ActiveMQConsumerResource(ServerLocator serverLocator, String queueName, String username, String password) {
this(serverLocator, SimpleString.toSimpleString(queueName), username, password);
} }
public ActiveMQConsumerResource(ServerLocator serverLocator, String queueName) { public ActiveMQConsumerResource(ServerLocator serverLocator, String queueName) {
this(serverLocator, SimpleString.toSimpleString(queueName)); this(serverLocator, SimpleString.toSimpleString(queueName), null, null);
}
public ActiveMQConsumerResource(ServerLocator serverLocator, SimpleString queueName, String username, String password) {
super(serverLocator, username, password);
this.queueName = queueName;
} }
public ActiveMQConsumerResource(ServerLocator serverLocator, SimpleString queueName) { public ActiveMQConsumerResource(ServerLocator serverLocator, SimpleString queueName) {
super(serverLocator); this(serverLocator, queueName, null, null);
this.queueName = queueName;
} }
public long getDefaultReceiveTimeout() { public long getDefaultReceiveTimeout() {

View File

@ -44,18 +44,34 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator;
*/ */
public class ActiveMQDynamicProducerResource extends ActiveMQProducerResource { public class ActiveMQDynamicProducerResource extends ActiveMQProducerResource {
public ActiveMQDynamicProducerResource(String url, String username, String password) {
super(url, username, password);
}
public ActiveMQDynamicProducerResource(String url) { public ActiveMQDynamicProducerResource(String url) {
super(url); super(url);
} }
public ActiveMQDynamicProducerResource(ServerLocator serverLocator, String username, String password) {
super(serverLocator, username, password);
}
public ActiveMQDynamicProducerResource(ServerLocator serverLocator) { public ActiveMQDynamicProducerResource(ServerLocator serverLocator) {
super(serverLocator); super(serverLocator);
} }
public ActiveMQDynamicProducerResource(String url, SimpleString address, String username, String password) {
super(url, address, username, password);
}
public ActiveMQDynamicProducerResource(String url, SimpleString address) { public ActiveMQDynamicProducerResource(String url, SimpleString address) {
super(url, address); super(url, address);
} }
public ActiveMQDynamicProducerResource(ServerLocator serverLocator, SimpleString address, String username, String password) {
super(serverLocator, address, username, password);
}
public ActiveMQDynamicProducerResource(ServerLocator serverLocator, SimpleString address) { public ActiveMQDynamicProducerResource(ServerLocator serverLocator, SimpleString address) {
super(serverLocator, address); super(serverLocator, address);
} }

View File

@ -49,38 +49,62 @@ public class ActiveMQProducerResource extends AbstractActiveMQClientResource {
SimpleString address = null; SimpleString address = null;
ClientProducer producer; ClientProducer producer;
protected ActiveMQProducerResource(String url, String username, String password) {
super(url, username, password);
}
protected ActiveMQProducerResource(String url) { protected ActiveMQProducerResource(String url) {
super(url); super(url);
} }
protected ActiveMQProducerResource(ServerLocator serverLocator, String username, String password) {
super(serverLocator, username, password);
}
protected ActiveMQProducerResource(ServerLocator serverLocator) { protected ActiveMQProducerResource(ServerLocator serverLocator) {
super(serverLocator); super(serverLocator);
} }
public ActiveMQProducerResource(String url, String address) { public ActiveMQProducerResource(String url, String address, String username, String password) {
this(url, SimpleString.toSimpleString(address)); this(url, SimpleString.toSimpleString(address), username, password);
} }
public ActiveMQProducerResource(String url, SimpleString address) { public ActiveMQProducerResource(String url, String address) {
super(url); this(url, address, null, null);
}
public ActiveMQProducerResource(String url, SimpleString address, String username, String password) {
super(url, username, password);
if (address == null) { if (address == null) {
throw new IllegalArgumentException(String.format("%s construction error - address cannot be null", this.getClass().getSimpleName())); throw new IllegalArgumentException(String.format("%s construction error - address cannot be null", this.getClass().getSimpleName()));
} }
this.address = address; this.address = address;
} }
public ActiveMQProducerResource(String url, SimpleString address) {
this(url, address, null, null);
}
public ActiveMQProducerResource(ServerLocator serverLocator, String address, String username, String password) {
this(serverLocator, SimpleString.toSimpleString(address), username, password);
}
public ActiveMQProducerResource(ServerLocator serverLocator, String address) { public ActiveMQProducerResource(ServerLocator serverLocator, String address) {
this(serverLocator, SimpleString.toSimpleString(address)); this(serverLocator, SimpleString.toSimpleString(address));
} }
public ActiveMQProducerResource(ServerLocator serverLocator, SimpleString address) { public ActiveMQProducerResource(ServerLocator serverLocator, SimpleString address, String username, String password) {
super(serverLocator); super(serverLocator, username, password);
if (address == null) { if (address == null) {
throw new IllegalArgumentException(String.format("%s construction error - address cannot be null", this.getClass().getSimpleName())); throw new IllegalArgumentException(String.format("%s construction error - address cannot be null", this.getClass().getSimpleName()));
} }
this.address = address; this.address = address;
} }
public ActiveMQProducerResource(ServerLocator serverLocator, SimpleString address) {
this(serverLocator, address, null, null);
}
public boolean isUseDurableMessage() { public boolean isUseDurableMessage() {
return useDurableMessage; return useDurableMessage;
} }