Search in sources :

Example 36 with ExpectedDatabase

use of com.github.springtestdbunit.annotation.ExpectedDatabase 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 37 with ExpectedDatabase

use of com.github.springtestdbunit.annotation.ExpectedDatabase 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 38 with ExpectedDatabase

use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testCreateUser.

@Test
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/registered-user-and-admin.xml", assertionMode = DatabaseAssertionMode.NON_STRICT)
public void testCreateUser() throws Exception {
    CommonUserRegistrationDTO inputDTO = getCommonUserRegistrationDTO(PASSWORD);
    MvcResult mvcResult = mvc.perform(post("/api/v1/auth/registration").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(inputDTO)).with(anonymous())).andExpect(OK_STATUS).andReturn();
}
Also used : CommonUserRegistrationDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonUserRegistrationDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 39 with ExpectedDatabase

use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.

the class AnalysisSubmissionControllerTests method testApproveSubmissionByNonOwner.

@Test
@WithUserDetails(DATA_NODE_USER)
@DatabaseSetups({ @DatabaseSetup("/data/analysis/submission/submission-pending.xml") })
@ExpectedDatabase(value = "/data/analysis/submission/submission-pending.xml", assertionMode = NON_STRICT)
public void testApproveSubmissionByNonOwner() 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}/approve", 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 40 with ExpectedDatabase

use of com.github.springtestdbunit.annotation.ExpectedDatabase 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)

Aggregations

ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)76 Test (org.junit.Test)72 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)53 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)42 MvcResult (org.springframework.test.web.servlet.MvcResult)26 Account_ (indi.mybatis.flying.pojo.Account_)25 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)20 IfProfileValue (org.springframework.test.annotation.IfProfileValue)19 Role_ (indi.mybatis.flying.pojo.Role_)17 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)11 HashMap (java.util.HashMap)9 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)7 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)7 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)6 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)6 PageParam (indi.mybatis.flying.pagination.PageParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Order (indi.mybatis.flying.pagination.Order)3 SortParam (indi.mybatis.flying.pagination.SortParam)3 JSONArray (org.json.JSONArray)3