Search in sources :

Example 21 with StatusMessage

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

the class ParticipantReportControllerTest method adminCanDeleteParticipantIndex.

@Test
public void adminCanDeleteParticipantIndex() throws Exception {
    // Mock getAuthenticatedSession().
    doReturn(session).when(controller).getAuthenticatedSession(ADMIN);
    // Execute and validate.
    StatusMessage result = controller.deleteParticipantReportIndex(REPORT_ID);
    assertEquals(result.getMessage(), "Report index deleted.");
    verify(mockReportService).deleteParticipantReportIndex(TEST_APP_ID, TEST_USER_ID, REPORT_ID);
}
Also used : StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 22 with StatusMessage

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

the class ParticipantReportControllerTest method saveParticipantReportData.

@Test
public void saveParticipantReportData() throws Exception {
    String json = TestUtils.createJson("{'date':'2015-02-12','data':{'field1':'Last','field2':'Name'}}");
    mockRequestBody(mockRequest, json);
    when(mockAccountService.getAccount(any())).thenReturn(Optional.of(mockOtherAccount));
    StatusMessage result = controller.saveParticipantReport(OTHER_PARTICIPANT_ID, REPORT_ID);
    assertEquals(result.getMessage(), "Report data saved.");
    verify(mockReportService).saveParticipantReport(eq(TEST_APP_ID), eq(TEST_USER_ID), eq(REPORT_ID), eq(OTHER_PARTICIPANT_HEALTH_CODE), reportDataCaptor.capture());
    ReportData reportData = reportDataCaptor.getValue();
    assertEquals(reportData.getDate().toString(), LocalDate.parse("2015-02-12").toString());
    assertNull(reportData.getKey());
    assertEquals(reportData.getData().get("field1").asText(), "Last");
    assertEquals(reportData.getData().get("field2").asText(), "Name");
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 23 with StatusMessage

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

the class ParticipantVersionControllerTest method deleteForHealthCode.

@Test
public void deleteForHealthCode() {
    // Mock dependencies.
    Account account = Account.create();
    account.setHealthCode(TestConstants.HEALTH_CODE);
    account.setDataGroups(ImmutableSet.of(BridgeConstants.TEST_USER_GROUP));
    when(mockAccountService.getAccount(any())).thenReturn(Optional.of(account));
    // Execute and validate.
    StatusMessage response = controller.deleteParticipantVersionsForUser(TestConstants.TEST_USER_ID);
    assertNotNull(response);
    verify(mockParticipantVersionService).deleteParticipantVersionsForHealthCode(TestConstants.TEST_APP_ID, TestConstants.HEALTH_CODE);
    ArgumentCaptor<AccountId> accountIdCaptor = ArgumentCaptor.forClass(AccountId.class);
    verify(mockAccountService).getAccount(accountIdCaptor.capture());
    AccountId accountId = accountIdCaptor.getValue();
    assertEquals(accountId.getAppId(), TestConstants.TEST_APP_ID);
    assertEquals(accountId.getId(), TestConstants.TEST_USER_ID);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 24 with StatusMessage

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

the class FileControllerTest method adminCanPermanentlyDelete.

@Test
public void adminCanPermanentlyDelete() throws Exception {
    doReturn(session).when(controller).getAuthenticatedSession(DEVELOPER);
    session.setParticipant(new StudyParticipant.Builder().withRoles(ImmutableSet.of(ADMIN)).build());
    StatusMessage message = controller.deleteFile(GUID, "true");
    assertEquals(message.getMessage(), DELETE_MSG.getMessage());
    verify(mockFileService).deleteFilePermanently(TEST_APP_ID, GUID);
}
Also used : StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 25 with StatusMessage

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

the class FileControllerTest method deleteTemplate.

@Test
public void deleteTemplate() throws Exception {
    doReturn(session).when(controller).getAuthenticatedSession(DEVELOPER);
    StatusMessage message = controller.deleteFile(GUID, "false");
    assertEquals(message.getMessage(), DELETE_MSG.getMessage());
    verify(mockFileService).deleteFile(TEST_APP_ID, GUID);
}
Also used : StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Aggregations

StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)239 Test (org.testng.annotations.Test)168 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)58 PostMapping (org.springframework.web.bind.annotation.PostMapping)43 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)36 App (org.sagebionetworks.bridge.models.apps.App)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)23 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)22 Account (org.sagebionetworks.bridge.models.accounts.Account)21 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)13 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)12 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)11 RequestContext (org.sagebionetworks.bridge.RequestContext)10 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)10 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)9 Cookie (javax.servlet.http.Cookie)6 Appointment (org.hl7.fhir.dstu3.model.Appointment)6 NotificationMessage (org.sagebionetworks.bridge.models.notifications.NotificationMessage)6