/** * {@inheritDoc} */ @Override public Environment getEnvironment(String id) throws BusinessException { return ciManager.getEnvironment(id); }
@Test(expectedExceptions = BusinessException.class) public void getNotExisting() throws Exception { Environment result = manager.getEnvironment("someId"); } }
for (Environment environment : environments) { try { exportedEnvironments.add(getEnvironment(environment.getId())); } catch (BusinessException e) { log.warn("Environment trying to export does not exists.", e);
return configurationInterfaceManager.getEnvironment(environmentId);
@Test(expectedExceptions = { BusinessException.class }) public void inactiveMapping() throws BusinessException { AgentMapping mapping1 = mock(AgentMapping.class); when(agentMappings.getMappings()).thenReturn(Collections.singleton(mapping1)); when(mapping1.getAgentName()).thenReturn("ins*"); when(mapping1.isActive()).thenReturn(false); when(mapping1.getIpAddress()).thenReturn("*"); when(mapping1.getEnvironmentId()).thenReturn("env1"); Environment environment = mock(Environment.class); when(configurationInterfaceManager.getEnvironment("env1")).thenReturn(environment); configurationResolver.getEnvironmentForAgent(definedIPs, agentName); } }
@Test public void createEnvironmentCheckId() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); assertThat(environment.getId(), is(not(nullValue()))); assertThat(environment.getCreatedDate(), is(not(nullValue()))); assertThat(manager.getEnvironment(environment.getId()), is(equalTo(environment))); }
@Test public void importEnvironment() throws Exception { Environment environment = new Environment(); environment.setId("myId"); environment.setName("test"); environment = manager.importEnvironment(environment); assertThat(environment.getId(), is("myId")); assertThat(environment.getImportDate(), is(not(nullValue()))); assertThat(manager.getEnvironment(environment.getId()), is(equalTo(environment))); }
@Test public void oneMatchingMapping() throws BusinessException { AgentMapping mapping1 = mock(AgentMapping.class); AgentMapping mapping2 = mock(AgentMapping.class); List<AgentMapping> mappings = new ArrayList<>(); mappings.add(mapping1); mappings.add(mapping2); when(agentMappings.getMappings()).thenReturn(mappings); when(mapping1.getAgentName()).thenReturn("ins*"); when(mapping1.isActive()).thenReturn(true); when(mapping1.getIpAddress()).thenReturn("*"); when(mapping2.getAgentName()).thenReturn("something else"); when(mapping2.isActive()).thenReturn(true); when(mapping1.getEnvironmentId()).thenReturn("env1"); Environment environment = mock(Environment.class); when(configurationInterfaceManager.getEnvironment("env1")).thenReturn(environment); assertThat(configurationResolver.getEnvironmentForAgent(definedIPs, agentName), is(environment)); }
@Test public void twoMatchingMappings() throws BusinessException { AgentMapping mapping1 = mock(AgentMapping.class); AgentMapping mapping2 = mock(AgentMapping.class); List<AgentMapping> mappings = new ArrayList<>(); mappings.add(mapping1); mappings.add(mapping2); when(agentMappings.getMappings()).thenReturn(mappings); when(mapping1.getAgentName()).thenReturn("inspectit"); when(mapping1.isActive()).thenReturn(true); when(mapping1.getIpAddress()).thenReturn("127.0.0.1"); when(mapping1.getEnvironmentId()).thenReturn("env1"); when(mapping2.getAgentName()).thenReturn("*"); when(mapping2.getIpAddress()).thenReturn("*"); when(mapping2.isActive()).thenReturn(true); when(mapping2.getEnvironmentId()).thenReturn("env2"); Environment environment1 = mock(Environment.class); Environment environment2 = mock(Environment.class); when(configurationInterfaceManager.getEnvironment("env1")).thenReturn(environment1); when(configurationInterfaceManager.getEnvironment("env2")).thenReturn(environment2); configurationResolver.getEnvironmentForAgent(definedIPs, agentName); assertThat(configurationResolver.getEnvironmentForAgent(definedIPs, agentName), is(environment1)); }
@Test public void get() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); Environment result = manager.getEnvironment(environment.getId()); assertThat(result.getId(), is(environment.getId())); }
@Test public void importEnvironemtExists() throws Exception { Environment environment = new Environment(); environment.setName("test"); manager.createEnvironment(environment); Environment importEnvironment = new Environment(); importEnvironment.setId(environment.getId()); importEnvironment.setName("imported"); manager.importEnvironment(importEnvironment); assertThat(manager.getEnvironment(environment.getId()), is(equalTo(importEnvironment))); }
@Test public void deleteProfileRemovedFromEnvironment() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); Environment environment = new Environment(); environment.setName("Test"); environment = manager.createEnvironment(environment); environment.setProfileIds(new HashSet<>(Collections.singleton(profile.getId()))); environment = manager.updateEnvironment(environment, true); when(serializationManager.copy(any(Environment.class))).thenAnswer(new Answer<Environment>() { @Override public Environment answer(InvocationOnMock invocation) throws Throwable { Environment env = (Environment) invocation.getArguments()[0]; Environment copy = new Environment(); copy.setId(env.getId()); copy.setName(env.getName()); copy.setRevision(env.getRevision()); copy.setProfileIds(new HashSet<>(env.getProfileIds())); return copy; } }); manager.deleteProfile(profile); assertThat(manager.getEnvironment(environment.getId()).getProfileIds(), is(not(equalTo(environment.getProfileIds())))); assertThat(manager.getEnvironment(environment.getId()).getProfileIds(), is(empty())); }