use of org.alfresco.bm.event.EventResult 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.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteMemberUnitTest method testSiteMemberMissing.
@Test
public void testSiteMemberMissing() throws Exception {
String userName = "user1";
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn(userName);
when(mockedEvent.getData()).thenReturn(mockedData);
when(mockedSiteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, userName)).thenReturn(null);
EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
verify(mockedData, never()).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, MessageFormat.format(CreateRMSiteMember.SITE_MEMBER_MISSING_MSG_TEMPLATE, userName));
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(data);
}
use of org.alfresco.bm.event.EventResult 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.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testRMSiteCreationNotPossible.
@Test
public void testRMSiteCreationNotPossible() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.class);
String siteId = randomUUID().toString();
String siteManager = randomUUID().toString();
String password = "password";
when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(siteManager);
when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
when(mockedSiteDataService.getSite(siteId)).thenReturn(null);
when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(HttpStatus.FORBIDDEN.toString());
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
EventResult result = createRMSite.processEvent(mockedEvent);
verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
verify(mockedSiteDataService, never()).addSiteMember(any(SiteMemberData.class));
assertEquals(false, result.isSuccess());
assertEquals("RM site could not be created.", result.getData());
assertEquals(0, result.getNextEvents().size());
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testWithNullOrEmptyPassword.
@Test
public void testWithNullOrEmptyPassword() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn("someUserName");
when(mockedEvent.getData()).thenReturn(mockedData);
// null password
when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn(null);
EventResult result = createRMSite.processEvent(mockedEvent);
assertEquals(false, result.isSuccess());
assertEquals("Requests data not complete for site creation: " + mockedData, result.getData());
assertEquals(0, result.getNextEvents().size());
// empty password
when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn("");
result = createRMSite.processEvent(mockedEvent);
assertEquals(false, result.isSuccess());
assertEquals("Requests data not complete for site creation: " + mockedData, result.getData());
assertEquals(0, result.getNextEvents().size());
}
Aggregations