@Test public void testAlternateConstructor() throws Exception { final AtomicBoolean called = new AtomicBoolean(false); class Delegate { @SuppressWarnings("unused") public String myPojoMessageMethod(String input) { called.set(true); return "processed" + input; } } this.adapter = new MessageListenerAdapter(new Delegate(), "myPojoMessageMethod"); this.adapter.onMessage(new Message("foo".getBytes(), messageProperties), null); assertTrue(called.get()); }
@Test public void testDefaultListenerMethod() throws Exception { final AtomicBoolean called = new AtomicBoolean(false); class Delegate { @SuppressWarnings("unused") public String handleMessage(String input) { called.set(true); return "processed" + input; } } this.adapter.setDelegate(new Delegate()); this.adapter.onMessage(new Message("foo".getBytes(), messageProperties), null); assertTrue(called.get()); }
@Test public void testExplicitListenerMethod() throws Exception { this.adapter.setDefaultListenerMethod("handle"); this.adapter.setDelegate(this.simpleService); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("handle", this.simpleService.called); }
@Test public void testMappedListenerMethod() throws Exception { Map<String, String> map = new HashMap<String, String>(); map.put("foo", "handle"); map.put("bar", "notDefinedOnInterface"); this.adapter.setDefaultListenerMethod("anotherHandle"); this.adapter.setQueueOrTagToMethodName(map); this.adapter.setDelegate(this.simpleService); this.messageProperties.setConsumerQueue("foo"); this.messageProperties.setConsumerTag("bar"); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("handle", this.simpleService.called); this.messageProperties.setConsumerQueue("junk"); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("notDefinedOnInterface", this.simpleService.called); this.messageProperties.setConsumerTag("junk"); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("anotherHandle", this.simpleService.called); }
@Test public void testJdkProxyListener() throws Exception { this.adapter.setDefaultListenerMethod("handle"); ProxyFactory factory = new ProxyFactory(this.simpleService); factory.setProxyTargetClass(false); this.adapter.setDelegate(factory.getProxy()); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("handle", this.simpleService.called); }
@Test public void testProxyListener() throws Exception { this.adapter.setDefaultListenerMethod("notDefinedOnInterface"); ProxyFactory factory = new ProxyFactory(this.simpleService); factory.setProxyTargetClass(true); this.adapter.setDelegate(factory.getProxy()); this.adapter.onMessage(new Message("foo".getBytes(), this.messageProperties), null); assertEquals("notDefinedOnInterface", this.simpleService.called); }
.basicPublish(eq("foo"), eq("bar"), eq(Boolean.FALSE), any(), any()); Message message = new Message("foo".getBytes(), this.messageProperties); this.adapter.onMessage(message, channel); assertThat(this.simpleService.called, equalTo("handle")); assertThat(replyMessage.get(), notNullValue());