use of org.alfresco.rest.model.RestSiteContainerModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsNotLoadedInDb.
@Test
public void testDeclareRecordsColabSiteExistsNotLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
String siteTitle = "someTitle";
String guid = UUID.randomUUID().toString();
String description = "someDescription";
String preset = "somePreset";
Visibility visibility = Visibility.PUBLIC;
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
when(mockedRestSiteModel.getGuid()).thenReturn(guid);
when(mockedRestSiteModel.getDescription()).thenReturn(description);
when(mockedRestSiteModel.getPreset()).thenReturn(preset);
when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
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));
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
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);
when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPI);
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(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
NodeDetail mockedFile = mock(NodeDetail.class);
String fileID = UUID.randomUUID().toString();
when(mockedFile.getId()).thenReturn(fileID);
when(mockedFile.getName()).thenReturn("recordName");
when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
verify(mockedSite, never()).createSite();
verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
assertEquals(MessageFormat.format(template, siteId.toLowerCase(), 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.model.RestSiteContainerModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb.
@Test
public void testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb() throws Exception {
String numberOfRecordsToDeclare = "1";
int maxActiveLoaders = 8;
String siteId = "testSiteId";
String documentLibraryId = UUID.randomUUID().toString();
String siteTitle = "someTitle";
String guid = UUID.randomUUID().toString();
String description = "someDescription";
String preset = "somePreset";
Visibility visibility = Visibility.PUBLIC;
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
when(mockedRestSiteModel.getGuid()).thenReturn(guid);
when(mockedRestSiteModel.getDescription()).thenReturn(description);
when(mockedRestSiteModel.getPreset()).thenReturn(preset);
when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
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));
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
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, times(1)).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
assertEquals(MessageFormat.format(template, siteId.toLowerCase(), 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.model.RestSiteContainerModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method mockExistingCollaborationSite.
/**
* Utility method that mocks the retrieval of an existing collaboration site
*
* @return the id of the generated document library
* @throws Exception
*/
private String mockExistingCollaborationSite(Site mockedSiteEndpoint, String siteId, boolean siteExistsInMongo) throws Exception {
String documentLibraryId = UUID.randomUUID().toString();
RestSiteModel colabSite = mock(RestSiteModel.class);
when(mockedSiteEndpoint.getSite()).thenReturn(colabSite);
when(colabSite.getVisibility()).thenReturn(Visibility.PUBLIC);
/*
* Mock document library
*/
RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
when(mockedSiteEndpoint.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
/*
* Mock the mongo service
*/
if (siteExistsInMongo) {
SiteData mockedSiteData = mock(SiteData.class);
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
} else {
when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
}
return documentLibraryId;
}
use of org.alfresco.rest.model.RestSiteContainerModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsNonExistentNodeId.
@Test
public void testDeclareRecordsNonExistentNodeId() 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(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)).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, 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}. 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.model.RestSiteContainerModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoaders method getCollaborationSiteDoclib.
/**
* Helper method that makes sure the site exists on the server and loads it in the benchmark DB
*
* @param eventOutputMsg
* @return the collaboration site's document library id
* @throws Exception
*/
private String getCollaborationSiteDoclib(StringBuilder eventOutputMsg) throws Exception {
// Check if the collaboration site exists on server using the REST api
RestSiteModel colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).getSite();
if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) {
// The collaboration site doesn't exist, create it
colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).createSite();
}
// Store the collaboration site in benchmark's DB
SiteData colabSiteData = siteDataService.getSite(collabSiteId);
if (colabSiteData == null) {
// Store site info in Benchmark's DB
colabSiteData = new SiteData();
colabSiteData.setSiteId(collabSiteId);
colabSiteData.setTitle(colabSite.getTitle());
colabSiteData.setGuid(colabSite.getGuid());
colabSiteData.setDescription(colabSite.getDescription());
colabSiteData.setSitePreset(colabSite.getPreset());
colabSiteData.setVisibility(colabSite.getVisibility().toString());
colabSiteData.setCreationState(Created);
siteDataService.addSite(colabSiteData);
eventOutputMsg.append(" Added site \"" + collabSiteId + "\" as created.\n");
}
// Get site's document library
RestSiteContainerModel documentLibrary = restCoreAPI.withCoreAPI().usingSite(collabSiteId).getSiteContainer("documentLibrary");
return documentLibrary.getId();
}
Aggregations