Search in sources :

Example 1 with Revision

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));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Revision(org.springframework.data.history.Revision) ArrayList(java.util.ArrayList) AdDescriptionRepository(de.spring.example.persistence.repository.AdDescriptionRepository) Test(org.junit.Test)

Example 2 with Revision

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));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Revision(org.springframework.data.history.Revision) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with Revision

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Revision(org.springframework.data.history.Revision) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 4 with Revision

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Revision(org.springframework.data.history.Revision) Test(org.junit.Test)

Example 5 with Revision

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Revision(org.springframework.data.history.Revision) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Revision (org.springframework.data.history.Revision)7 User (ca.corefacility.bioinformatics.irida.model.user.User)4 DateTime (org.joda.time.DateTime)4 RevisionMetadata (org.springframework.data.history.RevisionMetadata)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3 Project (ca.corefacility.bioinformatics.irida.model.project.Project)2 PageRequest (org.springframework.data.domain.PageRequest)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 AdDescriptionRepository (de.spring.example.persistence.repository.AdDescriptionRepository)1 ArrayList (java.util.ArrayList)1 PageImpl (org.springframework.data.domain.PageImpl)1 Pageable (org.springframework.data.domain.Pageable)1