@Test public void commandReceived() { ZigBeeEndpoint endpoint = getEndpoint(); ZclCommand command = mockZclCommand(ZclCommand.class); Mockito.when(command.getClusterId()).thenReturn(0); ZclCluster cluster = Mockito.mock(ZclCluster.class); Mockito.when(cluster.getClusterId()).thenReturn(0); endpoint.addInputCluster(cluster); endpoint.commandReceived(command); Mockito.verify(cluster, Mockito.timeout(TIMEOUT).times(1)).handleCommand(command); Mockito.verify(node, Mockito.timeout(TIMEOUT).times(0)) .sendTransaction(ArgumentMatchers.any(ZigBeeCommand.class)); command = mockZclCommand(ReportAttributesCommand.class); Mockito.when(command.getClusterId()).thenReturn(1); Mockito.when(command.getTransactionId()).thenReturn(123); Mockito.when(command.getCommandId()).thenReturn(99); endpoint.commandReceived(command); Mockito.verify(node, 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(99), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUPPORTED_CLUSTER, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(123), defaultResponse.getTransactionId()); ZigBeeApplication application = Mockito.mock(ZigBeeApplication.class); Mockito.when(application.appStartup(cluster)).thenReturn(ZigBeeStatus.SUCCESS); Mockito.when(application.getClusterId()).thenReturn(0); assertEquals(ZigBeeStatus.SUCCESS, endpoint.addApplication(application)); assertEquals(ZigBeeStatus.INVALID_STATE, endpoint.addApplication(application)); Mockito.verify(application, Mockito.times(1)).appStartup(ArgumentMatchers.any(ZclCluster.class)); assertEquals(application, endpoint.getApplication(0)); }
public void commandReceived(ZclCommand command) { if (!command.getSourceAddress().equals(getEndpointAddress())) { return; } logger.trace("{}: Endpoint {}. ZigBeeEndpoint.commandReceived({})", getIeeeAddress(), getEndpointId(), command); ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection()); if (cluster == null) { logger.debug("{}: Endpoint {}. Cluster {} not found for received endpoint command", getIeeeAddress(), getEndpointId(), String.format("%04X", command.getClusterId())); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } if (cluster.getApsSecurityRequired() && !command.getApsSecurity()) { logger.debug("{}: Endpoint {}. Cluster '{}' requires security but command is not secured", getIeeeAddress(), getEndpointId(), cluster.getClusterName()); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSECURED); if (response != null) { sendTransaction(response); } return; } cluster.handleCommand(command); }
ZigBeeEndpoint { public void commandReceived(ZclCommand command) { if (!command.getSourceAddress().equals(getEndpointAddress())) { return; } logger.trace("{}: Endpoint {}. ZigBeeEndpoint.commandReceived({})", getIeeeAddress(), getEndpointId(), command); ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection()); if (cluster == null) { logger.debug("{}: Endpoint {}. Cluster {} not found for received endpoint command", getIeeeAddress(), getEndpointId(), String.format("%04X", command.getClusterId())); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } if (cluster.getApsSecurityRequired() && !command.getApsSecurity()) { logger.debug("{}: Endpoint {}. Cluster '{}' requires security but command is not secured", getIeeeAddress(), getEndpointId(), cluster.getClusterName()); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSECURED); if (response != null) { sendTransaction(response); } return; } cluster.handleCommand(command); } }
ZigBeeEndpoint { public void commandReceived(ZclCommand command) { if (!command.getSourceAddress().equals(getEndpointAddress())) { return; } logger.trace("{}: Endpoint {}. ZigBeeEndpoint.commandReceived({})", getIeeeAddress(), getEndpointId(), command); ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection()); if (cluster == null) { logger.debug("{}: Endpoint {}. Cluster {} not found for received endpoint command", getIeeeAddress(), getEndpointId(), String.format("%04X", command.getClusterId())); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } if (cluster.getApsSecurityRequired() && !command.getApsSecurity()) { logger.debug("{}: Endpoint {}. Cluster '{}' requires security but command is not secured", getIeeeAddress(), getEndpointId(), cluster.getClusterName()); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSECURED); if (response != null) { sendTransaction(response); } return; } cluster.handleCommand(command); } ZigBeeEndpoint(ZigBeeNode node, int endpoint); }
ZigBeeEndpoint { public void commandReceived(ZclCommand command) { if (!command.getSourceAddress().equals(getEndpointAddress())) { return; } logger.trace("{}: Endpoint {}. ZigBeeEndpoint.commandReceived({})", getIeeeAddress(), getEndpointId(), command); ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection()); if (cluster == null) { logger.debug("{}: Endpoint {}. Cluster {} not found for received endpoint command", getIeeeAddress(), getEndpointId(), String.format("%04X", command.getClusterId())); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } if (cluster.getApsSecurityRequired() && !command.getApsSecurity()) { logger.debug("{}: Endpoint {}. Cluster '{}' requires security but command is not secured", getIeeeAddress(), getEndpointId(), cluster.getClusterName()); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSECURED); if (response != null) { sendTransaction(response); } return; } cluster.handleCommand(command); } ZigBeeEndpoint(ZigBeeNode node, int endpoint); int getDeviceId(); void setDeviceId(int deviceId); int getDeviceVersion(); void setDeviceVersion(int deviceVersion); int getEndpointId(); Collection<Integer> getInputClusterIds(); boolean addInputCluster(ZclCluster cluster); ZclCluster getInputCluster(int clusterId); ZclCluster getOutputCluster(int clusterId); void setInputClusterIds(List<Integer> inputClusterIds); IeeeAddress getIeeeAddress(); ZigBeeEndpointAddress getEndpointAddress(); Collection<Integer> getOutputClusterIds(); void setOutputClusterIds(Collection<Integer> outputClusterIds); boolean addOutputCluster(ZclCluster cluster); int getProfileId(); void setProfileId(int profileId); ZigBeeNode getParentNode(); ZigBeeStatus addApplication(ZigBeeApplication application); ZigBeeApplication getApplication(int clusterId); void commandReceived(ZclCommand command); boolean updateEndpoint(ZigBeeEndpoint endpoint); ZigBeeEndpointDao getDao(); void setDao(ZigBeeEndpointDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); NotificationService getNotificationService(); @Override String toString(); }
ZigBeeEndpoint { public void commandReceived(ZclCommand command) { if (!command.getSourceAddress().equals(getEndpointAddress())) { return; } logger.trace("{}: Endpoint {}. ZigBeeEndpoint.commandReceived({})", getIeeeAddress(), getEndpointId(), command); ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection()); if (cluster == null) { logger.debug("{}: Endpoint {}. Cluster {} not found for received endpoint command", getIeeeAddress(), getEndpointId(), String.format("%04X", command.getClusterId())); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSUPPORTED_CLUSTER); if (response != null) { sendTransaction(response); } return; } if (cluster.getApsSecurityRequired() && !command.getApsSecurity()) { logger.debug("{}: Endpoint {}. Cluster '{}' requires security but command is not secured", getIeeeAddress(), getEndpointId(), cluster.getClusterName()); DefaultResponse response = ZclCluster.createDefaultResponse(command, ZclStatus.UNSECURED); if (response != null) { sendTransaction(response); } return; } cluster.handleCommand(command); } ZigBeeEndpoint(ZigBeeNode node, int endpoint); int getDeviceId(); void setDeviceId(int deviceId); int getDeviceVersion(); void setDeviceVersion(int deviceVersion); int getEndpointId(); Collection<Integer> getInputClusterIds(); boolean addInputCluster(ZclCluster cluster); ZclCluster getInputCluster(int clusterId); ZclCluster getOutputCluster(int clusterId); void setInputClusterIds(List<Integer> inputClusterIds); IeeeAddress getIeeeAddress(); ZigBeeEndpointAddress getEndpointAddress(); Collection<Integer> getOutputClusterIds(); void setOutputClusterIds(Collection<Integer> outputClusterIds); boolean addOutputCluster(ZclCluster cluster); int getProfileId(); void setProfileId(int profileId); ZigBeeNode getParentNode(); ZigBeeStatus addApplication(ZigBeeApplication application); ZigBeeApplication getApplication(int clusterId); void commandReceived(ZclCommand command); boolean updateEndpoint(ZigBeeEndpoint endpoint); ZigBeeEndpointDao getDao(); void setDao(ZigBeeEndpointDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); NotificationService getNotificationService(); @Override String toString();  }