Search in sources :

Example 26 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromDocumentLibraryOneFromOneChildFolderAndOneCreated.

@Test
public void testDeclareRecordsFromDocumentLibraryOneFromOneChildFolderAndOneCreated() throws Exception {
    String numberOfRecordsToDeclare = "3";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    String childFileId1 = "childFileId1";
    RestNodeModel mockedOnModel1 = mock(RestNodeModel.class);
    when(mockedOnModel1.getIsFile()).thenReturn(true);
    when(mockedOnModel1.getId()).thenReturn(childFileId1);
    when(mockedOnModel1.getName()).thenReturn("fileName1");
    RestNodeModel mockedFile1 = mock(RestNodeModel.class);
    when(mockedFile1.onModel()).thenReturn(mockedOnModel1);
    String childFileId2 = "childFileId2";
    RestNodeModel mockedOnModel2 = mock(RestNodeModel.class);
    when(mockedOnModel2.getIsFile()).thenReturn(true);
    when(mockedOnModel2.getId()).thenReturn(childFileId2);
    when(mockedOnModel2.getName()).thenReturn("fileName2");
    RestNodeModel mockedFile2 = mock(RestNodeModel.class);
    when(mockedFile2.onModel()).thenReturn(mockedOnModel2);
    String childFolderId1 = "childFolderId1";
    RestNodeModel mockedOnModel3 = mock(RestNodeModel.class);
    when(mockedOnModel3.getIsFile()).thenReturn(false);
    when(mockedOnModel3.getId()).thenReturn(childFolderId1);
    when(mockedOnModel3.getName()).thenReturn("fileName3");
    RestNodeModel mockedFolder1 = mock(RestNodeModel.class);
    when(mockedFolder1.onModel()).thenReturn(mockedOnModel3);
    when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1, mockedFolder1)).thenReturn(Arrays.asList(mockedFile2));
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    // for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nCreated file {0}.Sheduled file to be declared as record: {1}. Sheduled file to be declared as record: {2}. Sheduled file to be declared as record: {3}. Raised further {4} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, fileID, childFileId1, childFileId2, fileID, 3), result.getData());
    assertEquals(4, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(1).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(2).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(3).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) RestNodeModel(org.alfresco.rest.model.RestNodeModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 27 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromTwiDiferentPaths.

@Test
public void testDeclareRecordsFromTwiDiferentPaths() throws Exception {
    String numberOfRecordsToDeclare = "2";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths("path1,path2");
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    String childFileId1 = "childFileId1";
    RestNodeModel mockedOnModel1 = mock(RestNodeModel.class);
    when(mockedOnModel1.getIsFile()).thenReturn(true);
    when(mockedOnModel1.getId()).thenReturn(childFileId1);
    when(mockedOnModel1.getName()).thenReturn("fileName1");
    RestNodeModel mockedFile1 = mock(RestNodeModel.class);
    when(mockedFile1.onModel()).thenReturn(mockedOnModel1);
    String childFileId2 = "childFileId2";
    RestNodeModel mockedOnModel2 = mock(RestNodeModel.class);
    when(mockedOnModel2.getIsFile()).thenReturn(true);
    when(mockedOnModel2.getId()).thenReturn(childFileId2);
    when(mockedOnModel2.getName()).thenReturn("fileName2");
    RestNodeModel mockedFile2 = mock(RestNodeModel.class);
    when(mockedFile2.onModel()).thenReturn(mockedOnModel2);
    when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1)).thenReturn(Arrays.asList(mockedFile2));
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nSheduled file to be declared as record: {0}. Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, childFileId1, childFileId2, 2), result.getData());
    assertEquals(3, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(1).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(2).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) RestNodeModel(org.alfresco.rest.model.RestNodeModel) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 28 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testCreateSiteMember.

@Test
public void testCreateSiteMember() throws Exception {
    String userName = "user1";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
    when(mockedEvent.getData()).thenReturn(mockedData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getCreationState()).thenReturn(DataCreationState.Scheduled);
    when(mockedSiteMemberData.getRole()).thenReturn(RMRole.Administrator.toString());
    when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(mockedSiteMemberData);
    RMUserAPI mockedRMUserAPI = mock(RMUserAPI.class);
    when(mockedRestAPIFactory.getRMUserAPI()).thenReturn(mockedRMUserAPI);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_MISSING_MSG_TEMPLATE, userName));
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_ALREADY_PROCESSED_MSG_TEMPLATE, mockedSiteMemberData));
    verify(mockedRMUserAPI, times(1)).assignRoleToUser(userName, RMRole.Administrator.toString());
    verify(mockedSiteDataService, times(1)).setSiteMemberCreationState(PATH_SNIPPET_RM_SITE_ID, userName, DataCreationState.Created);
    verify(mockedSiteDataService, times(2)).getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName);
    assertEquals(true, result.isSuccess());
    String data = (String) result.getData();
    assertTrue(data.startsWith(CREATED_RM_SITE_MEMBER_MSG));
    assertEquals(1, result.getNextEvents().size());
    assertEquals(createRMSiteMember.getEventNameRMSiteMemberCreated(), result.getNextEvents().get(0).getName());
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMUserAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 29 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testWithNullUsername.

@Test
public void testWithNullUsername() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(null);
    when(mockedEvent.getData()).thenReturn(mockedData);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data);
}
Also used : EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 30 with EventResult

use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.

the class CreateRMSiteMemberUnitTest method testAlreadyProcessedSiteMember.

@Test
public void testAlreadyProcessedSiteMember() throws Exception {
    String userName = "user1";
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
    when(mockedEvent.getData()).thenReturn(mockedData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getCreationState()).thenReturn(DataCreationState.Created);
    when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(mockedSiteMemberData);
    EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
    verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_MISSING_MSG_TEMPLATE, userName));
    verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_ALREADY_PROCESSED_MSG_TEMPLATE, mockedSiteMemberData));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data);
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

EventResult (org.alfresco.bm.event.EventResult)133 Test (org.junit.Test)119 Event (org.alfresco.bm.event.Event)109 DBObject (com.mongodb.DBObject)101 StopWatch (org.apache.commons.lang3.time.StopWatch)97 FolderData (org.alfresco.bm.cm.FolderData)77 UserModel (org.alfresco.utility.model.UserModel)35 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 SiteData (org.alfresco.bm.site.SiteData)20 SiteMemberData (org.alfresco.bm.site.SiteMemberData)17 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)15 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)14 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)12 UserData (org.alfresco.bm.user.UserData)11 Node (org.alfresco.rest.requests.Node)10 Site (org.alfresco.rest.requests.Site)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)9 RestWrapper (org.alfresco.rest.core.RestWrapper)8