Search in sources :

Example 51 with WithUserDetails

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

the class StudyControllerTests method testUploadFile.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-after-updating-description.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-description.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/study/studies-files.xml", assertionMode = NON_STRICT) })
public void testUploadFile() throws Exception {
    String path = this.getClass().getResource("/test.jpg").getPath();
    FileInputStream fileInputStream = new FileInputStream(path);
    MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg", fileInputStream);
    mvc.perform(fileUpload("/api/v1/study-management/studies/" + STUDY_ID + "/upload").file(multipartFile).param("label", "labelUploadedFile").param("file", path).contentType(MULTIPART_FORM_DATA)).andExpect(NO_ERROR_CODE);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) FileInputStream(java.io.FileInputStream) 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 52 with WithUserDetails

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

the class StudyControllerTests method testUpdateStudyDescription.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-description.xml", assertionMode = NON_STRICT) })
public void testUpdateStudyDescription() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setDescription(UPDATED_DESCRIPTION);
    StudyStatusDTO status = new StudyStatusDTO(STUDY_STATUS_ID, "Initiate");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_JSON_OBJECT, null);
}
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) 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 53 with WithUserDetails

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

the class AnalysisHelperTest method createSubmission.

@Test
@WithUserDetails("admin@odysseusinc.com")
public void createSubmission() throws Exception {
    DataSource dataSource = prepareDataSource();
    when(dataSourceService.getByIdUnsecured(1L)).thenReturn(dataSource);
    IUser user = prepareUser();
    Study study = prepareStudy(user);
    Analysis analysis = prepareAnalysis(user, study);
    List<Submission> submissions = AnalysisHelper.createSubmission(submissionService, Collections.<Long>singletonList(1L), user, analysis);
    try {
        assertThat(submissions, is(not(empty())));
        assertThat(submissions, contains(hasProperty("status", notNullValue())));
        assertThat(submissions, contains(hasProperty("submissionGroup", notNullValue())));
    } finally {
        cleanup(submissions, analysis, study);
    }
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) Submission(com.odysseusinc.arachne.portal.model.Submission) Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) DataSource(com.odysseusinc.arachne.portal.model.DataSource) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 54 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project tutorials by eugenp.

the class TestWithUserDetails method whenJohn_callLoadUserDetail_thenOK.

@Test
@WithUserDetails(value = "john", userDetailsServiceBeanName = "userDetailService")
public void whenJohn_callLoadUserDetail_thenOK() {
    CustomUser user = userService.loadUserDetail("jane");
    assertEquals("jane", user.getNickName());
}
Also used : CustomUser(org.baeldung.methodsecurity.entity.CustomUser) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 55 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project tutorials by eugenp.

the class TestWithUserDetails method givenJane_callSecuredLoadUserDetailWithJane_thenOK.

@Test
@WithUserDetails(value = "jane", userDetailsServiceBeanName = "userDetailService")
public void givenJane_callSecuredLoadUserDetailWithJane_thenOK() {
    CustomUser user = userService.securedLoadUserDetail("jane");
    assertEquals("jane", user.getNickName());
    assertEquals("jane", user.getUsername());
}
Also used : CustomUser(org.baeldung.methodsecurity.entity.CustomUser) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

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