Ejemplo n.º 1
0
  @Test
  public void testGenerateTasks_NotASponsor() throws Exception {
    FirebirdUser coordinator = FirebirdUserFactory.getInstance().createRegistrationCoordinator();

    List<Task> tasks = generator.generateTasks(coordinator, null);

    assertTrue(tasks.isEmpty());
  }
  @Test
  public void testPrepare() {
    FirebirdUser user = FirebirdUserFactory.getInstance().create();
    Organization annualRegistrationSponsor = OrganizationFactory.getInstance().create();
    Organization verifiedSponsor = OrganizationFactory.getInstance().create();
    Organization unverifiedSponsor = OrganizationFactory.getInstance().create();
    SponsorRole verifiedRole = user.addSponsorRepresentativeRole(verifiedSponsor);
    SponsorRole unverifiedRole = user.addSponsorRepresentativeRole(unverifiedSponsor);
    user.addSponsorRepresentativeRole(annualRegistrationSponsor);
    FirebirdWebTestUtility.setCurrentUser(action, user);
    UserSessionInformation userSessionInformation =
        UserSessionInformationFactory.getInstance()
            .create(user.getUsername(), verifiedRole.getVerifiedSponsorGroupName());
    FirebirdWebTestUtility.setUpGridSessionInformation(action, userSessionInformation);
    when(mockSponsorService.getSponsorOrganizationWithAnnualRegistrations())
        .thenReturn(annualRegistrationSponsor);

    action.prepare();

    assertEquals(1, action.getUnverifiedSponsorRoles().size());
    assertEquals(unverifiedRole, action.getUnverifiedSponsorRoles().get(0));
  }
Ejemplo n.º 3
0
public class DcpSponsorTasksGeneratorTest extends AbstractTaskGeneratorTest {

  private static final Set<String> groupNames = Sets.newHashSet();

  private DcpSponsorTasksGenerator generator;
  @Inject private TemplateService templateService;
  @Mock private SponsorService mockSponsorService;
  @Mock private ProtocolRegistrationService mockRegistrationService;

  private Organization sponsorOrganization = OrganizationFactory.getInstance().create();
  private FirebirdUser sponsor = FirebirdUserFactory.getInstance().create();

  @Override
  public void setUp() {
    super.setUp();
    generator =
        new DcpSponsorTasksGenerator(templateService, mockRegistrationService, mockSponsorService);
    SponsorRole sponsorRole = sponsor.addSponsorRepresentativeRole(sponsorOrganization);
    groupNames.add(sponsorRole.getVerifiedSponsorGroupName());
    List<AbstractProtocolRegistration> emptyList = Collections.emptyList();
    when(mockRegistrationService.getByStatusForUser(
            any(RegistrationStatus.class), eq(sponsor), anySetOf(String.class)))
        .thenReturn(emptyList);
  }

  @Test
  public void testGenerateTasks_NotASponsor() throws Exception {
    FirebirdUser coordinator = FirebirdUserFactory.getInstance().createRegistrationCoordinator();

    List<Task> tasks = generator.generateTasks(coordinator, null);

    assertTrue(tasks.isEmpty());
  }

  @Test
  public void testGenerateTasks_SponsorRoleNeedsVerification() throws Exception {
    Set<String> groupNames = Sets.newHashSet();

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    checkForOnlyTask(tasks, SPONSOR_ROLE_AWAITING_VERIFICATION_TASK_TITLE);
  }

  @Test
  public void testGenerateTasks_CtepSponsor() throws Exception {
    Set<String> groupNames = Sets.newHashSet();
    sponsor.getSponsorRoles().clear();
    Organization ctepSponsor = new Organization();
    sponsor.addSponsorRepresentativeRole(ctepSponsor);
    when(mockSponsorService.getSponsorOrganizationWithAnnualRegistrations())
        .thenReturn(ctepSponsor);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    assertTrue(tasks.isEmpty());
  }

  @Test
  public void testGenerateTasks_RegistrationSubmitted() throws Exception {
    InvestigatorRegistration registration =
        RegistrationFactory.getInstance().createInvestigatorRegistration(SUBMITTED);
    setUpMockRegistrationServiceToReturnRegistration(registration);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    checkForOnlyTask(tasks, REGISTRATION_SUBMITTED_TASK_TITLE, registration);
  }

  private void setUpMockRegistrationServiceToReturnRegistration(
      AbstractProtocolRegistration registration) {
    when(mockRegistrationService.getByStatusForUser(registration.getStatus(), sponsor, groupNames))
        .thenReturn(Lists.newArrayList(registration));
  }

  @Test
  public void testGenerateTasks_InReviewRegistration() throws Exception {
    InvestigatorRegistration registration =
        RegistrationFactory.getInstance().createInvestigatorRegistration(IN_REVIEW);
    setUpMockRegistrationServiceToReturnRegistration(registration);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    checkForOnlyTask(tasks, REGISTRATION_IN_REVIEW_TASK_TITLE, registration);
  }

