@Test public void HandleEphemeralDataRequestUninitialised() throws Exception { TestUtilities.outputTestHeader(); ZclKeyEstablishmentCluster keCluster = Mockito.mock(ZclKeyEstablishmentCluster.class); IeeeAddress ieeeAddress = new IeeeAddress("1111111111111111"); ZclKeyEstablishmentServer keServer = new ZclKeyEstablishmentServer(ieeeAddress, keCluster); ArgumentCaptor<ZclKeyEstablishmentCommand> commandArgumentCaptor = ArgumentCaptor .forClass(ZclKeyEstablishmentCommand.class); Mockito.when(keCluster.sendCommand(commandArgumentCaptor.capture())).thenReturn(null); ZigBeeCbkeExchange cbkeExchange = Mockito.mock(ZigBeeCbkeExchange.class); TestUtilities.setField(ZclKeyEstablishmentServer.class, keServer, "cbkeExchange", cbkeExchange); EphemeralDataRequestCommand command = new EphemeralDataRequestCommand(Mockito.mock(ByteArray.class)); command.setCommandDirection(ZclCommandDirection.CLIENT_TO_SERVER); assertTrue(keServer.commandReceived(command)); Mockito.verify(keCluster, Mockito.timeout(TIMEOUT).times(1)) .sendCommand(ArgumentMatchers.any(ZclKeyEstablishmentCommand.class)); Mockito.verify(cbkeExchange, Mockito.timeout(TIMEOUT).times(1)).completeKeyExchange(false); assertEquals(KeyEstablishmentState.UNINITIALISED, TestUtilities.getField(ZclKeyEstablishmentServer.class, keServer, "keyEstablishmentState")); assertEquals(1, commandArgumentCaptor.getAllValues().size()); TerminateKeyEstablishment terminateKeyEstablishment = (TerminateKeyEstablishment) commandArgumentCaptor .getAllValues().get(0); assertEquals(Integer.valueOf(KeyEstablishmentStatusEnum.BAD_MESSAGE.getKey()), terminateKeyEstablishment.getStatusCode()); assertEquals(Integer.valueOf(1), terminateKeyEstablishment.getKeyEstablishmentSuite()); assertEquals(Integer.valueOf(10), terminateKeyEstablishment.getWaitTime()); }
@Override public boolean commandReceived(ZclCommand command) { logger.debug("{}: CBKE Key Establishment Server: Received {}", ieeeAddress, command); Runnable handler = null; if (command.getCommandDirection() != ZclCommandDirection.CLIENT_TO_SERVER) { return false; } if (command instanceof InitiateKeyEstablishmentRequestCommand) { handler = new HandleInitiateKeyEstablishmentRequest((InitiateKeyEstablishmentRequestCommand) command); } if (command instanceof EphemeralDataRequestCommand) { handler = new HandleEphemeralDataRequest((EphemeralDataRequestCommand) command); } if (command instanceof ConfirmKeyDataRequestCommand) { handler = new HandleConfirmKeyRequest((ConfirmKeyDataRequestCommand) command); } if (command instanceof TerminateKeyEstablishment) { handler = new HandleTerminateKeyEstablishment((TerminateKeyEstablishment) command); } if (handler != null) { executorService.submit(handler); return true; } return false; }
ZclKeyEstablishmentServer implements ZclCommandListener { @Override public boolean commandReceived(ZclCommand command) { logger.debug("{}: CBKE Key Establishment Server: Received {}", ieeeAddress, command); Runnable handler = null; if (command.getCommandDirection() != ZclCommandDirection.CLIENT_TO_SERVER) { return false; } if (command instanceof InitiateKeyEstablishmentRequestCommand) { handler = new HandleInitiateKeyEstablishmentRequest((InitiateKeyEstablishmentRequestCommand) command); } if (command instanceof EphemeralDataRequestCommand) { handler = new HandleEphemeralDataRequest((EphemeralDataRequestCommand) command); } if (command instanceof ConfirmKeyDataRequestCommand) { handler = new HandleConfirmKeyRequest((ConfirmKeyDataRequestCommand) command); } if (command instanceof TerminateKeyEstablishment) { handler = new HandleTerminateKeyEstablishment((TerminateKeyEstablishment) command); } if (handler != null) { executorService.submit(handler); return true; } return false; } }
ZclKeyEstablishmentServer implements ZclCommandListener { @Override public boolean commandReceived(ZclCommand command) { logger.debug("{}: CBKE Key Establishment Server: Received {}", ieeeAddress, command); Runnable handler = null; if (command.getCommandDirection() != ZclCommandDirection.CLIENT_TO_SERVER) { return false; } if (command instanceof InitiateKeyEstablishmentRequestCommand) { handler = new HandleInitiateKeyEstablishmentRequest((InitiateKeyEstablishmentRequestCommand) command); } if (command instanceof EphemeralDataRequestCommand) { handler = new HandleEphemeralDataRequest((EphemeralDataRequestCommand) command); } if (command instanceof ConfirmKeyDataRequestCommand) { handler = new HandleConfirmKeyRequest((ConfirmKeyDataRequestCommand) command); } if (command instanceof TerminateKeyEstablishment) { handler = new HandleTerminateKeyEstablishment((TerminateKeyEstablishment) command); } if (handler != null) { executorService.submit(handler); return true; } return false; } ZclKeyEstablishmentServer(IeeeAddress ieeeAddress, ZclKeyEstablishmentCluster keCluster); }
ZclKeyEstablishmentServer implements ZclCommandListener { @Override public boolean commandReceived(ZclCommand command) { logger.debug("{}: CBKE Key Establishment Server: Received {}", ieeeAddress, command); Runnable handler = null; if (command.getCommandDirection() != ZclCommandDirection.CLIENT_TO_SERVER) { return false; } if (command instanceof InitiateKeyEstablishmentRequestCommand) { handler = new HandleInitiateKeyEstablishmentRequest((InitiateKeyEstablishmentRequestCommand) command); } if (command instanceof EphemeralDataRequestCommand) { handler = new HandleEphemeralDataRequest((EphemeralDataRequestCommand) command); } if (command instanceof ConfirmKeyDataRequestCommand) { handler = new HandleConfirmKeyRequest((ConfirmKeyDataRequestCommand) command); } if (command instanceof TerminateKeyEstablishment) { handler = new HandleTerminateKeyEstablishment((TerminateKeyEstablishment) command); } if (handler != null) { executorService.submit(handler); return true; } return false; } ZclKeyEstablishmentServer(IeeeAddress ieeeAddress, ZclKeyEstablishmentCluster keCluster); void setCbkeProvider(ZigBeeCbkeProvider cbkeProvider); void shutdown(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); ZigBeeCryptoSuites getCryptoSuite(); @Override boolean commandReceived(ZclCommand command); }
ZclKeyEstablishmentServer implements ZclCommandListener { @Override public boolean commandReceived(ZclCommand command) { logger.debug("{}: CBKE Key Establishment Server: Received {}", ieeeAddress, command); Runnable handler = null; if (command.getCommandDirection() != ZclCommandDirection.CLIENT_TO_SERVER) { return false; } if (command instanceof InitiateKeyEstablishmentRequestCommand) { handler = new HandleInitiateKeyEstablishmentRequest((InitiateKeyEstablishmentRequestCommand) command); } if (command instanceof EphemeralDataRequestCommand) { handler = new HandleEphemeralDataRequest((EphemeralDataRequestCommand) command); } if (command instanceof ConfirmKeyDataRequestCommand) { handler = new HandleConfirmKeyRequest((ConfirmKeyDataRequestCommand) command); } if (command instanceof TerminateKeyEstablishment) { handler = new HandleTerminateKeyEstablishment((TerminateKeyEstablishment) command); } if (handler != null) { executorService.submit(handler); return true; } return false; } ZclKeyEstablishmentServer(IeeeAddress ieeeAddress, ZclKeyEstablishmentCluster keCluster); void setCbkeProvider(ZigBeeCbkeProvider cbkeProvider); void shutdown(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); ZigBeeCryptoSuites getCryptoSuite(); @Override boolean commandReceived(ZclCommand command);  }