@Test public void keyEstablishmentCallback() throws Exception { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); ZigBeeNetworkManager networkManager = Mockito.mock(ZigBeeNetworkManager.class); Mockito.when(networkManager.getNotificationService()).thenReturn(new NotificationService()); SmartEnergyClient extension = new SmartEnergyClient(Mockito.mock(ZigBeeCbkeProvider.class)); SmartEnergyStatusCallback listener = Mockito.mock(SmartEnergyStatusCallback.class); extension.addListener(listener); ArgumentCaptor<Long> timerCaptor = ArgumentCaptor.forClass(Long.class); Mockito.when(networkManager.scheduleTask(ArgumentMatchers.any(), timerCaptor.capture())) .thenReturn(Mockito.mock(ScheduledFuture.class)); assertEquals(ZigBeeStatus.SUCCESS, extension.extensionInitialize(networkManager)); assertEquals(ZigBeeStatus.SUCCESS, extension.extensionStartup()); TestUtilities.setField(SmartEnergyClient.class, extension, "seState", SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); assertEquals(SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT, extension.getDiscoveryState()); ZigBeeNode node = Mockito.mock(ZigBeeNode.class); Mockito.when(networkManager.getNode(0)).thenReturn(node); Mockito.when(node.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); Mockito.when(node.getNodeState()).thenReturn(ZigBeeNodeState.ONLINE); extension.nodeAdded(node); extension.keyEstablishmentCallback(ZigBeeStatus.SUCCESS, 0); Mockito.verify(listener, Mockito.timeout(TIMEOUT)).sepStatusUpdate(ZigBeeSepClientStatus.INITIALIZING); assertEquals(SmartEnergyClientState.DISCOVER_METERING_SERVERS, extension.getDiscoveryState()); assertEquals(1, timerCaptor.getAllValues().size()); extension.keyEstablishmentCallback(ZigBeeStatus.FATAL_ERROR, 0); Mockito.verify(listener, Mockito.timeout(TIMEOUT)).sepStatusUpdate(ZigBeeSepClientStatus.FATAL_ERROR); assertEquals(1, timerCaptor.getAllValues().size()); extension.keyEstablishmentCallback(ZigBeeStatus.FAILURE, 23); Mockito.verify(listener, Mockito.timeout(TIMEOUT).times(2)).sepStatusUpdate(ZigBeeSepClientStatus.INITIALIZING); assertEquals(SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT, extension.getDiscoveryState()); assertEquals(3, timerCaptor.getAllValues().size()); extension.removeListener(listener); }
protected void keyEstablishmentCallback(ZigBeeStatus returnState, Integer waitTime) { logger.debug("SEP Extension: keyEstablishmentCallback state={}", returnState); if (returnState == ZigBeeStatus.FATAL_ERROR) { updateClientState(SmartEnergyClientState.FATAL); return; } else { updateClientState(returnState == ZigBeeStatus.SUCCESS ? SmartEnergyClientState.DISCOVER_METERING_SERVERS : SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); } int time = TIMER_IMMEDIATE; if (returnState == ZigBeeStatus.FAILURE) { if (waitTime == 0) { time = TIMER_RESTART_KEY_ESTABLISHMENT; } else { time = (waitTime * 1000); } logger.debug("SEP Extension: keyEstablishmentCallback next timer {}ms", time); timerStart(time); } else { setProfileSecurity(networkManager.getNode(0)); } }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { protected void keyEstablishmentCallback(ZigBeeStatus returnState, Integer waitTime) { logger.debug("SEP Extension: keyEstablishmentCallback state={}", returnState); if (returnState == ZigBeeStatus.FATAL_ERROR) { updateClientState(SmartEnergyClientState.FATAL); return; } else { updateClientState(returnState == ZigBeeStatus.SUCCESS ? SmartEnergyClientState.DISCOVER_METERING_SERVERS : SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); } int time = TIMER_IMMEDIATE; if (returnState == ZigBeeStatus.FAILURE) { if (waitTime == 0) { time = TIMER_RESTART_KEY_ESTABLISHMENT; } else { time = (waitTime * 1000); } logger.debug("SEP Extension: keyEstablishmentCallback next timer {}ms", time); timerStart(time); } else { setProfileSecurity(networkManager.getNode(0)); } } }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { protected void keyEstablishmentCallback(ZigBeeStatus returnState, Integer waitTime) { logger.debug("SEP Extension: keyEstablishmentCallback state={}", returnState); if (returnState == ZigBeeStatus.FATAL_ERROR) { updateClientState(SmartEnergyClientState.FATAL); return; } else { updateClientState(returnState == ZigBeeStatus.SUCCESS ? SmartEnergyClientState.DISCOVER_METERING_SERVERS : SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); } int time = TIMER_IMMEDIATE; if (returnState == ZigBeeStatus.FAILURE) { if (waitTime == 0) { time = TIMER_RESTART_KEY_ESTABLISHMENT; } else { time = (waitTime * 1000); } logger.debug("SEP Extension: keyEstablishmentCallback next timer {}ms", time); timerStart(time); } else { setProfileSecurity(networkManager.getNode(0)); } } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { protected void keyEstablishmentCallback(ZigBeeStatus returnState, Integer waitTime) { logger.debug("SEP Extension: keyEstablishmentCallback state={}", returnState); if (returnState == ZigBeeStatus.FATAL_ERROR) { updateClientState(SmartEnergyClientState.FATAL); return; } else { updateClientState(returnState == ZigBeeStatus.SUCCESS ? SmartEnergyClientState.DISCOVER_METERING_SERVERS : SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); } int time = TIMER_IMMEDIATE; if (returnState == ZigBeeStatus.FAILURE) { if (waitTime == 0) { time = TIMER_RESTART_KEY_ESTABLISHMENT; } else { time = (waitTime * 1000); } logger.debug("SEP Extension: keyEstablishmentCallback next timer {}ms", time); timerStart(time); } else { setProfileSecurity(networkManager.getNode(0)); } } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); @Override ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager); @Override ZigBeeStatus extensionStartup(); @Override void extensionShutdown(); ZigBeeCbkeProvider getCbkeProvider(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); void addListener(final SmartEnergyStatusCallback listener); void removeListener(final SmartEnergyStatusCallback listener); void setKeepAlivePeriod(int timeout); Calendar getLastKeepAlive(); ZigBeeStatus startKeyExchange(ZigBeeEndpointAddress endpoint); @Override void commandReceived(ZigBeeCommand command); @Override void networkStateUpdated(ZigBeeNetworkState state); SmartEnergyClientState getDiscoveryState(); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node); }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { protected void keyEstablishmentCallback(ZigBeeStatus returnState, Integer waitTime) { logger.debug("SEP Extension: keyEstablishmentCallback state={}", returnState); if (returnState == ZigBeeStatus.FATAL_ERROR) { updateClientState(SmartEnergyClientState.FATAL); return; } else { updateClientState(returnState == ZigBeeStatus.SUCCESS ? SmartEnergyClientState.DISCOVER_METERING_SERVERS : SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); } int time = TIMER_IMMEDIATE; if (returnState == ZigBeeStatus.FAILURE) { if (waitTime == 0) { time = TIMER_RESTART_KEY_ESTABLISHMENT; } else { time = (waitTime * 1000); } logger.debug("SEP Extension: keyEstablishmentCallback next timer {}ms", time); timerStart(time); } else { setProfileSecurity(networkManager.getNode(0)); } } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); @Override ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager); @Override ZigBeeStatus extensionStartup(); @Override void extensionShutdown(); ZigBeeCbkeProvider getCbkeProvider(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); void addListener(final SmartEnergyStatusCallback listener); void removeListener(final SmartEnergyStatusCallback listener); void setKeepAlivePeriod(int timeout); Calendar getLastKeepAlive(); ZigBeeStatus startKeyExchange(ZigBeeEndpointAddress endpoint); @Override void commandReceived(ZigBeeCommand command); @Override void networkStateUpdated(ZigBeeNetworkState state); SmartEnergyClientState getDiscoveryState(); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node);  }