/** * Test that unregister will not be called if there is no active connection to the server * and registration is not done at first place. */ @Test public void noUnregisterPlatform() throws Exception { // no unregister if no connection when(connection.isConnected()).thenReturn(false); platformManager.unregisterPlatform(); // no unregister if registration is not done at the first place when(connection.isConnected()).thenReturn(true); platformManager.unregisterPlatform(); verify(connection, times(0)).unregister(anyLong()); }
/** * Tests that unregister of platform is executed if connection to the server is established * and registration is performed. */ @Test public void unregisterPlatform() throws Exception { // first simulate connect long fakePlatformId = 3L; when(connection.isConnected()).thenReturn(true); when(configurationStorage.getAgentName()).thenReturn("testAgent"); when(versionService.getVersionAsString()).thenReturn("dummyVersion"); when(connection.register("testAgent", "dummyVersion")).thenReturn(agentConfiguration); when(agentConfiguration.getPlatformId()).thenReturn(fakePlatformId); platformManager.afterPropertiesSet(); platformManager.getPlatformId(); platformManager.unregisterPlatform(); verify(connection, times(1)).unregister(fakePlatformId); verify(connection, times(1)).disconnect(); }