use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromDocumentLibrary.
@Test
public void testDeclareRecordsFromDocumentLibrary() 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(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);
when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1, 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());
}
use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteDoesNotExistsAndLoadedInDb.
@Test
public void testDeclareRecordsColabSiteDoesNotExistsAndLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
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(null);
when(mockedSite.createSite()).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_NOT_FOUND));
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);
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, times(1)).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}. Raised further {2} events and rescheduled self.";
assertEquals(MessageFormat.format(template, fileID, fileID, 1), result.getData());
assertEquals(2, result.getNextEvents().size());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(1).getName());
}
use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareAllExistingFiles.
/**
* Given the collaboration site exists and contains undeclared files with the following structure
* - documentLibrary
* - file1
* - file2
* - folder
* - file3
* - file4
* When running the scheduler with numberOfRecordsToDeclare=0
* Then all existing files should be scheduled for declaring
*
* @throws Exception
*/
@Test
public void testDeclareAllExistingFiles() throws Exception {
String file1Id = "file1_id";
String file2Id = "file2_id";
String folderId = "folder_id";
String file3Id = "file3_id";
String file4Id = "file4_id";
/*
* Given
*/
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(8);
scheduleInPlaceRecordLoaders.setCollabSiteId(DEFAULT_COLLABORATION_SITE_ID);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit("0");
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
// mock the collaboration site
RestCoreAPI mockedCoreApi = mockCoreApi();
Site collabSite = mockSitesEndpoint(mockedCoreApi, DEFAULT_COLLABORATION_SITE_ID);
String documentLibrary = mockExistingCollaborationSite(collabSite, DEFAULT_COLLABORATION_SITE_ID, true);
// mock listing the document library
Node doclibNode = mockNodesEndpoint(mockedCoreApi, documentLibrary);
List<RestNodeModel> level0Nodes = Arrays.asList(mockNodeModel(file1Id, true), mockNodeModel(file2Id, true), mockNodeModel(folderId, false));
mockListChildren(doclibNode, false, level0Nodes);
// mock listing the folder
Node folderNode = mockNodesEndpoint(mockedCoreApi, folderId);
List<RestNodeModel> level1Nodes = Arrays.asList(mockNodeModel(file3Id, true), mockNodeModel(file4Id, true));
mockListChildren(folderNode, false, level1Nodes);
/*
* When
*/
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
/*
* Then
*/
assertEquals(true, result.isSuccess());
List<String> scheduledFiles = Arrays.asList(file1Id, file2Id, file3Id, file4Id);
validateScheduleFilesOutputMessage(new ArrayList<String>(), scheduledFiles, (String) result.getData());
validateFiredEvents(true, scheduledFiles, result.getNextEvents());
}
use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromDocumentLibraryAndOneCreated.
@Test
public void testDeclareRecordsFromDocumentLibraryAndOneCreated() 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);
when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1, 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());
}
use of org.alfresco.rest.requests.coreAPI.RestCoreAPI 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());
}
Aggregations