Search in sources :

Example 11 with SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class LoadSingleComponentUnitTest method mockSiteAndUserData.

/**
 * Helper methods
 */
/**
 * Helper method for mocking user data
 */
protected void mockSiteAndUserData() {
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(mockedSiteData);
    SiteMemberData mockedSiteMemberData = mock(SiteMemberData.class);
    when(mockedSiteMemberData.getUsername()).thenReturn("aUser");
    when(mockedSiteDataService.randomSiteMember(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, RMRole.Administrator.toString())).thenReturn(mockedSiteMemberData);
    UserData mockedUserData = mock(UserData.class);
    when(mockedUserData.getUsername()).thenReturn("aUser");
    when(mockedUserData.getPassword()).thenReturn("aUser");
    when(mockedUserDataService.findUserByUsername("aUser")).thenReturn(mockedUserData);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    when(mockedRestApiFactory.getRecordsAPI(any(UserModel.class))).thenReturn(mockedRecordsAPI);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) UserModel(org.alfresco.utility.model.UserModel) SiteMemberData(org.alfresco.bm.site.SiteMemberData) UserData(org.alfresco.bm.user.UserData)

Example 12 with SiteData

use of org.alfresco.bm.site.SiteData 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;
}
Also used : SiteData(org.alfresco.bm.site.SiteData) RestSiteModel(org.alfresco.rest.model.RestSiteModel) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel)

Example 13 with SiteData

use of org.alfresco.bm.site.SiteData 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 SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class CreateRMSiteMembersUnitTest method testScheduleSiteMembers.

@Test
public void testScheduleSiteMembers() throws Exception {
    int batchSize = 100;
    createRMSiteMembers.setBatchSize(batchSize);
    SiteMemberData mockedSiteMemberData1 = mock(SiteMemberData.class);
    SiteMemberData mockedSiteMemberData2 = mock(SiteMemberData.class);
    when(mockedSiteMemberData1.getSiteId()).thenReturn(PATH_SNIPPET_RM_SITE_ID);
    when(mockedSiteMemberData2.getSiteId()).thenReturn(PATH_SNIPPET_RM_SITE_ID);
    String username1 = "user1";
    String username2 = "user2";
    when(mockedSiteMemberData1.getUsername()).thenReturn(username1);
    when(mockedSiteMemberData2.getUsername()).thenReturn(username2);
    when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize)).thenReturn(Arrays.asList(mockedSiteMemberData1, mockedSiteMemberData2));
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(mockedSiteData);
    EventResult result = createRMSiteMembers.processEvent(null);
    verify(mockedSiteDataService, times(2)).getSite(PATH_SNIPPET_RM_SITE_ID);
    verify(mockedSiteDataService, never()).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Failed));
    verify(mockedSiteDataService, times(2)).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Scheduled));
    assertEquals(true, result.isSuccess());
    assertEquals(MessageFormat.format(CreateRMSiteMembers.SCHEDULED_MEMBERS_MSG_TEMPLATE, 2), result.getData());
    List<Event> nextEvents = result.getNextEvents();
    assertEquals(3, nextEvents.size());
    // event1
    Event event = nextEvents.get(0);
    assertEquals(createRMSiteMembers.getEventNameCreateRMSiteMember(), event.getName());
    DBObject dataObj = (DBObject) event.getData();
    assertNotNull(dataObj);
    assertEquals(username1, (String) dataObj.get(CreateRMSiteMember.FIELD_USERNAME));
    // event2
    event = nextEvents.get(1);
    assertEquals(createRMSiteMembers.getEventNameCreateRMSiteMember(), event.getName());
    dataObj = (DBObject) event.getData();
    assertNotNull(dataObj);
    assertEquals(username2, (String) dataObj.get(CreateRMSiteMember.FIELD_USERNAME));
    // self event
    assertEquals(createRMSiteMembers.getEventNameCreateRMSiteMembers(), nextEvents.get(2).getName());
}
Also used : SiteData(org.alfresco.bm.site.SiteData) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 15 with SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class CreateRMSiteUnitTest method testCreationStateNotCreated.

@Test
public void testCreationStateNotCreated() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    SiteData mockedSiteData = mock(SiteData.class);
    String siteId = randomUUID().toString();
    when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
    when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(randomUUID().toString());
    when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn("password");
    when(mockedEvent.getData()).thenReturn(mockedData);
    when(mockedSiteDataService.getSite(siteId)).thenReturn(mockedSiteData);
    when(mockedSiteData.getCreationState()).thenReturn(Failed);
    EventResult result = createRMSite.processEvent(mockedEvent);
    assertEquals(false, result.isSuccess());
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    verify(mockedSiteDataService, never()).addSiteMember(any(SiteMemberData.class));
    assertEquals("Site state has changed: " + mockedSiteData, result.getData());
    assertEquals(0, result.getNextEvents().size());
}
Also used : SiteData(org.alfresco.bm.site.SiteData) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

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