@Test public void initialize() throws Exception { TestUtilities.outputTestHeader(); ZigBeeNetworkManager manager = mockZigBeeNetworkManager(); Mockito.when(mockedTransport.initialize()).thenReturn(ZigBeeStatus.COMMUNICATION_ERROR); ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class); Mockito.when(transport.initialize()).thenReturn(ZigBeeStatus.COMMUNICATION_ERROR); ZigBeeNetworkDatabaseManager databaseManager = Mockito.mock(ZigBeeNetworkDatabaseManager.class); TestUtilities.setField(ZigBeeNetworkManager.class, manager, "databaseManager", databaseManager); ZigBeeNetworkDataStore dataStore = Mockito.mock(ZigBeeNetworkDataStore.class); manager.setNetworkDataStore(dataStore); Mockito.verify(databaseManager, Mockito.times(1)).setDataStore(dataStore); assertEquals(ZigBeeStatus.COMMUNICATION_ERROR, manager.initialize()); Mockito.verify(databaseManager, Mockito.times(1)).startup(); Mockito.when(mockedTransport.initialize()).thenReturn(ZigBeeStatus.SUCCESS); Mockito.when(mockedTransport.getNwkAddress()).thenReturn(Integer.valueOf(123)); Mockito.when(mockedTransport.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); manager = mockZigBeeNetworkManager(); Mockito.when(mockedTransport.initialize()).thenReturn(ZigBeeStatus.SUCCESS); Mockito.when(mockedTransport.getNwkAddress()).thenReturn(Integer.valueOf(123)); Mockito.when(mockedTransport.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); Mockito.when(transport.initialize()).thenReturn(ZigBeeStatus.SUCCESS); Mockito.when(transport.getNwkAddress()).thenReturn(Integer.valueOf(123)); Mockito.when(transport.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); Mockito.when(mockedTransport.initialize()).thenReturn(ZigBeeStatus.SUCCESS); Mockito.when(mockedTransport.getNwkAddress()).thenReturn(Integer.valueOf(123)); Mockito.when(mockedTransport.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); databaseManager = Mockito.mock(ZigBeeNetworkDatabaseManager.class); TestUtilities.setField(ZigBeeNetworkManager.class, manager, "databaseManager", databaseManager); assertEquals(ZigBeeStatus.SUCCESS, manager.initialize()); Mockito.verify(databaseManager, Mockito.times(1)).startup(); TestUtilities.setField(ZigBeeNetworkManager.class, manager, "networkState", ZigBeeNetworkState.INITIALISING); assertEquals(ZigBeeStatus.INVALID_STATE, manager.initialize()); Mockito.verify(mockedStateListener, Mockito.timeout(TIMEOUT).atLeast(1)) .networkStateUpdated(ZigBeeNetworkState.INITIALISING); assertEquals(ZigBeeNetworkState.INITIALISING, manager.getNetworkState()); manager.shutdown(); Mockito.verify(mockedTransport, Mockito.timeout(TIMEOUT).times(1)).shutdown(); Mockito.verify(databaseManager, Mockito.times(1)).shutdown(); Mockito.verify(mockedStateListener, Mockito.timeout(TIMEOUT).atLeast(1)) .networkStateUpdated(ZigBeeNetworkState.SHUTDOWN); assertEquals(ZigBeeNetworkState.SHUTDOWN, manager.getNetworkState()); }
public ZigBeeStatus initialize() { logger.debug("ZigBeeNetworkManager initialize: networkState={}", networkState); synchronized (this) { if (networkState != ZigBeeNetworkState.UNINITIALISED) { return ZigBeeStatus.INVALID_STATE; } setNetworkState(ZigBeeNetworkState.INITIALISING); } databaseManager.startup(); ZigBeeStatus transportResponse = transport.initialize(); if (transportResponse != ZigBeeStatus.SUCCESS) { setNetworkState(ZigBeeNetworkState.OFFLINE); return transportResponse; } localIeeeAddress = transport.getIeeeAddress(); return ZigBeeStatus.SUCCESS; }
ZigBeeNetworkManager implements ZigBeeTransportReceive { public ZigBeeStatus initialize() { logger.debug("ZigBeeNetworkManager initialize: networkState={}", networkState); synchronized (this) { if (networkState != ZigBeeNetworkState.UNINITIALISED) { return ZigBeeStatus.INVALID_STATE; } setNetworkState(ZigBeeNetworkState.INITIALISING); } databaseManager.startup(); ZigBeeStatus transportResponse = transport.initialize(); if (transportResponse != ZigBeeStatus.SUCCESS) { setNetworkState(ZigBeeNetworkState.OFFLINE); return transportResponse; } localIeeeAddress = transport.getIeeeAddress(); return ZigBeeStatus.SUCCESS; } }
ZigBeeNetworkManager implements ZigBeeTransportReceive { public ZigBeeStatus initialize() { logger.debug("ZigBeeNetworkManager initialize: networkState={}", networkState); synchronized (this) { if (networkState != ZigBeeNetworkState.UNINITIALISED) { return ZigBeeStatus.INVALID_STATE; } setNetworkState(ZigBeeNetworkState.INITIALISING); } databaseManager.startup(); ZigBeeStatus transportResponse = transport.initialize(); if (transportResponse != ZigBeeStatus.SUCCESS) { setNetworkState(ZigBeeNetworkState.OFFLINE); return transportResponse; } localIeeeAddress = transport.getIeeeAddress(); return ZigBeeStatus.SUCCESS; } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); }
ZigBeeNetworkManager implements ZigBeeTransportReceive { public ZigBeeStatus initialize() { logger.debug("ZigBeeNetworkManager initialize: networkState={}", networkState); synchronized (this) { if (networkState != ZigBeeNetworkState.UNINITIALISED) { return ZigBeeStatus.INVALID_STATE; } setNetworkState(ZigBeeNetworkState.INITIALISING); } databaseManager.startup(); ZigBeeStatus transportResponse = transport.initialize(); if (transportResponse != ZigBeeStatus.SUCCESS) { setNetworkState(ZigBeeNetworkState.OFFLINE); return transportResponse; } localIeeeAddress = transport.getIeeeAddress(); return ZigBeeStatus.SUCCESS; } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); void setNetworkDataStore(ZigBeeNetworkDataStore dataStore); void serializeNetworkDataStore(IeeeAddress nodeAddress); @SuppressWarnings("unchecked") void setSerializer(Class<?> serializer, Class<?> deserializer); void setLocalEndpointId(int localEndpointId); ZigBeeStatus initialize(); ZigBeeTransportTransmit getZigBeeTransport(); ZigBeeChannel getZigBeeChannel(); ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); int getZigBeePanId(); ZigBeeStatus setZigBeePanId(int panId); ExtendedPanId getZigBeeExtendedPanId(); ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId panId); ZigBeeStatus setDefaultProfileId(int defaultProfileId); ZigBeeStatus setDefaultDeviceId(int defaultDeviceId); ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); ZigBeeKey getZigBeeNetworkKey(); ZigBeeStatus setZigBeeLinkKey(final ZigBeeKey key); ZigBeeKey getZigBeeLinkKey(); ZigBeeStatus setZigBeeInstallKey(final ZigBeeKey key); ZigBeeStatus startup(boolean reinitialize); ZigBeeStatus reinitialize(); void shutdown(); void executeTask(Runnable runnableTask); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long delay); ScheduledFuture<?> rescheduleTask(ScheduledFuture<?> futureTask, Runnable runnableTask, long delay); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long initialDelay, long period); String getTransportVersionString(); boolean sendCommand(ZigBeeCommand command); void addCommandListener(ZigBeeCommandListener commandListener); void removeCommandListener(ZigBeeCommandListener commandListener); @Override void receiveCommand(final ZigBeeApsFrame incomingApsFrame); void createDefaultResponse(ZigBeeApsFrame apsFrame, ZclHeader zclHeader, ZclStatus status); void addAnnounceListener(ZigBeeAnnounceListener announceListener); void removeAnnounceListener(ZigBeeAnnounceListener announceListener); @Override void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress,
            final IeeeAddress ieeeAddress); void addNetworkStateListener(ZigBeeNetworkStateListener stateListener); void removeNetworkStateListener(ZigBeeNetworkStateListener stateListener); @Override synchronized void setTransportState(final ZigBeeTransportState state); ZigBeeStatus permitJoin(final int duration); ZigBeeStatus permitJoin(final ZigBeeEndpointAddress destination, final int duration); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress, boolean forceNodeRemoval); void addGroup(final ZigBeeGroupAddress group); void updateGroup(ZigBeeGroupAddress group); ZigBeeGroupAddress getGroup(final int groupId); void removeGroup(final int groupId); List<ZigBeeGroupAddress> getGroups(); void addNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void removeNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void rediscoverNode(IeeeAddress address); Set<ZigBeeNode> getNodes(); ZigBeeNode getNode(final Integer networkAddress); ZigBeeNode getNode(final IeeeAddress ieeeAddress); void removeNode(final ZigBeeNode node); void updateNode(final ZigBeeNode node); @Deprecated void addSupportedCluster(int cluster); ZigBeeStatus addSupportedClientCluster(int cluster); ZigBeeStatus addSupportedServerCluster(int cluster); boolean isClientClusterSupported(int cluster); boolean isServerClusterSupported(int cluster); ZigBeeStatus addExtension(ZigBeeNetworkExtension extension); ZigBeeNetworkExtension getExtension(Class<T> requestedExtension); ZigBeeNetworkState getNetworkState(); IeeeAddress getLocalIeeeAddress(); Integer getLocalNwkAddress(); NotificationService getNotificationService(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); @Override void receiveCommandState(int msgTag, ZigBeeTransportProgressState state); }
