/** * {@inheritDoc} */ @Override public void deleteProfile(Profile profile) throws BusinessException { try { ciManager.deleteProfile(profile); } catch (IOException e) { throw new TechnicalException("Delete the profile '" + profile.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@Test(expectedExceptions = BusinessException.class) public void deleteCommonProfile() throws Exception { Profile profile = new Profile(); Field f = Profile.class.getDeclaredField("commonProfile"); f.setAccessible(true); f.set(profile, true); manager.deleteProfile(profile); } }
@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 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())); }