@Test public void retrievePlatformId() throws Exception { 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(); long platformId = platformManager.getPlatformId(); assertThat(platformId, is(equalTo(fakePlatformId))); verify(connection, times(0)).connect(anyString(), anyInt()); }
@Test public void connectAndRetrievePlatformId() throws Exception { String host = "localhost"; int port = 1099; RepositoryConfig repositoryConfig = mock(RepositoryConfig.class); when(repositoryConfig.getHost()).thenReturn(host); when(repositoryConfig.getPort()).thenReturn(port); when(configurationStorage.getRepositoryConfig()).thenReturn(repositoryConfig); when(configurationStorage.getAgentName()).thenReturn("testAgent"); when(versionService.getVersionAsString()).thenReturn("dummyVersion"); long fakePlatformId = 7L; when(connection.isConnected()).thenReturn(false); when(connection.register("testAgent", "dummyVersion")).thenReturn(agentConfiguration); when(agentConfiguration.getPlatformId()).thenReturn(fakePlatformId); platformManager.afterPropertiesSet(); long platformId = platformManager.getPlatformId(); assertThat(platformId, is(equalTo(fakePlatformId))); verify(connection, times(1)).connect(host, port); }
/** * 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(); }
when(platformManager.getPlatformId()).thenReturn(platformId); verify(platformManager).getPlatformId();
when(platformManager.getPlatformId()).thenReturn(platformId); verify(timer, times(3)).getCurrentTime(); statementHook2.secondAfterBody(coreService, methodId, sensorTypeId, object, parameters, result, false, registeredSensorConfig); verify(platformManager).getPlatformId(); verify(platformManager, times(2)).getPlatformId();