  @Test
  public void testGenerateTasks_RegistrationReadyForApproval() throws Exception {
    InvestigatorRegistration registration =
        RegistrationFactory.getInstance().createInvestigatorRegistration(ACCEPTED);
    setUpMockRegistrationServiceToReturnRegistration(registration);
    registration.getProtocol().setSponsor(sponsorOrganization);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    checkForOnlyTask(tasks, REGISTRATION_PACKET_AWAITING_APPROVAL_TITLE, registration);
  }

  @Test
  public void testGenerateTasks_AcceptedRegistrationWithUnAcceptedSubinvestigatorRegistration()
      throws Exception {
    InvestigatorRegistration registration =
        RegistrationFactory.getInstance().createInvestigatorRegistration(ACCEPTED);
    RegistrationFactory.getInstance().createSubinvestigatorRegistration(registration);
    setUpMockRegistrationServiceToReturnRegistration(registration);
    registration.getProtocol().setSponsor(sponsorOrganization);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    assertTrue(tasks.isEmpty());
  }

  @Test
  public void testGenerateTasks_AcceptedSubinvestigatorRegistration() throws Exception {
    SubInvestigatorRegistration subinvestigatorRegistration =
        RegistrationFactory.getInstance().createSubinvestigatorRegistration();
    subinvestigatorRegistration.setStatus(ACCEPTED);
    setUpMockRegistrationServiceToReturnRegistration(subinvestigatorRegistration);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    assertTrue(tasks.isEmpty());
  }

  @Test
  public void
      testGenerateTasks_RegistrationReadyForApproval_NotSponsorRepresentativeForProtocolSponsor()
          throws Exception {
    sponsor.getSponsorRoles().clear();
    groupNames.clear();
    SponsorRole sponsorDelegateRole = sponsor.addSponsorDelegateRole(sponsorOrganization);
    groupNames.add(sponsorDelegateRole.getVerifiedSponsorGroupName());
    InvestigatorRegistration registration =
        RegistrationFactory.getInstance().createInvestigatorRegistration(ACCEPTED);
    setUpMockRegistrationServiceToReturnRegistration(registration);
    registration.getProtocol().setSponsor(sponsorOrganization);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    assertTrue(tasks.isEmpty());
  }

  @Test
  public void testGenerateTasks_RevisedRegistrationReadyForApproval() throws Exception {
    RevisedInvestigatorRegistration registration =
        RegistrationFactory.getInstance().createRevisedInvestigatorRegistration();
    registration.setStatus(ACCEPTED);
    setUpMockRegistrationServiceToReturnRegistration(registration);
    registration.getProtocol().setSponsor(sponsorOrganization);

    List<Task> tasks = generator.generateTasks(sponsor, groupNames);

    assertTrue(tasks.isEmpty());
  }
}
public class VerificationPageFlowActionTest extends AbstractFlowActionTestBase {

