Search in sources :

Example 46 with DatabaseSetups

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

the class StudyControllerTests method testUpdateContributorRoleForLastLeadInvestigator.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant-before-changing-role.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-before-changing-role.xml", assertionMode = NON_STRICT) })
public void testUpdateContributorRoleForLastLeadInvestigator() throws Exception {
    UpdateParticipantDTO participantDTO = new UpdateParticipantDTO();
    participantDTO.setRole(CONTRIBUTOR.name());
    mvc.perform(put("/api/v1/study-management/studies/" + STUDY_ID + "/participants/" + UserIdUtils.idToUuid(ADMIN_ID)).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(jsonPath("$.errorCode").value(VALIDATION_ERROR.getCode()));
}
Also used : UpdateParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO) 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 47 with DatabaseSetups

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

the class StudyControllerTests method testUpdateContributorRoleToContributor.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant-with-2-leaders-before-updating.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-with-contributor-and-leader.xml", assertionMode = NON_STRICT) })
public void testUpdateContributorRoleToContributor() throws Exception {
    UpdateParticipantDTO participantDTO = new UpdateParticipantDTO();
    participantDTO.setRole(CONTRIBUTOR.name());
    mvc.perform(put("/api/v1/study-management/studies/" + STUDY_ID + "/participants/" + UserIdUtils.idToUuid(ADMIN_ID)).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(NO_ERROR_CODE).andReturn();
}
Also used : UpdateParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO) 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 48 with DatabaseSetups

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

the class CacheTest method test22.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.result.xml") })
public void test22() {
    String name = "ann";
    String roleName = "user";
    String newRoleName = "admin";
    Account_ a = new Account_();
    Role_ r = new Role_();
    r.setName(roleName);
    roleService.insert(r);
    a.setName(name);
    a.setRole(r);
    accountService.insert(a);
    Account_ account_ = accountService.select(a.getId());
    Assert.assertEquals(roleName, account_.getRole().getName());
    Role_ r12 = roleService.select(r.getId());
    r12.setName(newRoleName);
    roleService.update(r12);
    account_ = accountService.select(a.getId());
    Assert.assertEquals(newRoleName, account_.getRole().getName());
    Account2_ a2 = new Account2_();
    Role2_ r2 = new Role2_();
    r2.setName(roleName);
    role2Service.insert(r2);
    a2.setName(name);
    a2.setRole(r2);
    account2Service.insert(a2);
    Account2_ account2_ = account2Service.select(a2.getId());
    Assert.assertEquals(roleName, account2_.getRole().getName());
    Role2_ r22 = role2Service.select(r2.getId());
    r22.setName(newRoleName);
    role2Service.update(r22);
    account2_ = account2Service.select(a2.getId());
    Assert.assertEquals(newRoleName, account2_.getRole().getName());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) Role2_(indi.mybatis.flying.pojo.Role2_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 49 with DatabaseSetups

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

the class CacheTest method testAccountTypeHandlerUsingCache.

/* 一个证明缓存对跨库关联也有效的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.result.xml") })
public void testAccountTypeHandlerUsingCache() {
    Role_ r = new Role_();
    r.setId(101);
    r.setName("user");
    roleService.insert(r);
    Account_ a = new Account_();
    a.setId(1L);
    a.setEmail("ann@live.cn");
    a.setRole(r);
    accountService.insert(a);
    Account_ a2 = new Account_();
    a2.setId(2L);
    a2.setEmail("bob@live.cn");
    accountService.insert(a2);
    LoginLog_ l = new LoginLog_();
    l.setId(2);
    l.setLoginIP("2");
    loginLogService.insert(l);
    LoginLogSource2 l2 = new LoginLogSource2();
    l2.setId(21);
    l2.setLoginIP("ip0");
    l2.setAccount(a);
    loginLogSource2Service.insert(l2);
    LoginLogSource2 loginLogSource2 = loginLogSource2Service.select(21);
    Assert.assertEquals("user", loginLogSource2.getAccount().getRole().getName());
    Account_ account = accountService.select(1L);
    LoginLogSource2 loginLogSource4 = loginLogSource2Service.select(21);
    loginLogSource4.setLoginIP("ip00");
    loginLogSource2Service.updateNoFlush(loginLogSource4);
    account = accountService.select(1L);
    accountService.update(account);
    LoginLogSource2 loginLogSource5 = loginLogSource2Service.select(21);
    Assert.assertEquals("ip00", loginLogSource5.getLoginIP());
    Assert.assertEquals(1, loginLogSource5.getAccount().getOpLock().intValue());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) LoginLogSource2(indi.mybatis.flying.pojo.LoginLogSource2) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 50 with DatabaseSetups

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

the class NoApplicationContextProviderTest method testNormal.

@Test
@IfProfileValue(name = "NO_PROVIDER", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.result.xml") })
public void testNormal() {
    Account_ a = accountService.selectWithoutCache(1);
    assertEquals("r", a.getRole().getName());
    Role_ r = roleService.selectWithoutCache(51);
    assertEquals("r", r.getName());
    try {
        Account22 account22 = account22Service.select(11);
        fail("Expected an Exception to be thrown");
    } catch (Exception e) {
        assertEquals("Can not find the ApplicationContextProvider bean in the context", e.getCause().getCause().getMessage());
    }
}
Also used : Account22(indi.mybatis.flying.pojo.Account22) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

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