Search in sources :

Example 6 with WithUserDetails

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

the class StudyControllerTests method testUpdateContributorRoleToLeadInvestigator.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant-before-changing-role.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-with-2-leaders.xml", assertionMode = NON_STRICT) })
public void testUpdateContributorRoleToLeadInvestigator() throws Exception {
    UpdateParticipantDTO participantDTO = new UpdateParticipantDTO();
    participantDTO.setRole(LEAD_INVESTIGATOR.name());
    mvc.perform(put("/api/v1/study-management/studies/" + STUDY_ID + "/participants/" + UserIdUtils.idToUuid(2L)).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 7 with WithUserDetails

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

the class UserControllerTests method testUploadAvatar.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testUploadAvatar() throws Exception {
    FileInputStream fileInputStream = new FileInputStream(this.getClass().getResource("/test.jpg").getPath());
    MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg", fileInputStream);
    this.mvc.perform(fileUpload("/api/v1/user-management/users/avatar").file(multipartFile).contentType(MULTIPART_FORM_DATA)).andExpect(TRUE_RESULT).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) FileInputStream(java.io.FileInputStream) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 8 with WithUserDetails

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

the class UserControllerTests method testSuggest.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup(value = "/data/user/users-for-suggestion.xml")
@ExpectedDatabase(value = "/data/user/users-for-suggestion.xml", assertionMode = NON_STRICT)
public void testSuggest() throws Exception {
    final String query = "fir";
    final Long studyId = 1L;
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/suggest?target=STUDY&query=" + query + "&id=" + studyId)).andExpect(OK_STATUS).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(3))).andReturn();
    JSONArray suggested = new JSONArray(mvcResult.getResponse().getContentAsString());
    List<Object> list = new ArrayList<>();
    for (int i = 0; i < suggested.length(); i++) {
        list.add(suggested.getJSONObject(i).get("id"));
    }
    // suggested user ids
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(3L)));
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(6L)));
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(7L)));
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 9 with WithUserDetails

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

the class UserControllerTests method testDeletePublicationFromUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-publication-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testDeletePublicationFromUser() throws Exception {
    Integer publicationId = 1;
    MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/publications/" + publicationId)).andExpect(jsonPath("$.result.publications").isEmpty()).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 10 with WithUserDetails

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

the class UserControllerTests method testLinkToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-link.xml", assertionMode = NON_STRICT)
public void testLinkToUser() throws Exception {
    UserLinkDTO link = getUserLinkDTO();
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/links").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(link))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.links").isNotEmpty()).andExpect(jsonPath("$.result.links").isArray()).andExpect(jsonPath("$.result.links", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray links = (JSONArray) getResultJSONObject(mvcResult).get("links");
    JSONAssert.assertEquals(USER_LINK, (JSONObject) links.get(0), FALSE);
}
Also used : UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO) JSONArray(org.json.JSONArray) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

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