@Test public void testProducerServerForText() { final TextObject textObj = new TextObject(); textObj.setACK(true); textObj.setContent("This is a Mock Text content."); textObj.setTopic("UnitTest"); SocketAddress socketAddress = new InetSocketAddress("127.0.0.1", 8000); Channel channel = mock(Channel.class); when(channel.write(argThat(new Matcher<TextACK>() { @Override public void describeTo(Description arg0) { } @Override public void _dont_implement_Matcher___instead_extend_BaseMatcher_() { } @Override public boolean matches(Object arg0) { TextACK textAck = (TextACK)arg0; System.out.println(textAck.toString()); Assert.assertEquals(TextACK.class, arg0.getClass()); switch(textAck.getStatus()){ case ProducerServerTextHandler.OK: Assert.assertEquals(SHAUtil.generateSHA(textObj.getContent()), textAck.getInfo()); break; case ProducerServerTextHandler.INVALID_TOPIC_NAME: Assert.assertEquals("TopicName is invalid.", textAck.getInfo()); break; case ProducerServerTextHandler.SAVE_FAILED: Assert.assertEquals("Can not save message.", textAck.getInfo()); break; } return true; } }))).thenReturn(null); when(channel.getRemoteAddress()).thenReturn(socketAddress); MessageEvent messageEvent = mock(MessageEvent.class); when(messageEvent.getMessage()).thenReturn(textObj); when(messageEvent.getRemoteAddress()).thenReturn(socketAddress); when(messageEvent.getChannel()).thenReturn(channel); MessageDAO messageDAO = mock(MessageDAO.class); ProducerServerTextHandler producerServerTextHandler = new ProducerServerTextHandler(messageDAO); producerServerTextHandler.messageReceived(null, messageEvent); textObj.setTopic("H:ello"); producerServerTextHandler.messageReceived(null, messageEvent); doThrow(new RuntimeException()).when(messageDAO).saveMessage(Matchers.anyString(), (SwallowMessage)Matchers.anyObject()); producerServerTextHandler.messageReceived(null, messageEvent); ChannelEvent e = mock(ChannelStateEvent.class); ExceptionEvent e2 = mock (ExceptionEvent.class); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); producerServerTextHandler.handleUpstream(ctx, e); producerServerTextHandler.exceptionCaught(ctx, e2); new ProducerServerForText().start(); }
public ProducerServerForText() { HawkJMXUtil.unregisterMBean("ProducerServerForText"); HawkJMXUtil.registerMBean("ProducerServerForText", new HawkMBean(this)); }
ProducerServerForText { public ProducerServerForText() { HawkJMXUtil.unregisterMBean("ProducerServerForText"); HawkJMXUtil.registerMBean("ProducerServerForText", new HawkMBean(this)); } }
ProducerServerForText { public ProducerServerForText() { HawkJMXUtil.unregisterMBean("ProducerServerForText"); HawkJMXUtil.registerMBean("ProducerServerForText", new HawkMBean(this)); } ProducerServerForText(); }
ProducerServerForText { public ProducerServerForText() { HawkJMXUtil.unregisterMBean("ProducerServerForText"); HawkJMXUtil.registerMBean("ProducerServerForText", new HawkMBean(this)); } ProducerServerForText(); void start(); int getPort(); void setPort(int port); void setMessageDAO(MessageDAO messageDAO); }
ProducerServerForText { public ProducerServerForText() { HawkJMXUtil.unregisterMBean("ProducerServerForText"); HawkJMXUtil.registerMBean("ProducerServerForText", new HawkMBean(this)); } ProducerServerForText(); void start(); int getPort(); void setPort(int port); void setMessageDAO(MessageDAO messageDAO);  }