IndexerManagerBean implements IIndexerManagerLocal { @Override @RolesAllowed({UserGroupMapping.ADMIN_ROLE_ID, UserGroupMapping.REGULAR_USER_ROLE_ID}) @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) public void createWorkspaceIndex(String workspaceId) throws WorkspaceAlreadyExistsException { try { if(indexManager.indicesExist(workspaceId)){ throw new WorkspaceAlreadyExistsException(workspaceId); } indexManager.createIndices(workspaceId); } catch (IndexerNotAvailableException | IndexerRequestException e) { LOGGER.log(Level.WARNING, "Cannot create index for workspace [" + workspaceId + "]", e); } }  @Override boolean ping(); @Override @RolesAllowed({UserGroupMapping.ADMIN_ROLE_ID, UserGroupMapping.REGULAR_USER_ROLE_ID}) @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) void createWorkspaceIndex(String workspaceId); @Override @RolesAllowed({UserGroupMapping.ADMIN_ROLE_ID, UserGroupMapping.REGULAR_USER_ROLE_ID}) void deleteWorkspaceIndex(String workspaceId); @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) void indexDocumentIteration(DocumentIteration documentIteration); @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) void indexDocumentIterations(List<DocumentIteration> documentIterations); @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) void indexPartIteration(PartIteration partIteration); @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) void indexPartIterations(List<PartIteration> partIterations); @Override @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) void removeDocumentIterationFromIndex(DocumentIteration documentIteration); @Override @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) void removePartIterationFromIndex(PartIteration partIteration); @Override @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) List<DocumentRevision> searchDocumentRevisions(DocumentSearchQuery documentSearchQuery, int from, int size); @Override @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) List<PartRevision> searchPartRevisions(PartSearchQuery partSearchQuery, int from, int size); @Override @RolesAllowed({UserGroupMapping.ADMIN_ROLE_ID}) void indexAllWorkspacesData(); @Override @RolesAllowed({UserGroupMapping.ADMIN_ROLE_ID, UserGroupMapping.REGULAR_USER_ROLE_ID}) void indexWorkspaceData(String workspaceId);  }
@Test public void createWorkspaceIndexTest() throws IndexerNotAvailableException { Mockito.when(indexManager.indicesExist(workspaceId)).thenReturn(true); try { indexerManagerBean.createWorkspaceIndex(workspaceId); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e.getClass().isAssignableFrom(WorkspaceAlreadyExistsException.class)); } Mockito.when(indexManager.indicesExist(workspaceId)).thenReturn(false); try { indexerManagerBean.createWorkspaceIndex(workspaceId); Mockito.verify(indexManager, times(1)).createIndices(workspaceId); } catch (WorkspaceAlreadyExistsException | IndexerNotAvailableException | IndexerRequestException e) { Assert.fail(e.getMessage()); } }