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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations