use of org.springframework.data.history.Revision in project JavaForFun by gumartinm.
the class AdDescriptionRevisionServiceShould method test.
@Test
public void test() {
AdDescriptionRepository adDescriptionRepository = mock(AdDescriptionRepository.class);
AdDescriptionRevisionServiceImpl adDescriptionRevisionService = new AdDescriptionRevisionServiceImpl();
adDescriptionRevisionService.setRepository(adDescriptionRepository);
List<Revision<Integer, AdDescription>> adRevisions = new ArrayList<>();
Pageable pageRequest = new PageRequest(0, 1);
Page<Revision<Integer, AdDescription>> page = new PageImpl<>(adRevisions);
given(adDescriptionRepository.findRevisions(1L, pageRequest)).willReturn(page);
assertThat(adDescriptionRevisionService.findRevisions(1L, pageRequest), is(page));
}
use of org.springframework.data.history.Revision in project irida by phac-nml.
the class UserServiceImplTest method testUpdateExistingPassword.
@Test(expected = PasswordReusedException.class)
public void testUpdateExistingPassword() {
String password = "Password1";
String oldPassword = "oldPassword";
String encodedPassword = password + "_ENCODED";
User revUser = new User();
revUser.setPassword(oldPassword);
Revision<Integer, User> rev = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime();
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(passwordEncoder.encode(password)).thenReturn(encodedPassword);
when(passwordEncoder.matches(password, oldPassword)).thenReturn(true);
when(userRepository.exists(1L)).thenReturn(true);
when(userRepository.findOne(1L)).thenReturn(user());
when(userRepository.findRevisions(1L)).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(rev)));
userService.changePassword(1L, password);
verify(userRepository, times(0)).save(any(User.class));
}
use of org.springframework.data.history.Revision in project irida by phac-nml.
the class ProjectServiceImplIT method testGetAllProjectRevisions.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetAllProjectRevisions() {
final String modifiedName = "creates a new revision";
final String modifiedDesc = "another new revision";
final Project p = projectService.read(1L);
p.setName(modifiedName);
projectService.update(p);
p.setProjectDescription(modifiedDesc);
projectService.update(p);
// reverse the order so that the latest revision is first in the list.
final Revisions<Integer, Project> revisions = projectService.findRevisions(1L).reverse();
assertEquals("Should have 2 revisions.", 2, revisions.getContent().size());
final Iterator<Revision<Integer, Project>> iterator = revisions.iterator();
final Revision<Integer, Project> mostRecent = iterator.next();
assertEquals("most recent revision should have project description change.", modifiedDesc, mostRecent.getEntity().getProjectDescription());
assertEquals("most recent revision should also have name changed.", modifiedName, mostRecent.getEntity().getName());
final Revision<Integer, Project> secondRecent = iterator.next();
assertEquals("second most recent revision should have modified name.", modifiedName, secondRecent.getEntity().getName());
assertNotEquals("second most recent revision should *not* have modified description.", modifiedDesc, secondRecent.getEntity().getProjectDescription());
}
use of org.springframework.data.history.Revision in project irida by phac-nml.
the class PasswordExpiryCheckerTest method testExpiredPassword.
@Test(expected = CredentialsExpiredException.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testExpiredPassword() {
user.setPassword("password1");
revUser.setPassword("password1");
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -10);
Date expiryDate = cal.getTime();
Revision<Integer, User> revision = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime(expiryDate.getTime());
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(userRepository.findRevisions(user.getId())).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(revision)));
checker.check(user);
verify(userRepository).findRevisions(user.getId());
}
use of org.springframework.data.history.Revision in project irida by phac-nml.
the class PasswordExpiryCheckerTest method testChangedPassword.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testChangedPassword() {
user.setPassword("password1");
revUser.setPassword("password2");
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -10);
Date expiryDate = cal.getTime();
Revision<Integer, User> revision = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime(expiryDate.getTime());
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(userRepository.findRevisions(user.getId())).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(revision)));
checker.check(user);
verify(userRepository).findRevisions(user.getId());
}
Aggregations