ZigBeeNetworkManager implements ZigBeeTransportReceive { public ZigBeeStatus initialize() { logger.debug("ZigBeeNetworkManager initialize: networkState={}", networkState); synchronized (this) { if (networkState != ZigBeeNetworkState.UNINITIALISED) { return ZigBeeStatus.INVALID_STATE; } setNetworkState(ZigBeeNetworkState.INITIALISING); } databaseManager.startup(); ZigBeeStatus transportResponse = transport.initialize(); if (transportResponse != ZigBeeStatus.SUCCESS) { setNetworkState(ZigBeeNetworkState.OFFLINE); return transportResponse; } localIeeeAddress = transport.getIeeeAddress(); return ZigBeeStatus.SUCCESS; } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); void setNetworkDataStore(ZigBeeNetworkDataStore dataStore); void serializeNetworkDataStore(IeeeAddress nodeAddress); @SuppressWarnings("unchecked") void setSerializer(Class<?> serializer, Class<?> deserializer); void setLocalEndpointId(int localEndpointId); ZigBeeStatus initialize(); ZigBeeTransportTransmit getZigBeeTransport(); ZigBeeChannel getZigBeeChannel(); ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); int getZigBeePanId(); ZigBeeStatus setZigBeePanId(int panId); ExtendedPanId getZigBeeExtendedPanId(); ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId panId); ZigBeeStatus setDefaultProfileId(int defaultProfileId); ZigBeeStatus setDefaultDeviceId(int defaultDeviceId); ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); ZigBeeKey getZigBeeNetworkKey(); ZigBeeStatus setZigBeeLinkKey(final ZigBeeKey key); ZigBeeKey getZigBeeLinkKey(); ZigBeeStatus setZigBeeInstallKey(final ZigBeeKey key); ZigBeeStatus startup(boolean reinitialize); ZigBeeStatus reinitialize(); void shutdown(); void executeTask(Runnable runnableTask); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long delay); ScheduledFuture<?> rescheduleTask(ScheduledFuture<?> futureTask, Runnable runnableTask, long delay); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long initialDelay, long period); String getTransportVersionString(); boolean sendCommand(ZigBeeCommand command); void addCommandListener(ZigBeeCommandListener commandListener); void removeCommandListener(ZigBeeCommandListener commandListener); @Override void receiveCommand(final ZigBeeApsFrame incomingApsFrame); void createDefaultResponse(ZigBeeApsFrame apsFrame, ZclHeader zclHeader, ZclStatus status); void addAnnounceListener(ZigBeeAnnounceListener announceListener); void removeAnnounceListener(ZigBeeAnnounceListener announceListener); @Override void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress,
            final IeeeAddress ieeeAddress); void addNetworkStateListener(ZigBeeNetworkStateListener stateListener); void removeNetworkStateListener(ZigBeeNetworkStateListener stateListener); @Override synchronized void setTransportState(final ZigBeeTransportState state); ZigBeeStatus permitJoin(final int duration); ZigBeeStatus permitJoin(final ZigBeeEndpointAddress destination, final int duration); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress, boolean forceNodeRemoval); void addGroup(final ZigBeeGroupAddress group); void updateGroup(ZigBeeGroupAddress group); ZigBeeGroupAddress getGroup(final int groupId); void removeGroup(final int groupId); List<ZigBeeGroupAddress> getGroups(); void addNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void removeNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void rediscoverNode(IeeeAddress address); Set<ZigBeeNode> getNodes(); ZigBeeNode getNode(final Integer networkAddress); ZigBeeNode getNode(final IeeeAddress ieeeAddress); void removeNode(final ZigBeeNode node); void updateNode(final ZigBeeNode node); @Deprecated void addSupportedCluster(int cluster); ZigBeeStatus addSupportedClientCluster(int cluster); ZigBeeStatus addSupportedServerCluster(int cluster); boolean isClientClusterSupported(int cluster); boolean isServerClusterSupported(int cluster); ZigBeeStatus addExtension(ZigBeeNetworkExtension extension); ZigBeeNetworkExtension getExtension(Class<T> requestedExtension); ZigBeeNetworkState getNetworkState(); IeeeAddress getLocalIeeeAddress(); Integer getLocalNwkAddress(); NotificationService getNotificationService(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); @Override void receiveCommandState(int msgTag, ZigBeeTransportProgressState state);  }