DocumentBaselineManagerBean implements IDocumentBaselineManagerLocal { @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentBaseline createBaseline(String workspaceId, String name, DocumentBaselineType type, String description, List<DocumentRevisionKey> documentRevisionKeys) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, FolderNotFoundException, UserNotActiveException, DocumentRevisionNotFoundException, NotAllowedException, WorkspaceNotEnabledException { User user = userManager.checkWorkspaceWriteAccess(workspaceId); DocumentBaseline baseline = new DocumentBaseline(user, name, type, description); baseline.getDocumentCollection().setCreationDate(new Date()); baseline.getDocumentCollection().setAuthor(user); documentBaselineDAO.createBaseline(baseline); snapshotDocuments(baseline, workspaceId, documentRevisionKeys); if (baseline.getDocumentCollection().getBaselinedDocuments().isEmpty()) { throw new NotAllowedException("NotAllowedException66"); } return baseline; }  @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentBaseline createBaseline(String workspaceId, String name, DocumentBaselineType type, String description, List<DocumentRevisionKey> documentRevisionKeys); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<DocumentBaseline> getBaselines(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteBaseline(String workspaceId, int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentBaseline getBaselineLight(String workspaceId, int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentCollection getACLFilteredDocumentCollection(String workspaceId, int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<BaselinedDocumentBinaryResourceCollection> getBinaryResourcesFromBaseline(String workspaceId, int baselineId);  }
@Test public void shouldNotBaselineAnEmptyCollection() throws Exception { Mockito.when(userManager.checkWorkspaceWriteAccess(workspace.getId())).thenReturn(user); Mockito.when(em.find(Workspace.class, workspace.getId())).thenReturn(workspace); Mockito.when(em.createQuery("SELECT DISTINCT f FROM Folder f WHERE f.parentFolder.completePath = :completePath", Folder.class)).thenReturn(folderTypedQuery); Mockito.when(folderTypedQuery.getResultList()).thenReturn(new ArrayList<>(0)); Mockito.when(workspaceDAO.loadWorkspace(workspace.getId())).thenReturn(workspace); Mockito.when(em.find(Folder.class, workspace.getId())).thenReturn(folder); Mockito.when(documentService.getAllDocumentsInWorkspace(workspace.getId())).thenReturn(new DocumentRevision[0]); try { docBaselineManagerBean.createBaseline(workspace.getId(), "name", DocumentBaselineType.RELEASED, "description", new ArrayList<>()); } catch (NotAllowedException e) { Properties properties = PropertiesLoader.loadLocalizedProperties(user.getLocale(), PROPERTIES_BASE_NAME, getClass()); String expected = properties.getProperty("NotAllowedException66"); Assert.assertEquals(expected, e.getMessage()); } }
@Test public void baselineDocuments() throws Exception { Mockito.when(userManager.checkWorkspaceWriteAccess(workspace.getId())).thenReturn(user); Mockito.when(em.find(Workspace.class, workspace.getId())).thenReturn(workspace); Mockito.when(em.createQuery("SELECT DISTINCT f FROM Folder f WHERE f.parentFolder.completePath = :completePath", Folder.class)).thenReturn(folderTypedQuery); Mockito.when(folderTypedQuery.getResultList()).thenReturn(new ArrayList<>(0)); Mockito.when(workspaceDAO.loadWorkspace(workspace.getId())).thenReturn(workspace); Mockito.when(em.find(Folder.class, workspace.getId())).thenReturn(folder); DocumentRevision[] revisions = new DocumentRevision[2]; DocumentMaster documentMaster1 = new DocumentMaster(workspace, "doc1", user); DocumentMaster documentMaster2 = new DocumentMaster(workspace, "doc2", user); documentMaster1.setId("doc001"); documentMaster2.setId("doc002"); DocumentRevision documentRevision1 = documentMaster1.createNextRevision(user); DocumentRevision documentRevision2 = documentMaster2.createNextRevision(user); revisions[0] = documentRevision2; revisions[1] = documentRevision1; documentRevision1.createNextIteration(user); documentRevision2.createNextIteration(user); documentRevision1.setLocation(folder); documentRevision2.setLocation(folder); Mockito.when(em.find(DocumentRevision.class, documentRevision1.getKey())).thenReturn(documentRevision1); Mockito.when(em.find(DocumentRevision.class, documentRevision2.getKey())).thenReturn(documentRevision2); Mockito.when(documentService.getAllDocumentsInWorkspace(workspace.getId())).thenReturn(revisions); Mockito.when(userManager.checkWorkspaceReadAccess(workspace.getId())).thenReturn(user); Mockito.when(documentRevisionDAO.loadDocR(documentRevision1.getKey())).thenReturn(documentRevision1); Mockito.when(documentRevisionDAO.loadDocR(documentRevision2.getKey())).thenReturn(documentRevision2); List<DocumentRevisionKey> documentRevisionKeys = new ArrayList<>(); documentRevisionKeys.add(new DocumentRevisionKey(workspace.getId(), documentMaster1.getId(), documentMaster1.getLastRevision().getVersion())); documentRevisionKeys.add(new DocumentRevisionKey(workspace.getId(), documentMaster2.getId(), documentMaster2.getLastRevision().getVersion())); DocumentBaseline documentBaseline = docBaselineManagerBean.createBaseline(workspace.getId(), "name", DocumentBaselineType.LATEST, "description", documentRevisionKeys); Assert.assertNotNull(documentBaseline); Assert.assertTrue(documentBaseline.hasBaselinedDocument(documentRevision1.getKey())); Assert.assertTrue(documentBaseline.hasBaselinedDocument(documentRevision2.getKey())); Assert.assertNotNull(documentBaseline.getBaselinedDocument(documentRevision1.getKey())); Assert.assertNotNull(documentBaseline.getBaselinedDocument(documentRevision2.getKey())); }