use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteMemberUnitTest method testWithEmtyUsername.
@Test
public void testWithEmtyUsername() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(CreateRMSiteMember.FIELD_USERNAME)).thenReturn("");
when(mockedEvent.getData()).thenReturn(mockedData);
EventResult result = createRMSiteMember.processEvent(mockedEvent, new StopWatch());
verify(mockedData, times(1)).put(CreateRMSiteMember.MSG_KEY, CreateRMSiteMember.INVALID_SITE_MEMBER_REQUEST_MSG);
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 testNoSiteIdForScheduledMembers.
@Test
public void testNoSiteIdForScheduledMembers() 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);
when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize)).thenReturn(Arrays.asList(mockedSiteMemberData1, mockedSiteMemberData2));
when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(null);
EventResult result = createRMSiteMembers.processEvent(null);
verify(mockedSiteDataService, times(2)).getSite(PATH_SNIPPET_RM_SITE_ID);
verify(mockedSiteDataService, times(2)).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Failed));
verify(mockedSiteDataService, never()).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, 0), result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(createRMSiteMembers.getEventNameCreateRMSiteMembers(), nextEvents.get(0).getName());
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteMembersUnitTest method testNoSiteMembersScheduled.
@Test
public void testNoSiteMembersScheduled() throws Exception {
int batchSize = 100;
createRMSiteMembers.setBatchSize(batchSize);
when(mockedSiteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize)).thenReturn(new ArrayList<SiteMemberData>());
EventResult result = createRMSiteMembers.processEvent(null);
verify(mockedSiteDataService, never()).getSite(PATH_SNIPPET_RM_SITE_ID);
verify(mockedSiteDataService, never()).setSiteMemberCreationState(eq(PATH_SNIPPET_RM_SITE_ID), any(String.class), eq(DataCreationState.Failed));
verify(mockedSiteDataService, never()).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, 0), result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(createRMSiteMembers.getEventNameRMSiteMembersCreated(), nextEvents.get(0).getName());
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testRMSiteCreation.
@Test
public void testRMSiteCreation() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.class);
RMSite mockedRMSite = mock(RMSite.class);
FilePlanAPI mockedFilePlanAPI = mock(FilePlanAPI.class);
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
TransferContainerAPI mockedTransferContainerAPI = mock(TransferContainerAPI.class);
FilePlan mockedFilePlan = mock(FilePlan.class);
UnfiledContainer mockedUnfiledRecordsContainer = mock(UnfiledContainer.class);
TransferContainer mockedTransfers = mock(TransferContainer.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);
when(mockedRMSiteAPI.createRMSite(any(RMSite.class))).thenReturn(mockedRMSite);
when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
when(mockedRestAPIFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedFilePlanAPI.getFilePlan(FILE_PLAN_ALIAS)).thenReturn(mockedFilePlan);
when(mockedFilePlan.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
when(mockedUnfiledContainerAPI.getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledRecordsContainer);
when(mockedUnfiledRecordsContainer.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getTransferContainerAPI(any(UserModel.class))).thenReturn(mockedTransferContainerAPI);
when(mockedTransferContainerAPI.getTransferContainer(TRANSFERS_ALIAS)).thenReturn(mockedTransfers);
when(mockedTransfers.getId()).thenReturn(randomUUID().toString());
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(HttpStatus.CREATED.toString());
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
EventResult result = createRMSite.processEvent(mockedEvent);
ArgumentCaptor<SiteData> siteData = forClass(SiteData.class);
verify(mockedSiteDataService).addSite(siteData.capture());
ArgumentCaptor<SiteMemberData> siteMemberData = forClass(SiteMemberData.class);
verify(mockedSiteDataService).addSiteMember(siteMemberData.capture());
// Check RM site
SiteData siteDataValue = siteData.getValue();
assertEquals(Scheduled, siteDataValue.getCreationState());
// Check RM admin member
SiteMemberData siteMemberDataValue = siteMemberData.getValue();
assertEquals(Created, siteMemberDataValue.getCreationState());
assertEquals(Administrator.toString(), siteMemberDataValue.getRole());
verify(mockedRMSiteAPI, times(1)).createRMSite(any(RMSite.class));
verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
assertEquals(true, result.isSuccess());
assertEquals("Created site: " + siteId + " Site creator: " + siteManager, (String) result.getData());
List<Event> events = result.getNextEvents();
assertEquals(1, events.size());
Event event = events.get(0);
assertEquals(DEFAULT_EVENT_NAME_SITE_CREATED, event.getName());
DBObject data = (DBObject) event.getData();
assertEquals(null, data);
}
use of org.alfresco.bm.event.EventResult in project records-management by Alfresco.
the class PrepareRMSiteMembersUnitTest method testNoUsersWanted.
@Test
public void testNoUsersWanted() throws Exception {
prepareRMSiteMembers.setRole("Administrator");
prepareRMSiteMembers.setAssignRMRoleToUsers(true);
prepareRMSiteMembers.setUserCount(0);
EventResult result = prepareRMSiteMembers.processEvent(null);
assertEquals(true, result.isSuccess());
assertEquals(PrepareRMSiteMembers.NO_USERS_WANTED_MSG, result.getData());
List<Event> nextEvents = result.getNextEvents();
assertEquals(1, nextEvents.size());
assertEquals(prepareRMSiteMembers.getEventNameContinueLoadingData(), nextEvents.get(0).getName());
}
Aggregations