public List<Version> recreateVersions() { versionRepository.deleteAll(); userRepository.deleteAll(); User user = userRepository.saveAndFlush(new User("admin", "admin", "*****@*****.**")); Date now = new Date(); Meta meta = new Meta(); meta.setDefaultVersionNo(3); meta.setDisabledLanguageShowMode(Meta.DisabledLanguageShowMode.SHOW_IN_DEFAULT_LANGUAGE); meta.setDocumentType(1); meta.setCreatorId(1); meta.setRestrictedOneMorePrivilegedThanRestrictedTwo(true); meta.setLinkableByOtherUsers(true); meta.setLinkedForUnauthorizedUsers(true); meta.setCreatedDatetime(new Date()); meta.setModifiedDatetime(new Date()); meta.setTarget("_blank"); userId = user.getId(); docId = metaRepository.save(meta).getId(); return Arrays.asList( versionRepository.saveAndFlush(new Version(docId, 0, user, now, user, now)), versionRepository.saveAndFlush(new Version(docId, 1, user, now, user, now)), versionRepository.saveAndFlush(new Version(docId, 2, user, now, user, now)), versionRepository.saveAndFlush(new Version(docId, 3, user, now, user, now)), versionRepository.saveAndFlush(new Version(docId, 4, user, now, user, now)), versionRepository.saveAndFlush(new Version(docId, 5, user, now, user, now))); }
@Test public void testCreate() { recreateVersions(); Version version = versionRepository.create(docId, userId); assertNotNull(version); assertThat(version.getDocId(), is(docId)); assertThat(version.getNo(), is(6)); assertThat(version.getCreatedBy(), equalTo(userRepository.findOne(userId))); }
@Test public void testSetDefault() { recreateVersions(); assertThat(versionRepository.findDefault(docId).getNo(), is(3)); versionRepository.updateDefaultNo(docId, 4, userId); Version version = versionRepository.findDefault(docId); assertNotNull(version); assertThat(version.getDocId(), is(docId)); assertThat(version.getNo(), is(4)); assertThat(version.getModifiedBy(), equalTo(userRepository.findOne(userId))); }