@Test public void testPurgeChannelsBuilderWithChannels() { MockBuilder builder = new MockBuilder(applicationContext) { @Override public void configure() { purgeChannels().channels(channel1, channel2).channel(channel3); } }; builder.run(null, null); Assert.assertEquals(builder.testCase().getActions().size(), 1); Assert.assertEquals( builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class); Assert.assertEquals(builder.testCase().getActions().get(0).getName(), "purge-channel"); PurgeMessageChannelAction action = (PurgeMessageChannelAction) builder.testCase().getActions().get(0); Assert.assertEquals(action.getChannels().size(), 3); Assert.assertEquals( action.getChannels().toString(), "[" + channel1.toString() + ", " + channel2.toString() + ", " + channel3.toString() + "]"); Assert.assertNull(action.getMessageSelector()); }
@Test public void testPurgeChannelBuilderWithNames() { MockBuilder builder = new MockBuilder(applicationContextMock) { @Override public void configure() { purgeChannels() .channelResolver(channelResolver) .channelNames("ch1", "ch2", "ch3") .channel("ch4") .selector(messageSelector); } }; reset(applicationContextMock); expect(applicationContextMock.getBean(TestListeners.class)) .andReturn(new TestListeners()) .once(); expect(applicationContextMock.getBean(TestActionListeners.class)) .andReturn(new TestActionListeners()) .once(); expect(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)) .andReturn(new HashMap<String, SequenceBeforeTest>()) .once(); replay(applicationContextMock); builder.run(null, null); Assert.assertEquals(builder.testCase().getActions().size(), 1); Assert.assertEquals( builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class); PurgeMessageChannelAction action = (PurgeMessageChannelAction) builder.testCase().getActions().get(0); Assert.assertEquals(action.getChannelNames().size(), 4); Assert.assertEquals(action.getChannelNames().toString(), "[ch1, ch2, ch3, ch4]"); Assert.assertEquals(action.getChannelResolver(), channelResolver); Assert.assertEquals(action.getMessageSelector(), messageSelector); verify(applicationContextMock); }
@Test public void testMissingChannelResolver() { MockBuilder builder = new MockBuilder(applicationContextMock) { @Override public void configure() { purgeChannels().channel("ch1"); } }; reset(applicationContextMock); expect(applicationContextMock.getBean(TestListeners.class)) .andReturn(new TestListeners()) .once(); expect(applicationContextMock.getBean(TestActionListeners.class)) .andReturn(new TestActionListeners()) .once(); expect(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)) .andReturn(new HashMap<String, SequenceBeforeTest>()) .once(); replay(applicationContextMock); builder.run(null, null); Assert.assertEquals(builder.testCase().getActions().size(), 1); Assert.assertEquals( builder.testCase().getActions().get(0).getClass(), PurgeMessageChannelAction.class); PurgeMessageChannelAction action = (PurgeMessageChannelAction) builder.testCase().getActions().get(0); Assert.assertEquals(action.getChannelNames().size(), 1); Assert.assertEquals(action.getChannelNames().toString(), "[ch1]"); Assert.assertNotNull(action.getChannelResolver()); Assert.assertTrue(action.getChannelResolver() instanceof BeanFactoryChannelResolver); verify(applicationContextMock); }