@Test(expectedExceptions = BusinessException.class) public void updateCommonProfile() throws Exception { Profile profile = new Profile(); Field f = Profile.class.getDeclaredField("commonProfile"); f.setAccessible(true); f.set(profile, true); manager.updateProfile(profile); }
@Test(expectedExceptions = BusinessException.class) public void updateProfileNotExisting() throws Exception { Profile profile = new Profile(); profile.setId("non-existing"); manager.updateProfile(profile); } }
/** * {@inheritDoc} */ @Override public Profile updateProfile(Profile profile) throws BusinessException { try { return ciManager.updateProfile(profile); } catch (JAXBException e) { throw new TechnicalException("Update the profile '" + profile.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Update the profile '" + profile.getName() + "'.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@Test public void updateProfile() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); profile.setName("new"); Profile updated = manager.updateProfile(profile); assertThat(updated.getName(), is("new")); assertThat(updated.getRevision(), is(2)); assertThat(updated.getUpdatedDate(), is(greaterThanOrEqualTo(updated.getCreatedDate()))); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher).publishEvent(captor.capture()); assertThat(captor.getValue(), is(instanceOf(ProfileUpdateEvent.class))); }
@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 public void updateProfileMethodAssignmentsChange() throws Exception { MethodSensorAssignment methodSensorAssignment1 = mock(MethodSensorAssignment.class); MethodSensorAssignment methodSensorAssignment2 = mock(MethodSensorAssignment.class); Profile profile = new Profile(); profile.setName("test"); SensorAssignmentProfileData profileData = new SensorAssignmentProfileData(); profileData.setMethodSensorAssignments(Collections.singletonList(methodSensorAssignment1)); profile.setProfileData(profileData); Profile created = manager.createProfile(profile); assertThat((Collection<MethodSensorAssignment>) profile.getProfileData().getData(SensorAssignmentProfileData.class), hasItem(methodSensorAssignment1)); profile = new Profile(); profile.setId(created.getId()); profile.setRevision(created.getRevision()); profile.setName(created.getName()); profileData = new SensorAssignmentProfileData(); profileData.setMethodSensorAssignments(Collections.singletonList(methodSensorAssignment2)); profile.setProfileData(profileData); Profile updated = manager.updateProfile(profile); assertThat((Collection<MethodSensorAssignment>) profile.getProfileData().getData(SensorAssignmentProfileData.class), hasItem(methodSensorAssignment2)); assertThat(updated.getRevision(), is(2)); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher).publishEvent(captor.capture()); assertThat(captor.getValue(), is(instanceOf(ProfileUpdateEvent.class))); ProfileUpdateEvent profileUpdateEvent = (ProfileUpdateEvent) captor.getValue(); assertThat(profileUpdateEvent.getRemovedSensorAssignments(), hasItem(methodSensorAssignment1)); assertThat(profileUpdateEvent.getAddedSensorAssignments(), hasItem(methodSensorAssignment2)); }
@Test public void updateProfileExceptionAssignmentsChange() throws Exception { ExceptionSensorAssignment exceptionSensorAssignment1 = mock(ExceptionSensorAssignment.class); ExceptionSensorAssignment exceptionSensorAssignment2 = mock(ExceptionSensorAssignment.class); Profile profile = new Profile(); profile.setName("test"); SensorAssignmentProfileData profileData = new SensorAssignmentProfileData(); profileData.setExceptionSensorAssignments(Collections.singletonList(exceptionSensorAssignment1)); profile.setProfileData(profileData); Profile created = manager.createProfile(profile); assertThat((Collection<ExceptionSensorAssignment>) profile.getProfileData().getData(SensorAssignmentProfileData.class), hasItem(exceptionSensorAssignment1)); profile = new Profile(); profile.setId(created.getId()); profile.setRevision(created.getRevision()); profile.setName(created.getName()); profileData = new SensorAssignmentProfileData(); profileData.setExceptionSensorAssignments(Collections.singletonList(exceptionSensorAssignment2)); profile.setProfileData(profileData); Profile updated = manager.updateProfile(profile); assertThat((Collection<ExceptionSensorAssignment>) profile.getProfileData().getData(SensorAssignmentProfileData.class), hasItem(exceptionSensorAssignment2)); assertThat(updated.getRevision(), is(2)); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher).publishEvent(captor.capture()); assertThat(captor.getValue(), is(instanceOf(ProfileUpdateEvent.class))); ProfileUpdateEvent profileUpdateEvent = (ProfileUpdateEvent) captor.getValue(); assertThat(profileUpdateEvent.getRemovedSensorAssignments(), hasItem(exceptionSensorAssignment1)); assertThat(profileUpdateEvent.getAddedSensorAssignments(), hasItem(exceptionSensorAssignment2)); }