/** * Create a new instance of MessageReceiver. * * @param nodeRegistry * the node registry * @param checkCRC * flag if we must check the CRC */ public NetMessageReceiver(NodeRegistry nodeFactory, boolean checkCRC) { super(nodeFactory, new BidibResponseFactory(), checkCRC); }
@Override protected BidibMessageProcessor createMessageReceiver(NodeRegistry nodeFactory) { return new MessageReceiver(nodeFactory, new BidibResponseFactory(), true) { @Override public void receive(ByteArrayOutputStream data) { LOGGER.warn("receive is not implemented!"); } }; }
public ProxyMessageProcessor(boolean checkCRC) { this.responseFactory = new BidibResponseFactory(); this.checkCRC = checkCRC; LOGGER.info("Create new ProxyMessageProcessor with checkCRC: {}", checkCRC); }
public SerialMessageReceiver(NodeRegistry nodeFactory) { super(nodeFactory, new BidibResponseFactory(), true); messageParser = new SerialMessageParser(); }
try { LOGGER.debug("Parsing message, date: {}, raw: {}", parts[0], parts[2]); messages.add(new Message(dateFormat.parse(parts[0].trim()).getTime(), new BidibResponseFactory() .create(getBytes(parts[2].trim()))));
@Test public void receive4Test() throws IOException, ProtocolException { NodeRegistry nodeFactory = Mockito.mock(NodeRegistry.class); BidibNode bidibNode = Mockito.mock(BidibNode.class); MessageListener messageListener = Mockito.mock(MessageListener.class); SerialMessageReceiver receiver = new SerialMessageReceiver(nodeFactory); receiver.addMessageListener(messageListener); // set the receive queue byte[] rawmessage = { 0x08, 0x03, 0x00, 0x1E, (byte) 0xC6, 0x00, 0x07, 0x00, 0x00, 0x08, 0x03, 0x00, 0x1F, (byte) 0xC6, 0x00, 0x08, 0x00, 0x00, 0x08, 0x03, 0x00, 0x20, (byte) 0xC6, 0x00, 0x09, 0x00, 0x00, 0x08, 0x03, 0x00, 0x21, (byte) 0xC6, 0x00, 0x0A, 0x00, 0x00, 0x08, 0x03, 0x00, 0x22, (byte) 0xC6, 0x00, 0x0B, 0x00, 0x00, 0x08, 0x03, 0x00, 0x23, (byte) 0xC6, 0x00, 0x0C, 0x00, 0x00, 0x08, 0x03, 0x00, 0x24, (byte) 0xC6, 0x00, 0x0D, 0x00, 0x00, (byte) 0xF5, (byte) 0xFE }; byte[] message = new byte[] { 0x08, 0x03, 0x00, 0x17, (byte) 0xC6, 0x00, 0x00, 0x00, 0x00 }; final byte[] nodeAddress = new byte[] { 3 }; Mockito.when(nodeFactory.findNode(nodeAddress)).thenReturn(bidibNode); Mockito .when(bidibNode.getNextReceiveMsgNum(Mockito.any(BidibMessage.class))).thenReturn(Integer.valueOf(0x1E), Integer.valueOf(0x1F), Integer.valueOf(0x20), Integer.valueOf(0x21), Integer.valueOf(0x22), Integer.valueOf(0x23), Integer.valueOf(0x24)); receiver.receive(pack(rawmessage)); BidibMessage response = new BidibResponseFactory().create(message); // verify that message was signaled Mockito.verify(messageListener, Mockito.times(7)).lcConfigX(Mockito.eq(nodeAddress), Mockito.any()); Assert.assertEquals(response.getType(), ByteUtils.getLowByte(BidibLibrary.MSG_LC_CONFIGX)); }
BidibMessage response = new BidibResponseFactory().create(message);
@Test public void receive2MessagesTest() throws IOException, ProtocolException { BidibMessage featureResponse1 = new BidibResponseFactory().create(new byte[] { 0x06, 0x01, 0x00, 0x0e, (byte) 0x90, 0x00, 0x20 }); NodeRegistry nodeFactory = Mockito.mock(NodeRegistry.class); BidibNode bidibNode = Mockito.mock(BidibNode.class); MessageListener messageListener = Mockito.mock(MessageListener.class); // BlockingQueue<BidibMessage> receiveQueue = Mockito.mock(BlockingQueue.class); SerialMessageReceiver receiver = new SerialMessageReceiver(nodeFactory); receiver.addMessageListener(messageListener); // set the receive queue byte[] data = new byte[] { 0x06, 0x01, 0x00, 0x0e, (byte) 0x90, 0x00, 0x20, /* CRC */ (byte) 0xA7, (byte) 0xFE, /* start 2nd message */0x06, 0x01, 0x00, 0x0f, (byte) 0x90, 0x00, 0x20, /* * CRC */ (byte) 0x28, (byte) 0xFE }; final byte[] nodeAddress = new byte[] { 1 }; Mockito.when(nodeFactory.findNode(nodeAddress)).thenReturn(bidibNode); Mockito.when(bidibNode.getNextReceiveMsgNum(Mockito.any(BidibMessage.class))).thenReturn(Integer.valueOf(0x0f)); Mockito.when(bidibNode.getNextReceiveMsgNum(featureResponse1)).thenReturn(Integer.valueOf(0x0e)); // Mockito.when(bidibNode.getReceiveQueue()).thenReturn(receiveQueue); receiver.receive(pack(data)); // verify that no message listener methods were called. Mockito.verifyZeroInteractions(messageListener); }
BidibMessage response0 = new BidibResponseFactory().create(message0); BidibMessage response1 = new BidibResponseFactory().create(message1); BidibMessage response2 = new BidibResponseFactory().create(message2); BidibMessage response3 = new BidibResponseFactory().create(message3);
@Test public void receiveNodeTabResponseTest() throws IOException, ProtocolException { NodeRegistry nodeFactory = Mockito.mock(NodeRegistry.class); BidibNode bidibNode = Mockito.mock(BidibNode.class); MessageListener messageListener = Mockito.mock(MessageListener.class); BlockingQueue<BidibMessage> receiveQueue = Mockito.mock(BlockingQueue.class); SerialMessageReceiver receiver = new SerialMessageReceiver(nodeFactory); receiver.addMessageListener(messageListener); // set the receive queue // 11.08.2013 22:38:40.383: receive NodeTabResponse[[1, 0],num=2,type=137,data=[1, 0, 129, 0, 13, 114, 0, 31, // 0]] : 0d 01 00 02 89 01 00 81 00 0d 72 00 1f 00 byte[] message = new byte[] { 0x0d, 0x01, 0x00, 0x02, (byte) 0x89, 0x01, 0x00, (byte) 0x81, 0x00, (byte) 0x0d, (byte) 0x72, 0x00, 0x1f, 0x00, (byte) 0xFE }; final byte[] nodeAddress = new byte[] { 1 }; Mockito.when(nodeFactory.findNode(nodeAddress)).thenReturn(bidibNode); Mockito.when(bidibNode.getNextReceiveMsgNum(Mockito.any(BidibMessage.class))).thenReturn(Integer.valueOf(2)); // Mockito.when(bidibNode.getReceiveQueue()).thenReturn(receiveQueue); Mockito.doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); receiveQueue.offer((BidibMessage) args[0]); return null; } }).when(bidibNode).addResponseToReceiveQueue(Mockito.any(BidibMessage.class)); receiver.receive(pack(message)); BidibMessage response = new BidibResponseFactory().create(message); // verify that message was signaled Mockito.verify(receiveQueue, Mockito.times(1)).offer(response); }
@Test public void receiveMagicResponseTest() throws IOException, ProtocolException { NodeRegistry nodeFactory = Mockito.mock(NodeRegistry.class); BidibNode bidibNode = Mockito.mock(BidibNode.class); MessageListener messageListener = Mockito.mock(MessageListener.class); BlockingQueue<BidibMessage> receiveQueue = Mockito.mock(BlockingQueue.class); SerialMessageReceiver receiver = new SerialMessageReceiver(nodeFactory); receiver.addMessageListener(messageListener); // set the receive queue // 0x05, 0x00, 0x00, (byte) 0x81, (byte) 0xFD, (byte) 0xDE, (byte) 0xAF, (byte) 0x89, 0xFE byte[] rawmessage = new byte[] { 0x05, 0x00, 0x00, (byte) 0x81, (byte) 0xFD, (byte) 0xDE, (byte) 0xAF, (byte) 0x89, (byte) 0xFE }; byte[] message = new byte[] { 0x05, 0x00, 0x00, (byte) 0x81, (byte) 0xFE, (byte) 0xAF }; final byte[] nodeAddress = new byte[] { 0 }; Mockito.when(nodeFactory.findNode(nodeAddress)).thenReturn(bidibNode); Mockito.when(bidibNode.getNextReceiveMsgNum(Mockito.any(BidibMessage.class))).thenReturn(Integer.valueOf(0)); // Mockito.when(bidibNode.getReceiveQueue()).thenReturn(receiveQueue); Mockito.doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); receiveQueue.offer((BidibMessage) args[0]); return null; } }).when(bidibNode).addResponseToReceiveQueue(Mockito.any(BidibMessage.class)); receiver.receive(pack(rawmessage)); BidibMessage response = new BidibResponseFactory().create(message); // verify that message was signaled Mockito.verify(receiveQueue, Mockito.times(1)).offer(response); }
@Test public void receive5Test() throws IOException, ProtocolException { NodeRegistry nodeFactory = Mockito.mock(NodeRegistry.class); BidibNode bidibNode = Mockito.mock(BidibNode.class); MessageListener messageListener = Mockito.mock(MessageListener.class); SerialMessageReceiver receiver = new SerialMessageReceiver(nodeFactory); receiver.addMessageListener(messageListener); // set the receive queue byte[] rawmessage = { 0x08, 0x03, 0x00, 0x25, (byte) 0xC6, 0x00, 0x0E, 0x00, 0x00, 0x08, 0x03, 0x00, 0x26, (byte) 0xC6, 0x00, 0x0F, 0x00, 0x00, (byte) 0xDA, (byte) 0xFE }; byte[] message = new byte[] { 0x08, 0x03, 0x00, 0x17, (byte) 0xC6, 0x00, 0x00, 0x00, 0x00 }; final byte[] nodeAddress = new byte[] { 3 }; Mockito.when(nodeFactory.findNode(nodeAddress)).thenReturn(bidibNode); Mockito .when(bidibNode.getNextReceiveMsgNum(Mockito.any(BidibMessage.class))) .thenReturn(Integer.valueOf(0x25), Integer.valueOf(0x26)); receiver.receive(pack(rawmessage)); BidibMessage response = new BidibResponseFactory().create(message); // verify that message was signaled Mockito.verify(messageListener, Mockito.times(2)).lcConfigX(Mockito.eq(nodeAddress), Mockito.any()); Assert.assertEquals(response.getType(), ByteUtils.getLowByte(BidibLibrary.MSG_LC_CONFIGX)); }
BidibMessage response = new BidibResponseFactory().create(message);
BidibMessage response = new BidibResponseFactory().create(message);
BidibMessage response1 = new BidibResponseFactory().create(message);
BidibMessage response1 = new BidibResponseFactory().create(message);
BidibMessage response = new BidibResponseFactory().create(message); Assert.assertTrue(response instanceof LcConfigXResponse);
BidibMessage response = new BidibResponseFactory().create(message);
BidibMessage response = new BidibResponseFactory().create(message);