Search in sources :

Example 36 with DatabaseSetups

use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.

the class BatchProcessTest method testBatchInsert.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchInsert.datasource.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchInsert.datasource.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchInsert.datasource.result.xml") })
public void testBatchInsert() {
    Collection<Account_> ac = new ArrayList<>();
    Role_ r1 = new Role_(), r2 = new Role_(), r3 = new Role_();
    r1.setId(1);
    r2.setId(2);
    r3.setId(3);
    Account_ a = new Account_();
    a.setId(1L);
    // a.setName("ann");
    a.setEmail("ann@live.cn");
    a.setPassword("5a690d842935c51f26f473e025c1b97a");
    a.setActivated(true);
    a.setActivateValue("");
    // a.setRole(r1);
    ac.add(a);
    Account_ a2 = new Account_();
    a2.setId(2L);
    a2.setName("bob");
    a2.setEmail("bob@live.cn");
    a2.setPassword("6a690d842935c51f26f473e025c1b97a");
    a2.setActivated(true);
    a2.setActivateValue("");
    a2.setDelegateRoleId(23L);
    ac.add(a2);
    Account_ a3 = new Account_();
    a3.setId(3L);
    a3.setName("carl");
    a3.setEmail("carl@live.cn");
    a3.setPassword("7a690d842935c51f26f473e025c1b97a");
    a3.setActivated(true);
    a3.setActivateValue("");
    a3.setRole(r3);
    ac.add(a3);
    accountService.insertBatch(ac);
    System.out.println(JSONObject.toJSONString(ac));
    Collection<Account_> ac2 = new ArrayList<>();
    try {
        accountService.insertBatch(ac2);
        // below code should never reach
        Assert.assertTrue(false);
    } catch (Exception e) {
    }
    System.out.println(JSONObject.toJSONString(ac2));
}
Also used : ArrayList(java.util.ArrayList) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 37 with DatabaseSetups

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

Example 38 with DatabaseSetups

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

the class AnalysisControllerTests method testCreateAnalysis.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/empty-analysis.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/analysis.xml", assertionMode = NON_STRICT) })
public void testCreateAnalysis() throws Exception {
    AnalysisCreateDTO analysisDTO = new AnalysisCreateDTO();
    analysisDTO.setTitle(ANALYSIS_TITLE);
    analysisDTO.setTypeId(ANALYSIS_TYPE_ID);
    analysisDTO.setStudyId(STUDY_ID);
    MvcResult mvcResult = mvc.perform(post("/api/v1/analysis-management/analyses").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(analysisDTO))).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andExpect(jsonPath("$.result.id").isNotEmpty()).andReturn();
    JSONObject result = getResultJSONObject(mvcResult);
    JSONAssert.assertEquals(ANALYSIS_JSON_OBJECT, result, false);
}
Also used : AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) JSONObject(org.json.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult) 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 39 with DatabaseSetups

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

the class AnalysisControllerTests method testUpdateAnalysisTitle.

@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-title-updating.xml", assertionMode = NON_STRICT) })
public void testUpdateAnalysisTitle() throws Exception {
    AnalysisUpdateDTO analysisDTO = new AnalysisUpdateDTO();
    analysisDTO.setTitle(UPDATED_ANALYSIS_TITLE);
    analysisDTO.setTypeId(ANALYSIS_TYPE_ID);
    testUpdate(analysisDTO, UPDATED_ANALYSIS_JSON_OBJECT, UPDATED_ANALYSIS_TITLE);
}
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 40 with DatabaseSetups

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

Aggregations

DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)50 Test (org.junit.Test)49 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)44 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)26 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 Account_ (indi.mybatis.flying.pojo.Account_)15 Role_ (indi.mybatis.flying.pojo.Role_)10 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)8 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)7 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)6 Detail2_ (indi.mybatis.flying.pojo.Detail2_)5 IfProfileValue (org.springframework.test.annotation.IfProfileValue)5 UpdateParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 AnalysisUpdateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO)3 Account2_ (indi.mybatis.flying.pojo.Account2_)3 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)3 Role2_ (indi.mybatis.flying.pojo.Role2_)3