Search in sources :

Example 21 with WithUserDetails

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

the class AnalysisSubmissionControllerTests method testDeleteSubmissionResult.

// @Test
// @WithUserDetails(DATA_NODE_ONWER)
// @DatabaseSetups({
// @DatabaseSetup("/data/analysis/submission/submission-published-with-added-files.xml"),
// })
// @ExpectedDatabases({
// @ExpectedDatabase(value = "/data/analysis/submission/submission-published-with-added-files.xml", assertionMode = NON_STRICT),
// 
// })
// public void testGetUploadingSubmissionResult() throws Exception {
// 
// prepareResultFile(1L);
// }
@Test
@WithUserDetails(DATA_NODE_ONWER)
@DatabaseSetups({ @DatabaseSetup("/data/analysis/submission/submission-in-progress.xml"), @DatabaseSetup("/data/analysis/submission/result-file.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/analysis/submission/submission-in-progress.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/submission/result/empty-result-file.xml", assertionMode = NON_STRICT) })
public void testDeleteSubmissionResult() throws Exception {
    Long submissionId = 1L;
    ArachneFileMeta fileMeta = prepareResultFile(1L);
    String fileUuid = fileMeta.getUuid();
    mvc.perform(delete("/api/v1/analysis-management/submissions/{submissionId}/result/{fileUuid}", submissionId, fileUuid)).andExpect(NO_ERROR_CODE);
    if (checkFileExists(getResultFilePath(submissionId))) {
        throw new Exception("JCR file was not deleted");
    }
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) IOException(java.io.IOException) 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 22 with WithUserDetails

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

the class AnalysisSubmissionControllerTests method testApproveSubmissionResultByNonOwner.

@Test
@WithUserDetails(STUDY_LEAD)
@DatabaseSetups({ @DatabaseSetup("/data/analysis/submission/submission-executed.xml") })
@ExpectedDatabase(value = "/data/analysis/submission/submission-executed.xml", assertionMode = NON_STRICT)
public void testApproveSubmissionResultByNonOwner() throws Exception {
    ApproveDTO approveDTO = new ApproveDTO(SUBMISSION_ID, true, null, null);
    prepareAnalysisFile(STUDY_ID, ANALYSIS_ID);
    prepareSubmissionGroupFile(STUDY_ID, ANALYSIS_ID, SUBMISSION_GROUP_ID);
    mvc.perform(post("/api/v1/analysis-management/submissions/{submissionId}/approveresult", 1).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(approveDTO))).andExpect(PERMISSION_DENIED_CODE);
}
Also used : ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 23 with WithUserDetails

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

the class AnalysisSubmissionControllerTests method testManualUploadingSubmissionResult.

@Test
@WithUserDetails(DATA_NODE_ONWER)
@DatabaseSetups({ @DatabaseSetup("/data/analysis/submission/submission-in-progress.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/analysis/submission/result/submission-in-progress-with-added-file.xml", assertionMode = NON_STRICT) })
public void testManualUploadingSubmissionResult() throws Exception {
    FileInputStream fileInputStream = new FileInputStream(this.getClass().getResource("/test.jpg").getPath());
    MockMultipartFile multipartFile = new MockMultipartFile("file", "test.sql", "image/jpeg", fileInputStream);
    mvc.perform(fileUpload("/api/v1/analysis-management/submissions/result/manualupload").file(multipartFile).contentType(MULTIPART_FORM_DATA).param("submissionId", "1").param("label", "test.sql")).andExpect(NO_ERROR_CODE);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) 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)

Example 24 with WithUserDetails

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

the class StudyControllerTests method testAddExistedParticipant.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant.xml", assertionMode = NON_STRICT) })
public void testAddExistedParticipant() throws Exception {
    AddStudyParticipantDTO participantDTO = new AddStudyParticipantDTO();
    participantDTO.setUserId(USER_2_UUID);
    participantDTO.setRole(CONTRIBUTOR);
    mvc.perform(post("/api/v1/study-management/studies/" + STUDY_ID + "/participants").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(jsonPath("$.errorCode").value(ALREADY_EXIST.getCode()));
}
Also used : AddStudyParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO) 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 25 with WithUserDetails

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

the class StudyControllerTests method testUpdateStudyTitle.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-title.xml", assertionMode = NON_STRICT) })
public void testUpdateStudyTitle() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setTitle("Study Title New");
    updatedStudyDTO.setDescription("description");
    StudyTypeDTO type = new StudyTypeDTO(STUDY_TYPE_ID);
    type.setName("type");
    updatedStudyDTO.setType(type);
    StudyStatusDTO status = new StudyStatusDTO(STUDY_STATUS_ID, "Initiate");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_TITLE_JSON_OBJECT, UPDATED_STUDY_TITLE);
}
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)

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