Skip to content

Commit 537cf7e

Browse files
committed
Fix AMQP resource creation in RMQObjectFactory
The exchange/routing key/queue were all marked as non-nullable, whereas they can be null. The RMQDestination constructor takes care of checking the arguments. Fixes #129 (cherry picked from commit 1ef64f8)
1 parent 8757597 commit 537cf7e

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/main/java/com/rabbitmq/jms/admin/RMQObjectFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ public Object createDestination(Reference ref, Hashtable<?, ?> environment, Name
227227
String dname = getStringProperty(ref, environment, "destinationName", false, null);
228228
boolean amqp = getBooleanProperty(ref, environment, "amqp", true, false);
229229
if (amqp) {
230-
String amqpExchangeName = getStringProperty(ref, environment, "amqpExchangeName", false, null);
231-
String amqpRoutingKey = getStringProperty(ref, environment,"amqpRoutingKey", false, null);
232-
String amqpQueueName = getStringProperty(ref, environment, "amqpQueueName", false, null);
230+
String amqpExchangeName = getStringProperty(ref, environment, "amqpExchangeName", true, null);
231+
String amqpRoutingKey = getStringProperty(ref, environment,"amqpRoutingKey", true, null);
232+
String amqpQueueName = getStringProperty(ref, environment, "amqpQueueName", true, null);
233233
return new RMQDestination(dname, amqpExchangeName, amqpRoutingKey, amqpQueueName);
234234
} else {
235235
return new RMQDestination(dname, !topic, false);

src/test/java/com/rabbitmq/jms/admin/RMQDestinationTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,34 @@ void amqpDestinationRegeneration() throws Exception {
4646
assertThat(newReference.getAmqpQueueName()).isEqualTo("queue");
4747
}
4848

49+
@Test
50+
void amqpDestinationExchangeRoutingKeyOnlyRegeneration() throws Exception {
51+
RMQDestination destination = new RMQDestination(
52+
"destination", "exchange", "routing-key", null
53+
);
54+
Reference reference = destination.getReference();
55+
RMQDestination newReference = (RMQDestination) rmqObjectFactory.getObjectInstance(reference, null, null, null);
56+
assertThat(newReference.isQueue()).isTrue();
57+
assertThat(newReference.getDestinationName()).isEqualTo("destination");
58+
assertThat(newReference.isAmqp()).isTrue();
59+
assertThat(newReference.getAmqpExchangeName()).isEqualTo("exchange");
60+
assertThat(newReference.getAmqpRoutingKey()).isEqualTo("routing-key");
61+
assertThat(newReference.getAmqpQueueName()).isNull();
62+
}
63+
64+
@Test
65+
void amqpDestinationQueueOnlyRegeneration() throws Exception {
66+
RMQDestination destination = new RMQDestination(
67+
"destination", null, null, "queue"
68+
);
69+
Reference reference = destination.getReference();
70+
RMQDestination newReference = (RMQDestination) rmqObjectFactory.getObjectInstance(reference, null, null, null);
71+
assertThat(newReference.isQueue()).isTrue();
72+
assertThat(newReference.getDestinationName()).isEqualTo("destination");
73+
assertThat(newReference.isAmqp()).isTrue();
74+
assertThat(newReference.getAmqpExchangeName()).isNull();
75+
assertThat(newReference.getAmqpRoutingKey()).isNull();
76+
assertThat(newReference.getAmqpQueueName()).isEqualTo("queue");
77+
}
78+
4979
}

src/test/java/com/rabbitmq/jms/admin/RMQObjectFactoryTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void getObjectInstanceShouldCreateAMQPDestinationQUEUEViaEnvironment() th
9191

9292

9393
@Test
94-
public void getObjectInstanceShouldCreateARMQDestinationTOPICViaEnvironment() throws Exception {
94+
public void getObjectInstanceShouldCreateAMQPDestinationTOPICViaEnvironment() throws Exception {
9595

9696
Hashtable<?, ?> environment = new Hashtable<Object, Object>() {{
9797
put("className", "javax.jms.Topic");
@@ -116,15 +116,14 @@ public void getObjectInstanceShouldThrowNamingExceptionWhenMissingRequiredProper
116116

117117
Hashtable<?, ?> environment = new Hashtable<Object, Object>() {{
118118
put("className", "javax.jms.Queue");
119-
put("destinationName", "TEST_QUEUE");
120119
put("amqp", "true");
121120
}};
122121

123122
try {
124123
rmqObjectFactory.getObjectInstance("anything but a javax.naming.Reference", new CompositeName("java:global/jms/TestConnectionFactory"), null, environment);
125124
fail("Should have thrown a NamingException");
126125
} catch (NamingException ne) {
127-
assertEquals("Property [amqpExchangeName] may not be null.", ne.getMessage());
126+
assertEquals("Property [destinationName] may not be null.", ne.getMessage());
128127
}
129128

130129
}

0 commit comments

Comments
 (0)