Search in sources :

Example 11 with RestCoreAPI

use of org.alfresco.rest.requests.coreAPI.RestCoreAPI 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());
}
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) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) Visibility(org.alfresco.dataprep.SiteService.Visibility) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 12 with RestCoreAPI

use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsAndLoadedInDb.

/**
 * Given the collaboration site already exists and is loaded in the database
 * When running the scheduler with numberOfRecordsToDeclare=1
 * Then we don't attempt to load or create the site and 1 file is created and scheduled to be declared
 *
 * @throws Exception
 */
@Test
public void testDeclareRecordsColabSiteExistsAndLoadedInDb() throws Exception {
    String fileID = UUID.randomUUID().toString();
    /*
         * Given
         */
    String numberOfRecordsToDeclare = "1";
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(DEFAULT_MAX_ACTIVE_LOADERS);
    scheduleInPlaceRecordLoaders.setCollabSiteId(DEFAULT_COLLABORATION_SITE_ID);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
    RestCoreAPI mockedRestCoreAPI = mockCoreApi();
    Site mockedSitesEndpoint = mockSitesEndpoint(mockedRestCoreAPI, DEFAULT_COLLABORATION_SITE_ID);
    String documentLibraryId = mockExistingCollaborationSite(mockedSitesEndpoint, DEFAULT_COLLABORATION_SITE_ID, true);
    Node doclibNodesEndpoint = mockNodesEndpoint(mockedRestCoreAPI, documentLibraryId);
    mockListChildren(doclibNodesEndpoint, false, new ArrayList<RestNodeModel>());
    // mock node builder
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(doclibNodesEndpoint.defineNodes()).thenReturn(mockedNodeBuilder);
    // mock create folder helper method
    NodeDetail mockedAutoGeneratedFolder = mock(NodeDetail.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedAutoGeneratedFolder);
    // mock create file
    NodeDetail mockedFile = mock(NodeDetail.class);
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedAutoGeneratedFolder.file("recordToBe")).thenReturn(mockedFile);
    /*
         * When
         */
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    /*
         * Then
         */
    verify(mockedSitesEndpoint, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    List<String> createdAndScheduledFiles = Arrays.asList(fileID);
    validateScheduleFilesOutputMessage(createdAndScheduledFiles, createdAndScheduledFiles, (String) result.getData());
    validateFiredEvents(true, Arrays.asList(fileID), result.getNextEvents());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) RestNodeModel(org.alfresco.rest.model.RestNodeModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 13 with RestCoreAPI

use of org.alfresco.rest.requests.coreAPI.RestCoreAPI 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());
}
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) 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 14 with RestCoreAPI

use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteDoesExistAndLoadedInMongoDB.

@Test
public void testRMSiteDoesExistAndLoadedInMongoDB() throws Exception {
    String username = "bob";
    String password = "secret";
    prepareRMSite.setUsername(username);
    prepareRMSite.setPassword(password);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteData.getSiteId()).thenReturn(RM_SITE_ID);
    when(mockedSiteData.getCreationState()).thenReturn(Created);
    when(mockedSiteDataService.getSite(RM_SITE_ID)).thenReturn(mockedSiteData);
    People mockedPeople = mock(People.class);
    RestCoreAPI mockedCoreAPI = mock(RestCoreAPI.class);
    when(mockedCoreAPI.usingAuthUser()).thenReturn(mockedPeople);
    when(mockedRestCoreAPI.withCoreAPI()).thenReturn(mockedCoreAPI);
    when(mockedRestCoreAPI.getStatusCode()).thenReturn(HttpStatus.OK.toString());
    EventResult result = prepareRMSite.processEvent(null);
    ArgumentCaptor<UserData> userData = forClass(UserData.class);
    verify(mockedUserDataService).createNewUser(userData.capture());
    // Check RM admin user
    assertEquals(Created, userData.getValue().getCreationState());
    // Check events
    assertEquals(true, result.isSuccess());
    assertEquals("RM Site already created, continue loading data.", result.getData());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals("scheduleFilePlanLoaders", event.getName());
    DBObject data = (DBObject) event.getData();
    assertNull(data);
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) People(org.alfresco.rest.requests.People) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 15 with RestCoreAPI

use of org.alfresco.rest.requests.coreAPI.RestCoreAPI in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteCreatorDoesNotExist.

@Test
public void testRMSiteCreatorDoesNotExist() throws Exception {
    String username = "bob";
    String password = "secret";
    prepareRMSite.setUsername(username);
    prepareRMSite.setPassword(password);
    People mockedPeople = mock(People.class);
    RestCoreAPI mockedCoreAPI = mock(RestCoreAPI.class);
    when(mockedCoreAPI.usingAuthUser()).thenReturn(mockedPeople);
    when(mockedRestCoreAPI.withCoreAPI()).thenReturn(mockedCoreAPI);
    when(mockedRestCoreAPI.getStatusCode()).thenReturn(HttpStatus.UNAUTHORIZED.toString());
    EventResult result = prepareRMSite.processEvent(null);
    assertEquals(false, result.isSuccess());
    assertEquals("Provided RM Site Creator does not exist, or provided credentials are not valid.", result.getData());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) People(org.alfresco.rest.requests.People) Test(org.junit.Test)

Aggregations

RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)16 EventResult (org.alfresco.bm.event.EventResult)15 Test (org.junit.Test)15 SiteData (org.alfresco.bm.site.SiteData)11 Node (org.alfresco.rest.requests.Node)10 Site (org.alfresco.rest.requests.Site)10 StopWatch (org.apache.commons.lang3.time.StopWatch)10 RestWrapper (org.alfresco.rest.core.RestWrapper)9 RestNodeModelsCollection (org.alfresco.rest.model.RestNodeModelsCollection)8 RestPaginationModel (org.alfresco.rest.model.RestPaginationModel)8 RestSiteContainerModel (org.alfresco.rest.model.RestSiteContainerModel)8 RestSiteModel (org.alfresco.rest.model.RestSiteModel)8 RepoTestModel (org.alfresco.utility.model.RepoTestModel)8 NodesBuilder (org.alfresco.rest.model.builder.NodesBuilder)7 NodeDetail (org.alfresco.rest.model.builder.NodesBuilder.NodeDetail)7 RestNodeModel (org.alfresco.rest.model.RestNodeModel)6 People (org.alfresco.rest.requests.People)5 DBObject (com.mongodb.DBObject)4 Event (org.alfresco.bm.event.Event)4 UserData (org.alfresco.bm.user.UserData)4