if (subscriberConnection.getClientID() == null) assertEquals("testSetClientID_1", subscriberConnection.getClientID()); assertTrue(subscriberConnection.getClientID() != null);
local_addr = new JMSAddress(connection.getClientID(), false); mcast_addr = new JMSAddress(topicName, true);
if (subscriberConnection.getClientID() != null)
/** * Test that a call to <code>setClientID</code> will throw an * <code>IllegalStateException</code> if a client ID has already been set * see JMS javadoc * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String) */ @Test public void testSetClientID_1() { try { // we start from a clean state for the connection subscriberConnection.close(); subscriberConnection = null; subscriberConnection = subscriberTCF.createTopicConnection(); // if the JMS provider does not set a client ID, we do. if (subscriberConnection.getClientID() == null) { subscriberConnection.setClientID("testSetClientID_1"); Assert.assertEquals("testSetClientID_1", subscriberConnection.getClientID()); } // now the connection has a client ID (either "testSetClientID_1" or one set by the provider Assert.assertTrue(subscriberConnection.getClientID() != null); // an attempt to set a client ID should now throw an IllegalStateException subscriberConnection.setClientID("another client ID"); Assert.fail("Should raise a javax.jms.IllegalStateException"); } catch (javax.jms.IllegalStateException e) { } catch (JMSException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a " + e); } catch (java.lang.IllegalStateException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); } }
/** * Test that a call to <code>setClientID</code> can occur only after connection creation * and before any other action on the connection. * <em>This test is relevant only if the ID is set by the JMS client</em> * see JMS javadoc * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String) */ @Test public void testSetClientID_2() { try { // we start from a clean state for the first connection subscriberConnection.close(); subscriberConnection = null; subscriberConnection = subscriberTCF.createTopicConnection(); // if the JMS provider has set a client ID, this test is not relevant if (subscriberConnection.getClientID() != null) { return; } // we start the connection subscriberConnection.start(); // an attempt to set the client ID now should throw an IllegalStateException subscriberConnection.setClientID("testSetClientID_2"); Assert.fail("Should throw a javax.jms.IllegalStateException"); } catch (javax.jms.IllegalStateException e) { } catch (JMSException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a " + e); } catch (java.lang.IllegalStateException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); } }