/** * {@inheritDoc} */ @Override public Environment updateEnvironment(Environment environment) throws BusinessException { try { return ciManager.updateEnvironment(environment, true); } catch (JAXBException e) { throw new TechnicalException("Update the environment '" + environment.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Update the environment '" + environment.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@Test(expectedExceptions = BusinessException.class) public void updateEnvironmentNotExisting() throws Exception { Environment environment = new Environment(); environment.setId("non-existing"); manager.updateEnvironment(environment, false); } }
environment.getProfileIds().remove(id); try { updateEnvironment(environment, false); } catch (Exception e) { log.error("Update of the environment on the profile deletion failed.", e);
@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 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(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); }
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 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())); }