@Test public void testSetPropertiesWithBadUriOptionCausesFail() throws Exception { JmsConnectionFactory cf = new JmsConnectionFactory(); Map<String, String> props = new HashMap<String, String>(); props.put("remoteURI", "amqp://localhost:1234?jms.badOption=true"); try { cf.setProperties(props); fail("Should have thrown exception"); } catch (IllegalArgumentException iae) { // expected } }
@Test public void testSetProperties() throws Exception { String clientID = getTestName(); String queuePrefix = "q:"; String jmsOptionPrefix = "jms."; String baseUri = "amqp://localhost:1234"; String uri = baseUri + "?" + jmsOptionPrefix + CLIENT_ID_PROP + "=" + clientID; // Create a connection factory object JmsConnectionFactory cf = new JmsConnectionFactory(); // Verify the outcome conditions have not been met already assertNotEquals("value should not match yet", clientID, cf.getClientID()); assertNotEquals("value should not match yet", queuePrefix, cf.getQueuePrefix()); assertNotEquals("value should not match yet", baseUri, cf.getRemoteURI()); // Set the properties Map<String, String> props = new HashMap<String, String>(); // Add the URI property, itself containing a property option in its query props.put("remoteURI", uri); // Add another property directly props.put("queuePrefix", queuePrefix); Map<String, String> unusedProps = cf.setProperties(props); // Verify the clientID property option from the URI was applied. assertEquals("uri property query option not applied as expected", clientID, cf.getClientID()); // Verify the direct property was applied assertEquals("direct property not applied as expected", queuePrefix, cf.getQueuePrefix()); // Verify the URI was filtered to remove the applied options assertEquals( "URI was filtered to remove options that were applied", baseUri, cf.getRemoteURI()); // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); try { unusedProps.put("a", "b"); fail("Map should be unmodifiable"); } catch (UnsupportedOperationException uoe) { // expected } }
@Test public void testSetPropertiesWithUnusedOptions() throws Exception { String uri = "amqp://localhost:1234"; String unusedKey = "unusedKey"; String unusedValue = "unusedValue"; // Create a connection factory object JmsConnectionFactory cf = new JmsConnectionFactory(); // Verify the outcome conditions have not been met already assertNotEquals("value should not match yet", uri, cf.getRemoteURI()); // Set the properties Map<String, String> props = new HashMap<String, String>(); // Add a property that will get used props.put("remoteURI", uri); // Add a property that wont get used props.put(unusedKey, unusedValue); Map<String, String> unusedProps = cf.setProperties(props); // Verify the URI property was applied. assertEquals("uri property option not applied as expected", uri, cf.getRemoteURI()); // Verify that the unused property was returned assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue( "Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); // Verify the returned map was unmodifiable try { unusedProps.put("a", "b"); fail("Map should be unmodifiable"); } catch (UnsupportedOperationException uoe) { // expected } }