REM:
1. 清理部分单测用例
This commit is contained in:
HuangXin 2020-09-27 18:23:35 +08:00
parent ed80e3fa8a
commit 17329dfe02
1 changed files with 167 additions and 167 deletions

View File

@ -1,169 +1,169 @@
package com.dispose.test.dev.mapper; //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 <huangxin@cmhi.chinamoblie.com>
*/
@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<UserAccount> 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); //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){ //import javax.annotation.Resource;
// Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2); //import java.util.List;
// } //
} ///**
// * The type User account mapper test.
@Test // *
public void a6_addUserAccess() throws JsonProcessingException { // * @author <huangxin@cmhi.chinamoblie.com>
UserAccount add = userAccountMapper.addUserAccount("xajhuang2", "test123", "admin"); // */
Assert.assertNotNull(add); //@RunWith(SpringRunner.class)
UserAccount user = userAccountMapper.getUserByName("xajhuang2"); //@SpringBootTest
Assert.assertNotNull(user); //@Slf4j
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); //@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); //@FixMethodOrder(MethodSorters.NAME_ASCENDING)
//@Transactional
add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin"); //@Rollback
Assert.assertNotNull(add); //public class UserAccountMapperTest extends InitTestEnvironment {
} // /**
// * The Obj mapper.
@Test // */
public void a7_delUserAccount() throws JsonProcessingException { // @Autowired
String username = "xajhuang2"; // private ObjectMapper objMapper;
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); //
Assert.assertNotNull(add); // /**
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); // * The User account mapper.
userAccountMapper.delUserAccount(username, "admin"); // */
UserAccount user = userAccountMapper.getUserByName(username); // @Resource
Assert.assertNotNull(user); // private UserAccountMapper userAccountMapper;
Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED); //
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); // /**
} // * A 1 get user by name.
// *
@Test // * @throws JsonProcessingException the json processing exception
public void a8_disableUserAccount() throws JsonProcessingException { // */
String username = "xajhuang2"; // @Test
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); // public void a1_getUserByName() throws JsonProcessingException {
Assert.assertNotNull(add); // UserAccount user = userAccountMapper.getUserByName("admin");
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); //
userAccountMapper.disableUserAccount(username, "admin"); // log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
UserAccount user = userAccountMapper.getUserByName(username); //
Assert.assertNotNull(user); // Assert.assertNotNull(user);
Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED); // Assert.assertEquals(user.getUsername(), "admin");
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); // }
} //
} // /**
// * 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<UserAccount> 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));
// }
//}