@Test public void commandReceived() { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); ZigBeeNetworkManager networkManager = getMocketNetworkManager(); ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress("1234567890")); assertTrue(node.setNetworkAddress(12345)); ZigBeeEndpoint endpoint1 = Mockito.mock(ZigBeeEndpoint.class); Mockito.when(endpoint1.getEndpointId()).thenReturn(1); ZigBeeEndpoint endpoint2 = Mockito.mock(ZigBeeEndpoint.class); Mockito.when(endpoint2.getEndpointId()).thenReturn(2); node.addEndpoint(endpoint1); node.addEndpoint(endpoint2); ZigBeeEndpointAddress sourceAddress = Mockito.mock(ZigBeeEndpointAddress.class); Mockito.when(sourceAddress.getAddress()).thenReturn(12345); Mockito.when(sourceAddress.getEndpoint()).thenReturn(1); ZigBeeEndpointAddress invalidSourceAddress = Mockito.mock(ZigBeeEndpointAddress.class); Mockito.when(invalidSourceAddress.getAddress()).thenReturn(1234); Mockito.when(invalidSourceAddress.getEndpoint()).thenReturn(1); ZclCommand zigbeeCommand = Mockito.mock(ZclCommand.class); Mockito.when(zigbeeCommand.getSourceAddress()).thenReturn(invalidSourceAddress); node.commandReceived(zigbeeCommand, null, null); Mockito.verify(endpoint1, Mockito.times(0)).commandReceived(ArgumentMatchers.any(ZclCommand.class)); Mockito.verify(endpoint2, Mockito.times(0)).commandReceived(ArgumentMatchers.any(ZclCommand.class)); ZigBeeAddress zigbeeAddress = Mockito.mock(ZigBeeAddress.class); Mockito.when(zigbeeAddress.getAddress()).thenReturn(124); ZigBeeCommand zigbeeCommandInvalidAddressCmd = Mockito.mock(ZigBeeCommand.class); Mockito.when(zigbeeCommandInvalidAddressCmd.getSourceAddress()).thenReturn(zigbeeAddress); node.commandReceived(zigbeeCommandInvalidAddressCmd, null, null); Mockito.verify(endpoint1, Mockito.times(0)).commandReceived(ArgumentMatchers.any(ZclCommand.class)); Mockito.verify(endpoint2, Mockito.times(0)).commandReceived(ArgumentMatchers.any(ZclCommand.class)); ZclCommand unicast = Mockito.mock(ZclCommand.class); ZigBeeEndpointAddress unicastDestination = Mockito.mock(ZigBeeEndpointAddress.class); Mockito.when(unicastDestination.getAddress()).thenReturn(123); Mockito.when(unicastDestination.getEndpoint()).thenReturn(1); Mockito.when(unicast.getSourceAddress()).thenReturn(sourceAddress); Mockito.when(unicast.getDestinationAddress()).thenReturn(unicastDestination); Mockito.when(unicast.getClusterId()).thenReturn(1); Mockito.when(unicast.getTransactionId()).thenReturn(123); Mockito.when(unicast.getCommandId()).thenReturn(99); node.commandReceived(unicast, null, null); Mockito.verify(endpoint1, Mockito.times(1)).commandReceived(unicast); Mockito.verify(endpoint2, Mockito.times(0)).commandReceived(unicast); assertNull(node.getLinkQualityStatistics().getLastReceivedLqi()); assertNull(node.getLinkQualityStatistics().getLastReceivedRssi()); Mockito.when(sourceAddress.getEndpoint()).thenReturn(10); node.commandReceived(unicast, 1, 2); ArgumentCaptor<ZigBeeCommand> commandCapture = ArgumentCaptor.forClass(ZigBeeCommand.class); Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).sendTransaction(commandCapture.capture()); ZigBeeCommand response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); DefaultResponse defaultResponse = (DefaultResponse) response; assertEquals(Integer.valueOf(1), defaultResponse.getClusterId()); assertEquals(Integer.valueOf(99), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUPPORTED_CLUSTER, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(123), defaultResponse.getTransactionId()); assertEquals(Integer.valueOf(2), node.getLinkQualityStatistics().getLastReceivedLqi()); assertEquals(Integer.valueOf(1), node.getLinkQualityStatistics().getLastReceivedRssi()); ZdoCommand zdoCommand = Mockito.mock(ZdoCommand.class); ZigBeeAddress zdoSource = Mockito.mock(ZigBeeAddress.class); Mockito.when(zdoSource.getAddress()).thenReturn(12345); Mockito.when(zdoCommand.getSourceAddress()).thenReturn(zdoSource); node.commandReceived(zdoCommand, null, null); }
public void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi) { if (!(command instanceof ZclCommand) || networkAddress == null || command.getSourceAddress().getAddress() != networkAddress) { return; } logger.trace("{}: ZigBeeNode.commandReceived({})", ieeeAddress, command); linkQualityStatistics.updateReceivedLqi(lqi); linkQualityStatistics.updateReceivedRssi(rssi); ZclCommand zclCommand = (ZclCommand) command; ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress(); ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint()); if (endpoint == null) { logger.debug("{}: Endpoint {} not found for received node command", ieeeAddress, endpointAddress.getEndpoint()); DefaultResponse response = ZclCluster.createDefaultResponse(zclCommand, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } endpoint.commandReceived(zclCommand); }
ZigBeeNode { public void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi) { if (!(command instanceof ZclCommand) || networkAddress == null || command.getSourceAddress().getAddress() != networkAddress) { return; } logger.trace("{}: ZigBeeNode.commandReceived({})", ieeeAddress, command); linkQualityStatistics.updateReceivedLqi(lqi); linkQualityStatistics.updateReceivedRssi(rssi); ZclCommand zclCommand = (ZclCommand) command; ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress(); ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint()); if (endpoint == null) { logger.debug("{}: Endpoint {} not found for received node command", ieeeAddress, endpointAddress.getEndpoint()); DefaultResponse response = ZclCluster.createDefaultResponse(zclCommand, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } endpoint.commandReceived(zclCommand); } }
ZigBeeNode { public void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi) { if (!(command instanceof ZclCommand) || networkAddress == null || command.getSourceAddress().getAddress() != networkAddress) { return; } logger.trace("{}: ZigBeeNode.commandReceived({})", ieeeAddress, command); linkQualityStatistics.updateReceivedLqi(lqi); linkQualityStatistics.updateReceivedRssi(rssi); ZclCommand zclCommand = (ZclCommand) command; ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress(); ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint()); if (endpoint == null) { logger.debug("{}: Endpoint {} not found for received node command", ieeeAddress, endpointAddress.getEndpoint()); DefaultResponse response = ZclCluster.createDefaultResponse(zclCommand, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } endpoint.commandReceived(zclCommand); } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); }
ZigBeeNode { public void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi) { if (!(command instanceof ZclCommand) || networkAddress == null || command.getSourceAddress().getAddress() != networkAddress) { return; } logger.trace("{}: ZigBeeNode.commandReceived({})", ieeeAddress, command); linkQualityStatistics.updateReceivedLqi(lqi); linkQualityStatistics.updateReceivedRssi(rssi); ZclCommand zclCommand = (ZclCommand) command; ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress(); ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint()); if (endpoint == null) { logger.debug("{}: Endpoint {} not found for received node command", ieeeAddress, endpointAddress.getEndpoint()); DefaultResponse response = ZclCluster.createDefaultResponse(zclCommand, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } endpoint.commandReceived(zclCommand); } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); void shutdown(); IeeeAddress getIeeeAddress(); boolean setNetworkAddress(Integer networkAddress); Integer getNetworkAddress(); void setNodeDescriptor(NodeDescriptor nodeDescriptor); NodeDescriptor getNodeDescriptor(); void setPowerDescriptor(PowerDescriptor powerDescriptor); PowerDescriptor getPowerDescriptor(); void permitJoin(final int duration); void permitJoin(final boolean enable); @Deprecated boolean isFullFuntionDevice(); boolean isFullFunctionDevice(); @Deprecated boolean isReducedFuntionDevice(); boolean isReducedFunctionDevice(); boolean isSecurityCapable(); boolean isPrimaryTrustCenter(); LogicalType getLogicalType(); Set<BindingTable> getBindingTable(); Future<ZigBeeStatus> updateBindingTable(); Collection<ZigBeeEndpoint> getEndpoints(); ZigBeeEndpoint getEndpoint(final int endpointId); void addEndpoint(final ZigBeeEndpoint endpoint); void updateEndpoint(final ZigBeeEndpoint endpoint); void removeEndpoint(final int endpointId); void addNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); void removeNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); Set<NeighborTable> getNeighbors(); boolean setNeighbors(Set<NeighborTable> neighbors); Set<Integer> getAssociatedDevices(); boolean setAssociatedDevices(Set<Integer> associatedDevices); Collection<RoutingTable> getRoutes(); boolean setRoutes(Set<RoutingTable> routes); void setLastUpdateTime(); Date getLastUpdateTime(); void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi); boolean isDiscovered(); ZigBeeNodeDao getDao(); void setDao(ZigBeeNodeDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); boolean setNodeState(ZigBeeNodeState state); ZigBeeNodeState getNodeState(); NotificationService getNotificationService(); ZigBeeLinkQualityStatistics getLinkQualityStatistics(); @Override String toString(); }
ZigBeeNode { public void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi) { if (!(command instanceof ZclCommand) || networkAddress == null || command.getSourceAddress().getAddress() != networkAddress) { return; } logger.trace("{}: ZigBeeNode.commandReceived({})", ieeeAddress, command); linkQualityStatistics.updateReceivedLqi(lqi); linkQualityStatistics.updateReceivedRssi(rssi); ZclCommand zclCommand = (ZclCommand) command; ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress(); ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint()); if (endpoint == null) { logger.debug("{}: Endpoint {} not found for received node command", ieeeAddress, endpointAddress.getEndpoint()); DefaultResponse response = ZclCluster.createDefaultResponse(zclCommand, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } endpoint.commandReceived(zclCommand); } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); void shutdown(); IeeeAddress getIeeeAddress(); boolean setNetworkAddress(Integer networkAddress); Integer getNetworkAddress(); void setNodeDescriptor(NodeDescriptor nodeDescriptor); NodeDescriptor getNodeDescriptor(); void setPowerDescriptor(PowerDescriptor powerDescriptor); PowerDescriptor getPowerDescriptor(); void permitJoin(final int duration); void permitJoin(final boolean enable); @Deprecated boolean isFullFuntionDevice(); boolean isFullFunctionDevice(); @Deprecated boolean isReducedFuntionDevice(); boolean isReducedFunctionDevice(); boolean isSecurityCapable(); boolean isPrimaryTrustCenter(); LogicalType getLogicalType(); Set<BindingTable> getBindingTable(); Future<ZigBeeStatus> updateBindingTable(); Collection<ZigBeeEndpoint> getEndpoints(); ZigBeeEndpoint getEndpoint(final int endpointId); void addEndpoint(final ZigBeeEndpoint endpoint); void updateEndpoint(final ZigBeeEndpoint endpoint); void removeEndpoint(final int endpointId); void addNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); void removeNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); Set<NeighborTable> getNeighbors(); boolean setNeighbors(Set<NeighborTable> neighbors); Set<Integer> getAssociatedDevices(); boolean setAssociatedDevices(Set<Integer> associatedDevices); Collection<RoutingTable> getRoutes(); boolean setRoutes(Set<RoutingTable> routes); void setLastUpdateTime(); Date getLastUpdateTime(); void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi); boolean isDiscovered(); ZigBeeNodeDao getDao(); void setDao(ZigBeeNodeDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); boolean setNodeState(ZigBeeNodeState state); ZigBeeNodeState getNodeState(); NotificationService getNotificationService(); ZigBeeLinkQualityStatistics getLinkQualityStatistics(); @Override String toString();  }