Search in sources :

Example 11 with WithUserDetails

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

the class UserControllerTests method testGetProfile.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/enabled-user.xml")
@ExpectedDatabase(value = "/data/user/enabled-user.xml", assertionMode = NON_STRICT)
public void testGetProfile() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/" + USER_2_UUID + "/profile")).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(USER_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 12 with WithUserDetails

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

the class UserControllerTests method testRemoveLinkFromUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-link-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testRemoveLinkFromUser() throws Exception {
    final Integer linkId = 1;
    MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/links/" + linkId)).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.skills").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 13 with WithUserDetails

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

the class UserControllerTests method testAddPublicationToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-publication.xml", assertionMode = NON_STRICT)
public void testAddPublicationToUser() throws Exception {
    UserPublicationDTO inputDTO = new UserPublicationDTO();
    inputDTO.setDescription(USER_LINK_DESCRIPTION);
    inputDTO.setTitle(USER_LINK_TITLE);
    inputDTO.setUrl(USER_LINK_URL);
    inputDTO.setDate(DATE);
    inputDTO.setPublisher(PUBLISHER);
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/publications").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(inputDTO))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.publications").isNotEmpty()).andExpect(jsonPath("$.result.publications", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray publications = (JSONArray) getResultJSONObject(mvcResult).get("publications");
    JSONAssert.assertEquals(PUBLICATION, (JSONObject) publications.get(0), FALSE);
}
Also used : JSONArray(org.json.JSONArray) UserPublicationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO) 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 14 with WithUserDetails

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

the class UserControllerTests method testGetUserInfo.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testGetUserInfo() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/auth/me")).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getResultJSONObject(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 15 with WithUserDetails

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

the class AchillesControllerTest method getFile.

@WithUserDetails(value = "admin@odysseusinc.com")
@DatabaseSetup(value = { "/data/achilles/datanode.xml", "/data/achilles/users.xml", "/data/achilles/studies.xml", "/data/achilles/datasources.xml", "/data/achilles/reports.xml", "/data/achilles/characterizations.xml", "/data/achilles/permissions.xml", "/data/achilles/study-participants.xml" })
public void getFile() throws Exception {
    Bootstrap bootstrap = new Bootstrap();
    AchillesFile observationFile = achillesFileRepository.findOne(11L);
    assertThat(observationFile, is(notNullValue()));
    observationFile.setData(bootstrap.observationJson());
    AchillesFile dashboardFile = achillesFileRepository.findOne(4L);
    assertThat(dashboardFile, is(notNullValue()));
    dashboardFile.setData(bootstrap.dashboardJson());
    achillesFileRepository.save(Arrays.asList(observationFile, dashboardFile));
    mvc.perform(get(String.format(API_FILES, PUBLIC_DS, "dashboard.json")).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.result.SUMMARY.ATTRIBUTE_NAME[0]", is("Source name")));
    mvc.perform(get(String.format(API_FILES, PUBLIC_DS, "observations/observation_3051227.json")).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.result.OBSERVATIONS_BY_TYPE.CONCEPT_NAME", is("Lab observation numeric result")));
}
Also used : AchillesFile(com.odysseusinc.arachne.portal.model.achilles.AchillesFile) 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