environment.setDescription("Environment that contains the default inspectIT monitoring settings and all default profiles."); try { createEnvironment(environment); } catch (Exception e) { log.error("Error creating default Configuration interface environment on the CMR.", e);
/** * {@inheritDoc} */ @Override public Environment createEnvironment(Environment environment) throws BusinessException { try { return ciManager.createEnvironment(environment); } catch (JAXBException e) { throw new TechnicalException("Create the environment '" + environment.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Create the environment '" + environment.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@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 createEnvironmentCheckExists() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); assertThat(manager.getAllEnvironments(), hasItem(environment)); }
@Test public void updateEnvironment() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); environment.setName("new"); Environment updated = manager.updateEnvironment(environment, false); assertThat(updated.getName(), is("new")); assertThat(updated.getRevision(), is(2)); assertThat(environment.getUpdatedDate(), is(greaterThanOrEqualTo(environment.getCreatedDate()))); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher).publishEvent(captor.capture()); assertThat(captor.getValue(), is(instanceOf(EnvironmentUpdateEvent.class))); }
@Test public void deleteEnvironment() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); manager.deleteEnvironment(environment); assertThat(manager.getAllEnvironments(), not(hasItem(environment))); }
@Test public void updateEnvironmentCheckProfiles() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); environment.setName("new"); Set<String> profiles = new HashSet<>(); profiles.add("non-existing-profile-id"); environment.setProfileIds(profiles); Environment updated = manager.updateEnvironment(environment, true); assertThat(updated.getName(), is("new")); assertThat(updated.getRevision(), is(2)); assertThat(updated.getProfileIds(), is(empty())); }
@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 deleteEnvironmentUpdateMappings() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); AgentMappings mappings = manager.getAgentMappings(); List<AgentMapping> list = new ArrayList<>(); AgentMapping mapping = new AgentMapping("test", "test"); mapping.setEnvironmentId(environment.getId()); list.add(mapping); mappings.setMappings(list); manager.saveAgentMappings(mappings, true); manager.deleteEnvironment(environment); assertThat(manager.getAgentMappings().getMappings(), is(empty())); } }
@Test public void createEnvironmentIncludeDefaults() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setDefaultProfile(true); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); assertThat(environment.getProfileIds(), hasItem(profile.getId())); } }
@Test(expectedExceptions = BusinessException.class) public void updateEnvironmentRevisionFails() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); Environment clone = new Environment(); clone.setId(environment.getId()); manager.updateEnvironment(environment, false); manager.updateEnvironment(clone, false); }
@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())); }
environment = manager.createEnvironment(environment);