@Test
public void testInvalidProperties() throws Exception {
// Null properties
try {
new JMSManager(null);
fail("Creating a JMSManager with null properties " +
"should throw an exception");
} catch(MessagingException expected) {
assertTrue(expected.getMessage().contains("properties"));
}
// Missing all properties
properties = new Properties();
try {
new JMSManager(properties);
fail("Creating a JMSManager with no properties " +
"should throw an exception");
} catch(MessagingException expected) {
assertTrue(expected.getMessage().contains(Context.INITIAL_CONTEXT_FACTORY));
}
// Missing provider url property
properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
"ConnectionFactory");
try {
new JMSManager(properties);
fail("Creating a JMSManager with no provider url " +
"property should throw an exception");
} catch(MessagingException expected) {
assertTrue(expected.getMessage().contains(Context.PROVIDER_URL));
}
// Missing initial context factory property
properties = new Properties();
properties.setProperty(Context.PROVIDER_URL,
"vm://localhost");
properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
"ConnectionFactory");
try {
new JMSManager(properties);
fail("Creating a JMSManager with no initial context factory " +
"property should throw an exception");
} catch(MessagingException expected) {
assertTrue(expected.getMessage().contains(Context.INITIAL_CONTEXT_FACTORY));
}
// Invalid initial context factory
properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"test.InvalidInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,
"vm://localhost");
properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
"ConnectionFactory");
try {
new JMSManager(properties);
fail("Starting a JMSManager with an invalid initial " +
"context factory should throw an exception");
} catch(MessagingException expected) {}
// Invalid provider url
properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,
"tcp://localhost:00000");
properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
"ConnectionFactory");
try {
new JMSManager(properties);
fail("Starting a JMSManager with an invalid " +
"provider url should throw an exception");
} catch(MessagingException expected) {}
}