Search in sources :

Example 46 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ArachneCentralAPI by OHDSI.

the class StudyControllerTests method testUpdateStudyStatus.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-status.xml", assertionMode = NON_STRICT_UNORDERED) })
public void testUpdateStudyStatus() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setDescription("description");
    StudyTypeDTO type = new StudyTypeDTO(STUDY_TYPE_ID);
    type.setName("type1");
    updatedStudyDTO.setType(type);
    StudyStatusDTO status = new StudyStatusDTO(2L, "Active");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_STATUS_JSON_OBJECT, "Active");
}
Also used : CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 47 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ArachneCentralAPI by OHDSI.

the class StudyControllerTests method testUpdateContributorRoleToContributor.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant-with-2-leaders-before-updating.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-with-contributor-and-leader.xml", assertionMode = NON_STRICT) })
public void testUpdateContributorRoleToContributor() throws Exception {
    UpdateParticipantDTO participantDTO = new UpdateParticipantDTO();
    participantDTO.setRole(CONTRIBUTOR.name());
    mvc.perform(put("/api/v1/study-management/studies/" + STUDY_ID + "/participants/" + UserIdUtils.idToUuid(ADMIN_ID)).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(NO_ERROR_CODE).andReturn();
}
Also used : UpdateParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Example 48 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ArachneCentralAPI by OHDSI.

the class StudyControllerTests method testCreateStudy.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study.xml", assertionMode = NON_STRICT) })
public void testCreateStudy() throws Exception {
    CreateStudyDTO studyDTO = new CreateStudyDTO();
    studyDTO.setTypeId(STUDY_TYPE_ID);
    studyDTO.setTitle(STUDY_TITLE);
    MvcResult mvcResult = mvc.perform(post("/api/v1/study-management/studies/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(studyDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONObject result = getResultJSONObject(mvcResult);
    JSONAssert.assertEquals(STUDY_JSON_OBJECT, result, false);
}
Also used : JSONObject(org.json.JSONObject) CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 49 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ArachneCentralAPI by OHDSI.

the class StudyControllerTests method testUpdateStudyType.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-type.xml", assertionMode = NON_STRICT_UNORDERED) })
public void testUpdateStudyType() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setDescription("description");
    StudyTypeDTO type = new StudyTypeDTO(1L);
    type.setName("type1");
    updatedStudyDTO.setType(type);
    StudyStatusDTO status = new StudyStatusDTO(STUDY_STATUS_ID, "Initiate");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_TYPE_JSON_OBJECT, "type1");
}
Also used : CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 50 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ArachneCentralAPI by OHDSI.

the class StudyControllerTests method testUpdateContributorRoleForLastLeadInvestigator.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant-before-changing-role.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-before-changing-role.xml", assertionMode = NON_STRICT) })
public void testUpdateContributorRoleForLastLeadInvestigator() throws Exception {
    UpdateParticipantDTO participantDTO = new UpdateParticipantDTO();
    participantDTO.setRole(CONTRIBUTOR.name());
    mvc.perform(put("/api/v1/study-management/studies/" + STUDY_ID + "/participants/" + UserIdUtils.idToUuid(ADMIN_ID)).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(jsonPath("$.errorCode").value(VALIDATION_ERROR.getCode()));
}
Also used : UpdateParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Aggregations

WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)56 Test (org.junit.Test)55 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)28 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)26 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)21 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)20 MvcResult (org.springframework.test.web.servlet.MvcResult)15 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)8 CreateStudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO)7 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)6 StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)6 FileInputStream (java.io.FileInputStream)5 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)5 UpdateParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO)4 JSONObject (org.json.JSONObject)4 AnalysisUpdateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO)3 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)3 JSONArray (org.json.JSONArray)3 AddStudyParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO)2 CustomUser (org.baeldung.methodsecurity.entity.CustomUser)2