Search in sources :

Example 1 with AppAndUsers

use of org.sagebionetworks.bridge.models.apps.AppAndUsers in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersDefaultsPasswordPolicy.

@Test
public void createAppAndUsersDefaultsPasswordPolicy() throws SynapseException {
    app.setPasswordPolicy(null);
    app.setExternalIdRequiredOnSignup(false);
    app.setSynapseDataAccessTeamId(null);
    app.setSynapseProjectId(null);
    List<StudyParticipant> participants = ImmutableList.of(new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withRoles(ImmutableSet.of(DEVELOPER)).build());
    IdentifierHolder holder = new IdentifierHolder("user-id");
    when(mockParticipantService.createParticipant(any(), any(), anyBoolean())).thenReturn(holder);
    AccessControlList acl = new AccessControlList();
    acl.setResourceAccess(new HashSet<>());
    when(mockSynapseClient.createTeam(any())).thenReturn(team);
    when(mockSynapseClient.createEntity(any())).thenReturn(project);
    when(mockSynapseClient.getACL(any())).thenReturn(acl);
    EntityView view = new EntityView();
    view.setScopeIds(new ArrayList<>());
    when(mockSynapseClient.getEntity(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(view);
    AppAndUsers mockAppAndUsers = new AppAndUsers(ImmutableList.of("12345678"), app, participants);
    service.createAppAndUsers(mockAppAndUsers);
    verify(mockAppDao).createApp(appCaptor.capture());
    assertNotNull(appCaptor.getValue().getPasswordPolicy());
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) EntityView(org.sagebionetworks.repo.model.table.EntityView) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 2 with AppAndUsers

use of org.sagebionetworks.bridge.models.apps.AppAndUsers in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersWithEmptyUser.

@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*users are required.*")
public void createAppAndUsersWithEmptyUser() throws SynapseException {
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    List<StudyParticipant> mockUsers = new ArrayList<>();
    AppAndUsers mockAppAndUsers = new AppAndUsers(TEST_ADMIN_IDS, app, mockUsers);
    // execute
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) ArrayList(java.util.ArrayList) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 3 with AppAndUsers

use of org.sagebionetworks.bridge.models.apps.AppAndUsers in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUserInWrongRole.

private void createAppAndUserInWrongRole(Set<Roles> roles) throws SynapseException {
    app.setExternalIdRequiredOnSignup(false);
    app.setSynapseDataAccessTeamId(null);
    app.setSynapseProjectId(null);
    List<StudyParticipant> participants = ImmutableList.of(new StudyParticipant.Builder().withSynapseUserId(TEST_USER_SYNAPSE_ID).withEmail(TEST_USER_EMAIL).withRoles(roles).build());
    AppAndUsers mockAppAndUsers = new AppAndUsers(ImmutableList.of("12345678"), app, participants);
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant)

Example 4 with AppAndUsers

use of org.sagebionetworks.bridge.models.apps.AppAndUsers in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersWithEmptyRoles.

@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*adminIds are required.*")
public void createAppAndUsersWithEmptyRoles() throws SynapseException {
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    StudyParticipant mockUser1 = new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withFirstName(TEST_USER_FIRST_NAME).withLastName(TEST_USER_LAST_NAME).withRoles(ImmutableSet.of()).withPassword(TEST_USER_PASSWORD).build();
    List<StudyParticipant> mockUsers = ImmutableList.of(mockUser1);
    AppAndUsers mockAppAndUsers = new AppAndUsers(null, app, mockUsers);
    // execute
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 5 with AppAndUsers

use of org.sagebionetworks.bridge.models.apps.AppAndUsers in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersWithNullApp.

@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*app cannot be null.*")
public void createAppAndUsersWithNullApp() throws SynapseException {
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    StudyParticipant mockUser1 = new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withFirstName(TEST_USER_FIRST_NAME).withLastName(TEST_USER_LAST_NAME).withRoles(ImmutableSet.of(Roles.RESEARCHER, Roles.DEVELOPER)).withPassword(TEST_USER_PASSWORD).build();
    StudyParticipant mockUser2 = new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL_2).withSynapseUserId(TEST_USER_SYNAPSE_ID_2).withFirstName(TEST_USER_FIRST_NAME).withLastName(TEST_USER_LAST_NAME).withRoles(ImmutableSet.of(Roles.RESEARCHER)).withPassword(TEST_USER_PASSWORD).build();
    List<StudyParticipant> mockUsers = ImmutableList.of(mockUser1, mockUser2);
    AppAndUsers mockAppAndUsers = new AppAndUsers(TEST_ADMIN_IDS, null, mockUsers);
    // execute
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Aggregations

AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)33 Test (org.testng.annotations.Test)30 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)20 App (org.sagebionetworks.bridge.models.apps.App)15 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)11 IdentifierHolder (org.sagebionetworks.bridge.models.accounts.IdentifierHolder)4 SynapseNotFoundException (org.sagebionetworks.client.exceptions.SynapseNotFoundException)4 VersionHolder (org.sagebionetworks.bridge.models.VersionHolder)3 TestUtils.getValidApp (org.sagebionetworks.bridge.TestUtils.getValidApp)2 EntityView (org.sagebionetworks.repo.model.table.EntityView)2 ArrayList (java.util.ArrayList)1 RequestContext (org.sagebionetworks.bridge.RequestContext)1 Study (org.sagebionetworks.bridge.models.studies.Study)1 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)1 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1