Search in sources :

Example 6 with Revision

use of org.springframework.data.history.Revision in project irida by phac-nml.

the class PasswordExpiryCheckerTest method testNonExpiredLogin.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testNonExpiredLogin() {
    Date today = new Date();
    Calendar cal = new GregorianCalendar();
    cal.setTime(today);
    cal.add(Calendar.DAY_OF_MONTH, -1);
    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 7 with Revision

use of org.springframework.data.history.Revision in project irida by phac-nml.

the class ProjectServiceImplIT method testGetPagedProjectRevisions.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetPagedProjectRevisions() {
    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 Page<Revision<Integer, Project>> revisions = projectService.findRevisions(1L, new PageRequest(1, 1));
    assertEquals("Should have 2 revisions.", 1, revisions.getContent().size());
    final Revision<Integer, Project> mostRecent = revisions.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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) Revision(org.springframework.data.history.Revision) WithMockUser(org.springframework.security.test.context.support.WithMockUser) 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