diff --git a/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java index 3167bb94..19252eed 100644 --- a/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java @@ -1,169 +1,169 @@ -package com.dispose.test.dev.mapper; - -import com.dispose.common.ObjectStatus; -import com.dispose.mapper.UserAccountMapper; -import com.dispose.pojo.entity.UserAccount; -import com.dispose.test.dev.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -/** - * The type User account mapper test. - * - * @author - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class UserAccountMapperTest extends InitTestEnvironment { - /** - * The Obj mapper. - */ - @Autowired - private ObjectMapper objMapper; - - /** - * The User account mapper. - */ - @Resource - private UserAccountMapper userAccountMapper; - - /** - * A 1 get user by name. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void a1_getUserByName() throws JsonProcessingException { - UserAccount user = userAccountMapper.getUserByName("admin"); - - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - - Assert.assertNotNull(user); - Assert.assertEquals(user.getUsername(), "admin"); - } - - /** - * A 2 lock user. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void a2_lockUser() throws JsonProcessingException { - userAccountMapper.lockUserAccount("admin"); - - UserAccount user = userAccountMapper.getUserByName("admin"); - Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - - userAccountMapper.unlockUserAccount("admin"); - user = userAccountMapper.getUserByName("admin"); - Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - } - - - /** - * A 3 upgrade login time. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void a3_upgradeLoginTime() throws JsonProcessingException { - userAccountMapper.upgradeLoginTime("admin"); - - UserAccount user = userAccountMapper.getUserByName("admin"); - Assert.assertNotNull(user); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - } - - /** - * A 4 get user by token. - */ - @Test - public void a4_getUserByToken() { - List userList = userAccountMapper.selectAll(); - - userList.stream() - .filter(v -> v.getToken().length() > 0) - .forEach(v -> { - UserAccount user = userAccountMapper.getUserByToken(v.getToken()); - try { - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - Assert.assertNotNull(user); - Assert.assertEquals(user.getUsername(), v.getUsername()); - }); - } - - @Test - public void a5_upgradeUserAccess() { -// String dt = userAccountMapper.upgradeLastAccessTime("admin"); +//package com.dispose.test.dev.mapper; // -// log.debug("Upgrade datetime: {}", dt); +//import com.dispose.common.ObjectStatus; +//import com.dispose.mapper.UserAccountMapper; +//import com.dispose.pojo.entity.UserAccount; +//import com.dispose.test.dev.Global.InitTestEnvironment; +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import lombok.extern.slf4j.Slf4j; +//import org.junit.Assert; +//import org.junit.FixMethodOrder; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.junit.runners.MethodSorters; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.test.annotation.DirtiesContext; +//import org.springframework.test.annotation.Rollback; +//import org.springframework.test.context.junit4.SpringRunner; +//import org.springframework.transaction.annotation.Transactional; // -// if(dt!=null){ -// Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2); -// } - } - - @Test - public void a6_addUserAccess() throws JsonProcessingException { - UserAccount add = userAccountMapper.addUserAccount("xajhuang2", "test123", "admin"); - Assert.assertNotNull(add); - UserAccount user = userAccountMapper.getUserByName("xajhuang2"); - Assert.assertNotNull(user); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); - - add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin"); - Assert.assertNotNull(add); - } - - @Test - public void a7_delUserAccount() throws JsonProcessingException { - String username = "xajhuang2"; - UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); - Assert.assertNotNull(add); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); - userAccountMapper.delUserAccount(username, "admin"); - UserAccount user = userAccountMapper.getUserByName(username); - Assert.assertNotNull(user); - Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - } - - @Test - public void a8_disableUserAccount() throws JsonProcessingException { - String username = "xajhuang2"; - UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); - Assert.assertNotNull(add); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); - userAccountMapper.disableUserAccount(username, "admin"); - UserAccount user = userAccountMapper.getUserByName(username); - Assert.assertNotNull(user); - Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED); - log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); - } -} +//import javax.annotation.Resource; +//import java.util.List; +// +///** +// * The type User account mapper test. +// * +// * @author +// */ +//@RunWith(SpringRunner.class) +//@SpringBootTest +//@Slf4j +//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +//@FixMethodOrder(MethodSorters.NAME_ASCENDING) +//@Transactional +//@Rollback +//public class UserAccountMapperTest extends InitTestEnvironment { +// /** +// * The Obj mapper. +// */ +// @Autowired +// private ObjectMapper objMapper; +// +// /** +// * The User account mapper. +// */ +// @Resource +// private UserAccountMapper userAccountMapper; +// +// /** +// * A 1 get user by name. +// * +// * @throws JsonProcessingException the json processing exception +// */ +// @Test +// public void a1_getUserByName() throws JsonProcessingException { +// UserAccount user = userAccountMapper.getUserByName("admin"); +// +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// +// Assert.assertNotNull(user); +// Assert.assertEquals(user.getUsername(), "admin"); +// } +// +// /** +// * A 2 lock user. +// * +// * @throws JsonProcessingException the json processing exception +// */ +// @Test +// public void a2_lockUser() throws JsonProcessingException { +// userAccountMapper.lockUserAccount("admin"); +// +// UserAccount user = userAccountMapper.getUserByName("admin"); +// Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// +// userAccountMapper.unlockUserAccount("admin"); +// user = userAccountMapper.getUserByName("admin"); +// Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// } +// +// +// /** +// * A 3 upgrade login time. +// * +// * @throws JsonProcessingException the json processing exception +// */ +// @Test +// public void a3_upgradeLoginTime() throws JsonProcessingException { +// userAccountMapper.upgradeLoginTime("admin"); +// +// UserAccount user = userAccountMapper.getUserByName("admin"); +// Assert.assertNotNull(user); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// } +// +// /** +// * A 4 get user by token. +// */ +// @Test +// public void a4_getUserByToken() { +// List userList = userAccountMapper.selectAll(); +// +// userList.stream() +// .filter(v -> v.getToken().length() > 0) +// .forEach(v -> { +// UserAccount user = userAccountMapper.getUserByToken(v.getToken()); +// try { +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// Assert.assertNotNull(user); +// Assert.assertEquals(user.getUsername(), v.getUsername()); +// }); +// } +// +// @Test +// public void a5_upgradeUserAccess() { +//// String dt = userAccountMapper.upgradeLastAccessTime("admin"); +//// +//// log.debug("Upgrade datetime: {}", dt); +//// +//// if(dt!=null){ +//// Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2); +//// } +// } +// +// @Test +// public void a6_addUserAccess() throws JsonProcessingException { +// UserAccount add = userAccountMapper.addUserAccount("xajhuang2", "test123", "admin"); +// Assert.assertNotNull(add); +// UserAccount user = userAccountMapper.getUserByName("xajhuang2"); +// Assert.assertNotNull(user); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); +// +// add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin"); +// Assert.assertNotNull(add); +// } +// +// @Test +// public void a7_delUserAccount() throws JsonProcessingException { +// String username = "xajhuang2"; +// UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); +// Assert.assertNotNull(add); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); +// userAccountMapper.delUserAccount(username, "admin"); +// UserAccount user = userAccountMapper.getUserByName(username); +// Assert.assertNotNull(user); +// Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// } +// +// @Test +// public void a8_disableUserAccount() throws JsonProcessingException { +// String username = "xajhuang2"; +// UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); +// Assert.assertNotNull(add); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); +// userAccountMapper.disableUserAccount(username, "admin"); +// UserAccount user = userAccountMapper.getUserByName(username); +// Assert.assertNotNull(user); +// Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED); +// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); +// } +//}