Search in sources :

Example 26 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project nixmash-blog by mintster.

the class AdminControllerTests method registeredUserCannotAccessAdmin.

@Test
@WithUserDetails(value = "erwin", userDetailsServiceBeanName = "currentUserDetailsService")
public void registeredUserCannotAccessAdmin() throws Exception {
    // Erwin a registered user but not in ROLE_POSTS
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request).andExpect(status().isForbidden()).andExpect(forwardedUrl("/403"));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 27 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project oc-explorer by devgateway.

the class UserDashboardRestControllerTest method saveDashboardForCurrentUser.

@Test
@WithUserDetails(value = "admin", userDetailsServiceBeanName = "testUserDetailsAdminProcuringEntity")
public void saveDashboardForCurrentUser() {
    UserDashboard ud = new UserDashboard();
    ud.setName("some name");
    ud.setFormUrlEncodedBody("some body");
    ResponseEntity<Void> responseEntity = userDashboardRestController.saveDashboardForCurrentUser(ud);
    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
Also used : UserDashboard(org.devgateway.ocds.persistence.dao.UserDashboard) Test(org.junit.Test) AbstractSpringDataRestControllerTest(org.devgateway.toolkit.web.AbstractSpringDataRestControllerTest) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 28 with WithUserDetails

use of org.springframework.security.test.context.support.WithUserDetails in project ocvn by devgateway.

the class UserDashboardRestControllerTest method saveDashboardForCurrentUser.

@Test
@WithUserDetails(value = "admin", userDetailsServiceBeanName = "testUserDetailsAdminProcuringEntity")
public void saveDashboardForCurrentUser() {
    UserDashboard ud = new UserDashboard();
    ud.setName("some name");
    ud.setFormUrlEncodedBody("some body");
    ResponseEntity<Void> responseEntity = userDashboardRestController.saveDashboardForCurrentUser(ud);
    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
Also used : UserDashboard(org.devgateway.ocds.persistence.dao.UserDashboard) Test(org.junit.Test) AbstractSpringDataRestControllerTest(org.devgateway.toolkit.web.AbstractSpringDataRestControllerTest) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 29 with WithUserDetails

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

the class AnalysisControllerTests method testUpdateAnalysisDescription.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/analysis-before-updating.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/analysis-after-description-updating.xml", assertionMode = NON_STRICT) })
public void testUpdateAnalysisDescription() throws Exception {
    AnalysisUpdateDTO analysisDTO = new AnalysisUpdateDTO();
    analysisDTO.setDescription(UPDATED_ANALYSIS_DESCRIPTION_VALUE);
    analysisDTO.setTypeId(ANALYSIS_TYPE_ID);
    testUpdate(analysisDTO, UPDATED_ANALYSIS_DESCR_JSON_OBJECT, null);
}
Also used : AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) 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 30 with WithUserDetails

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

the class AnalysisControllerTests method testUpdateCodeFile.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/analysis-list.xml"), @DatabaseSetup("/data/analysis/code-file-before-deleting.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/code-file-after-updating.xml", assertionMode = NON_STRICT) })
public void testUpdateCodeFile() throws Exception {
    String uuid = "68b75ac9-ab29-49a6-8edb-95142456f5fc";
    String path = this.getClass().getResource("/test.jpg").getPath();
    FileInputStream fileInputStream = new FileInputStream(path);
    MockMultipartFile multipartFile = new MockMultipartFile("file", "test_updated.jpg", "image/jpeg", fileInputStream);
    MockMultipartHttpServletRequestBuilder builder = fileUpload("/api/v1/analysis-management/analyses/{analysisId}/files/{fileUuid}", ANALYSIS_ID, uuid);
    builder.with(request -> {
        request.setMethod("PUT");
        return request;
    });
    mvc.perform(builder.file(multipartFile).param("label", "labelUploadedFile").param("file", path).contentType(MULTIPART_FORM_DATA)).andExpect(NO_ERROR_CODE).andExpect(TRUE_RESULT);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) FileInputStream(java.io.FileInputStream) 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