  @Inject private VerificationPageFlowAction action;
  @Inject private AccountManagementService mockAccountService;
  private FirebirdUser user = FirebirdUserFactory.getInstance().create();

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    action.setServletRequest(getMockRequest());
    setAccountConfigurationDataInSession(getAccountConfigurationData());
    action.prepare();
    user.setId(1L);
    setUpGridSessionInformation();
  }

  @Test
  public void testPerformSave() {
    assertEquals(ActionSupport.SUCCESS, action.performSave());
  }

  @Test
  public void testSaveAndProceedNext_NewUser() throws ValidationException, GridInvocationException {
    assertEquals(VerificationPageFlowAction.USER_HOME_RETURN, action.saveAndProceedNext());
    verify(mockAccountService).create(action.getAccountConfigurationData());
  }

  @Test
  public void testSaveAndProceedNext_ExistingUser()
      throws ValidationException, GridInvocationException {
    FirebirdWebTestUtility.setCurrentUser(action, user);
    assertEquals(VerificationPageFlowAction.MY_ACCOUNT_RETURN, action.saveAndProceedNext());
    verify(mockAccountService).addRoles(user, action.getAccountConfigurationData());
    verify(getMockSession()).setAttribute(FirebirdUIConstants.ROLES_UPDATED, true);
  }

  @Test
  public void testSaveAndProceedNext_VerifiedRoles() {
    getAccountConfigurationData().getRoles().add(INVESTIGATOR);
    setUpGridSessionInformation(INVESTIGATOR.getGroupName(), INVESTIGATOR.getVerifiedGroupName());
    assertEquals(VerificationPageFlowAction.USER_HOME_RETURN, action.saveAndProceedNext());
  }

  @Test
  public void testSaveAndProceedNext_UnverifiedNewUser() {
    getAccountConfigurationData().getRoles().add(INVESTIGATOR);
    setUpGridSessionInformation(INVESTIGATOR.getGroupName());
    assertEquals(
        VerificationPageFlowAction.FUNCTIONALITY_WARNING_RETURN, action.saveAndProceedNext());
  }

  @Test
  public void testSaveAndProceedNext_UnverifiedAddRoles() {
    getAccountConfigurationData().getRoles().add(INVESTIGATOR);
    setUpGridSessionInformation(INVESTIGATOR.getGroupName());
    FirebirdWebTestUtility.setCurrentUser(action, user);
    assertEquals(
        VerificationPageFlowAction.FUNCTIONALITY_WARNING_RETURN, action.saveAndProceedNext());
  }

  public void setUpGridSessionInformation(String... groupNames) {
    UserSessionInformation sessionInformation =
        UserSessionInformationFactory.getInstance().create(user.getUsername(), groupNames);
    FirebirdWebTestUtility.setUpGridSessionInformation(action, sessionInformation);
  }

  @Test
  public void testSaveAndProceedNext_GridInvocationException()
      throws ValidationException, GridInvocationException {
    FirebirdWebTestUtility.setCurrentUser(action, user);
    GridInvocationException mockGridInvocationException = mock(GridInvocationException.class);
    doThrow(mockGridInvocationException)
        .when(mockAccountService)
        .addRoles(eq(user), any(AccountConfigurationData.class));
    assertEquals(ActionSupport.INPUT, action.saveAndProceedNext());
    assertTrue(action.hasActionErrors());
  }

  @Test
  public void testSaveAndProceedNext_ValidationError()
      throws ValidationException, GridInvocationException {
    ValidationFailure validationFailure = new ValidationFailure("failed");
    ValidationResult result = new ValidationResult(validationFailure);
    ValidationException validationException = new ValidationException(result);
    doThrow(validationException)
        .when(mockAccountService)
        .create(any(AccountConfigurationData.class));
    assertEquals(ActionSupport.INPUT, action.saveAndProceedNext());
  }

  @Test
  public void testIsVerificationRequiredForRoles_VerifiedInvestigator() {
    getAccountConfigurationData().getRoles().add(INVESTIGATOR);
    setUpGridSessionInformation(INVESTIGATOR.getGroupName(), INVESTIGATOR.getVerifiedGroupName());
    assertEquals(false, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_UnverifiedInvestigator() {
    getAccountConfigurationData().getRoles().add(INVESTIGATOR);
    setUpGridSessionInformation(INVESTIGATOR.getGroupName());
    assertEquals(true, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_RegistrationCoordinator() {
    getAccountConfigurationData().getRoles().add(REGISTRATION_COORDINATOR);
    assertEquals(true, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_VerifiedSponsor() {
    getAccountConfigurationData().getRoles().add(SPONSOR);
    Organization sponsor = OrganizationFactory.getInstance().create();
    getAccountConfigurationData().getSponsorOrganizations().add(sponsor);
    setUpGridSessionInformation(
        SPONSOR.getGroupName(),
        SPONSOR.getVerifiedGroupName(),
        SPONSOR.getGroupName() + "_" + getNesIdExtension(sponsor),
        SPONSOR.getVerifiedGroupName() + "_" + getNesIdExtension(sponsor));
    assertEquals(false, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_UnverifiedSponsor() {
    getAccountConfigurationData().getRoles().add(SPONSOR);
    Organization sponsor = OrganizationFactory.getInstance().create();
    getAccountConfigurationData().getSponsorOrganizations().add(sponsor);
    setUpGridSessionInformation(
        SPONSOR.getGroupName(), SPONSOR.getGroupName() + "_" + getNesIdExtension(sponsor));
    assertEquals(true, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_VerifiedSponsorDelegate() {
    getAccountConfigurationData().getRoles().add(SPONSOR_DELEGATE);
    Organization sponsor = OrganizationFactory.getInstance().create();
    getAccountConfigurationData().getDelegateOrganizations().add(sponsor);
    setUpGridSessionInformation(
        SPONSOR_DELEGATE.getGroupName(),
        SPONSOR_DELEGATE.getVerifiedGroupName(),
        SPONSOR_DELEGATE.getGroupName() + "_" + getNesIdExtension(sponsor),
        SPONSOR_DELEGATE.getVerifiedGroupName() + "_" + getNesIdExtension(sponsor));
    assertEquals(false, action.isVerificationRequiredForRoles());
  }

  @Test
  public void testIsVerificationRequiredForRoles_UnverifiedSponsorDelegate() {
    getAccountConfigurationData().getRoles().add(SPONSOR_DELEGATE);
    Organization sponsor = OrganizationFactory.getInstance().create();
    getAccountConfigurationData().getDelegateOrganizations().add(sponsor);
    setUpGridSessionInformation(
        SPONSOR_DELEGATE.getGroupName(),
        SPONSOR_DELEGATE.getGroupName() + "_" + getNesIdExtension(sponsor));
    assertTrue(action.isVerificationRequiredForRoles());
  }
}