@Test public void sendTransaction() { ZigBeeNetworkManager networkManager = Mockito.mock(ZigBeeNetworkManager.class); Mockito.when(networkManager.getNotificationService()).thenReturn(new NotificationService()); ZigBeeCommand command = getCommand(123); Mockito.when(command.getTransactionId()).thenReturn(null); ZigBeeTransactionMatcher responseMatcher = Mockito.mock(ZigBeeTransactionMatcher.class); ZigBeeNode node = Mockito.mock(ZigBeeNode.class); Mockito.when(node.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); NodeDescriptor nodeDescriptor = Mockito.mock(NodeDescriptor.class); Set<MacCapabilitiesType> macCapabilities = new HashSet<>(); macCapabilities.add(MacCapabilitiesType.RECEIVER_ON_WHEN_IDLE); Mockito.when(nodeDescriptor.getMacCapabilities()).thenReturn(macCapabilities); Mockito.when(node.getNodeDescriptor()).thenReturn(nodeDescriptor); Mockito.when(networkManager.getNode(123)).thenReturn(node); ZigBeeNode sleepyNode = Mockito.mock(ZigBeeNode.class); Mockito.when(sleepyNode.getIeeeAddress()).thenReturn(new IeeeAddress("FEDCBA0987654321")); NodeDescriptor sleepyNodeDescriptor = Mockito.mock(NodeDescriptor.class); Set<MacCapabilitiesType> sleepyMacCapabilities = new HashSet<>(); Mockito.when(sleepyNodeDescriptor.getMacCapabilities()).thenReturn(sleepyMacCapabilities); Mockito.when(sleepyNode.getNodeDescriptor()).thenReturn(sleepyNodeDescriptor); Mockito.when(networkManager.getNode(456)).thenReturn(sleepyNode); ZigBeeNode sleepyNode2 = Mockito.mock(ZigBeeNode.class); Mockito.when(sleepyNode2.getIeeeAddress()).thenReturn(new IeeeAddress("1111111111111111")); NodeDescriptor sleepyNodeDescriptor2 = Mockito.mock(NodeDescriptor.class); Mockito.when(sleepyNodeDescriptor2.getMacCapabilities()).thenReturn(sleepyMacCapabilities); Mockito.when(sleepyNode2.getNodeDescriptor()).thenReturn(sleepyNodeDescriptor2); Mockito.when(networkManager.getNode(111)).thenReturn(sleepyNode2); ZigBeeTransactionManager transactionManager = new ZigBeeTransactionManager(networkManager) { @Override protected ScheduledFuture<?> scheduleTask(Runnable runnableTask, long delay) { return Mockito.mock(ScheduledFuture.class); } }; transactionManager.setDefaultProfile(new ZigBeeTransactionProfile(0, 12, 0)); assertEquals(12, transactionManager.getDefaultProfile().getMaxOutstandingTransactions()); transactionManager.setSleepyProfile(new ZigBeeTransactionProfile(0, 13, 0)); assertEquals(13, transactionManager.getSleepyProfile().getMaxOutstandingTransactions()); transactionManager.setMulticastProfile(new ZigBeeTransactionProfile(2, 90, 0)); assertEquals(90, transactionManager.getMulticastProfile().getMaxOutstandingTransactions()); transactionManager.setBroadcastProfile(new ZigBeeTransactionProfile(2, 100, 0)); assertEquals(100, transactionManager.getBroadcastProfile().getMaxOutstandingTransactions()); transactionManager.setMaxOutstandingTransactions(4); assertEquals(4, transactionManager.getMaxOutstandingTransactions()); transactionManager.setMaxSleepyTransactions(1); assertEquals(1, transactionManager.getMaxSleepyTransactions()); assertNull(transactionManager.getQueue(new IeeeAddress("1234567890ABCDEF"))); Future<CommandResult> cmdResult = transactionManager.sendTransaction(command, responseMatcher); assertNotNull(cmdResult); Mockito.verify(command, Mockito.times(1)).setTransactionId(ArgumentMatchers.anyInt()); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); assertNotNull(transactionManager.getQueue(new IeeeAddress("1234567890ABCDEF"))); assertFalse(transactionManager.getQueue(new IeeeAddress("1234567890ABCDEF")).isSleepy()); ZigBeeCommand sleepyCommand = Mockito.mock(ZigBeeCommand.class); Mockito.when(sleepyCommand.getDestinationAddress()).thenReturn(new ZigBeeEndpointAddress(456)); cmdResult = transactionManager.sendTransaction(sleepyCommand, responseMatcher); assertNotNull(cmdResult); Mockito.verify(command, Mockito.times(1)).setTransactionId(ArgumentMatchers.anyInt()); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); assertNotNull(transactionManager.getQueue(new IeeeAddress("FEDCBA0987654321"))); assertTrue(transactionManager.getQueue(new IeeeAddress("FEDCBA0987654321")).isSleepy()); ZigBeeCommand sleepyCommand2 = Mockito.mock(ZigBeeCommand.class); Mockito.when(sleepyCommand2.getDestinationAddress()).thenReturn(new ZigBeeEndpointAddress(111)); cmdResult = transactionManager.sendTransaction(sleepyCommand2, responseMatcher); assertNotNull(cmdResult); Mockito.verify(command, Mockito.times(1)).setTransactionId(ArgumentMatchers.anyInt()); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); assertNotNull(transactionManager.getQueue(new IeeeAddress("1111111111111111"))); assertTrue(transactionManager.getQueue(new IeeeAddress("1111111111111111")).isSleepy()); command = Mockito.mock(ZigBeeCommand.class); Mockito.when(command.getDestinationAddress()).thenReturn(new ZigBeeEndpointAddress(789)); cmdResult = transactionManager.sendTransaction(command, responseMatcher); assertNotNull(cmdResult); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); command = getCommand(123); transactionManager.sendTransaction(command); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); transactionManager.setMaxOutstandingTransactions(10); command = Mockito.mock(ZigBeeCommand.class); Mockito.when(command.getDestinationAddress()) .thenReturn(new ZigBeeEndpointAddress(ZigBeeBroadcastDestination.BROADCAST_ALL_DEVICES.getKey())); transactionManager.sendTransaction(command); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendCommand(command); transactionManager.removeNode(new IeeeAddress("1111111111111111")); assertNull(transactionManager.getQueue(new IeeeAddress("1111111111111111"))); transactionManager.removeNode(new IeeeAddress("9999999999999999")); transactionManager.shutdown(); }
public void sendTransaction(ZigBeeCommand command) { sendTransaction(command, null); }
ZigBeeTransactionManager implements ZigBeeNetworkNodeListener { public void sendTransaction(ZigBeeCommand command) { sendTransaction(command, null); } }
ZigBeeTransactionManager implements ZigBeeNetworkNodeListener { public void sendTransaction(ZigBeeCommand command) { sendTransaction(command, null); } ZigBeeTransactionManager(ZigBeeNetworkManager manager); }
ZigBeeTransactionManager implements ZigBeeNetworkNodeListener { public void sendTransaction(ZigBeeCommand command) { sendTransaction(command, null); } ZigBeeTransactionManager(ZigBeeNetworkManager manager); void shutdown(); int getMaxOutstandingTransactions(); void setMaxOutstandingTransactions(int maxOutstandingTransactions); int getMaxSleepyTransactions(); void setMaxSleepyTransactions(int maxSleepyTransactions); void setDefaultProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getDefaultProfile(); void setSleepyProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getSleepyProfile(); void setMulticastProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getMulticastProfile(); void setBroadcastProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getBroadcastProfile(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); ZigBeeCommand receive(final ZigBeeCommand command); void receiveCommandState(int transactionId, ZigBeeTransportProgressState state); ZigBeeTransactionQueue getQueue(IeeeAddress address); void removeNode(IeeeAddress address); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node); @Override void nodeRemoved(ZigBeeNode node); }
ZigBeeTransactionManager implements ZigBeeNetworkNodeListener { public void sendTransaction(ZigBeeCommand command) { sendTransaction(command, null); } ZigBeeTransactionManager(ZigBeeNetworkManager manager); void shutdown(); int getMaxOutstandingTransactions(); void setMaxOutstandingTransactions(int maxOutstandingTransactions); int getMaxSleepyTransactions(); void setMaxSleepyTransactions(int maxSleepyTransactions); void setDefaultProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getDefaultProfile(); void setSleepyProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getSleepyProfile(); void setMulticastProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getMulticastProfile(); void setBroadcastProfile(ZigBeeTransactionProfile profile); ZigBeeTransactionProfile getBroadcastProfile(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); ZigBeeCommand receive(final ZigBeeCommand command); void receiveCommandState(int transactionId, ZigBeeTransportProgressState state); ZigBeeTransactionQueue getQueue(IeeeAddress address); void removeNode(IeeeAddress address); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node); @Override void nodeRemoved(ZigBeeNode node);  }