projectIterationId.getIterationSlug())).thenReturn(
hProjectIteration);
when(identity.hasPermission("modify-translation", hProject, hLocale))
.thenReturn(true);
when(identity.hasPermission("glossary-update", "")).thenReturn(true);
LoadOptionsResult optionsResult =
new LoadOptionsResult(new UserConfigHolder().getState());
when(
loadOptionsHandler.execute(isA(LoadOptionsAction.class),
any(ExecutionContext.class))).thenReturn(optionsResult);
when(translationWorkspace.getWorkspaceContext()).thenReturn(
workspaceContext);
when(workspaceContext.getWorkspaceId()).thenReturn(workspaceId);
Collection<ValidationAction> validationList =
validationFactory.getAllValidationActions().values();
Map<ValidationId, State> validationStates =
new HashMap<ValidationId, State>();
for (ValidationAction valAction : validationList) {
validationStates.put(valAction.getId(), valAction.getState());
}
GetValidationRulesResult validationResult =
new GetValidationRulesResult(validationStates);
when(
getValidationRulesHandler.execute(
isA(GetValidationRulesAction.class),
any(ExecutionContext.class))).thenReturn(
validationResult);
ActivateWorkspaceResult result = handler.execute(action, null);
verify(identity).checkLoggedIn();
verify(translationWorkspace).addEditorClient(eq(HTTP_SESSION_ID),
editorClientIdCaptor.capture(), eq(person.getId()));
EditorClientId editorClientId = editorClientIdCaptor.getValue();
assertThat(editorClientId.getHttpSessionId(),
Matchers.equalTo(HTTP_SESSION_ID));
verify(translationWorkspace).publish(
enterWorkspaceEventCaptor.capture());
EnterWorkspace enterWorkspace = enterWorkspaceEventCaptor.getValue();
assertThat(enterWorkspace.getPerson(), Matchers.equalTo(person));
assertThat(enterWorkspace.getEditorClientId(),
Matchers.equalTo(editorClientId));
Identity userIdentity = result.getIdentity();
assertThat(userIdentity.getPerson(), Matchers.equalTo(person));
assertThat(userIdentity.getEditorClientId(),
Matchers.equalTo(editorClientId));
UserWorkspaceContext userWorkspaceContext =
result.getUserWorkspaceContext();
assertThat(userWorkspaceContext.getWorkspaceRestrictions()
.isHasGlossaryUpdateAccess(), Matchers.equalTo(true));
assertThat(userWorkspaceContext.getWorkspaceRestrictions()
.isProjectActive(), Matchers.equalTo(true));
assertThat(userWorkspaceContext.getWorkspaceRestrictions()
.isHasEditTranslationAccess(), Matchers.equalTo(true));
assertThat(result.getStoredUserConfiguration(),
Matchers.sameInstance(optionsResult.getConfiguration()));
}