/** * {@inheritDoc} */ @Override public AlertingDefinition createAlertingDefinition(AlertingDefinition alertingDefinition) throws BusinessException { try { return ciManager.createAlertingDefinition(alertingDefinition); } catch (JAXBException e) { throw new TechnicalException("Update the alerting definition.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Update the alerting definition.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@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))); }
/** * {@inheritDoc} */ @Override public void deleteAlertingDefinition(AlertingDefinition alertingDefinition) throws BusinessException { try { ciManager.deleteAlertingDefinition(alertingDefinition); } catch (IOException e) { throw new TechnicalException("Delete the alerting definition '" + alertingDefinition.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@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())); }
@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(expectedExceptions = { Exception.class }) public void updateProfileRevisionFails() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); Profile clone = new Profile(); clone.setId(profile.getId()); manager.updateProfile(profile); manager.updateProfile(clone); }
@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 deleteAlertingDefinition() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); manager.deleteAlertingDefinition(alertingDefinition); assertThat(manager.getAlertingDefinitions(), not(hasItem(alertingDefinition))); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher, times(2)).publishEvent(captor.capture()); assertThat(captor.getAllValues().get(0), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionCreatedEvent.class))); assertThat(captor.getAllValues().get(1), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionDeletedEvent.class))); }
@Test public void deleteProfile() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); manager.deleteProfile(profile); assertThat(manager.getAllProfiles(), is(empty())); }
@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 importProfileExists() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); manager.createProfile(profile); Profile importProfile = new Profile(); importProfile.setId(profile.getId()); importProfile.setName("imported"); manager.importProfile(importProfile); assertThat(manager.getProfile(profile.getId()), is(importProfile)); }
profile1.setName("profile1"); profile1.setProfileData(new SensorAssignmentProfileData()); profile1 = manager.createProfile(profile1); Profile profile2 = new Profile(); profile2.setName("profile2"); profile2.setProfileData(new SensorAssignmentProfileData()); profile2 = manager.createProfile(profile2); environment = manager.createEnvironment(environment); Environment updated = manager.updateEnvironment(environment, true); assertThat(updated.getRevision(), is(2)); assertThat(updated.getProfileIds(), hasItem(profile1.getId())); environment.setProfileIds(Collections.singleton(profile2.getId())); updated = manager.updateEnvironment(environment, false);
@Test(expectedExceptions = BusinessException.class) public void getAlertingDefinitionNotExisting() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); AlertingDefinition returnedDefinition = manager.getAlertingDefinition("unknown_id"); } }
@Test public void createAlertingDefinitionExists() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); alertingDefinition = manager.createAlertingDefinition(alertingDefinition); assertThat(manager.getAlertingDefinitions(), hasItem(alertingDefinition)); } }
@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 createProfileCheckId() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); manager.createProfile(profile); assertThat(profile.getId(), is(not(nullValue()))); assertThat(profile.getCreatedDate(), is(not(nullValue()))); assertThat(manager.getAllProfiles(), hasItem(profile)); }
@Test(expectedExceptions = BusinessException.class) public void updateAlertingDefinitionRevisionFailed() throws BusinessException, JAXBException, IOException { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); AlertingDefinition clone = new AlertingDefinition(); clone.setId(alertingDefinition.getId()); manager.updateAlertingDefinition(alertingDefinition); manager.updateAlertingDefinition(clone); }
@Test public void mappings() throws Exception { AgentMappings mappings = manager.getAgentMappings(); List<AgentMapping> list = new ArrayList<>(); AgentMapping mapping = new AgentMapping("test", "test"); list.add(mapping); mappings.setMappings(list); manager.saveAgentMappings(mappings, false); assertThat(mappings.getRevision(), is(2)); }
@Test public void createEnvironmentCheckExists() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); assertThat(manager.getAllEnvironments(), hasItem(environment)); }
AgentMappings agentMappings = configurationInterfaceManager.getAgentMappings(); return configurationInterfaceManager.getEnvironment(environmentId);