52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
package com.guo.learningprogresstracker;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.guo.learningprogresstracker.entity.TestTableEntity;
|
|
import com.guo.learningprogresstracker.service.impl.TestTableServiceImpl;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
/**
|
|
* 用于测试数据库连接是否成功
|
|
*/
|
|
@SpringBootTest
|
|
public class DataSourceTest {
|
|
|
|
@Autowired
|
|
TestTableServiceImpl testTableService;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
StpUtil.login("1", "test_driver");
|
|
}
|
|
|
|
@Test
|
|
public void testAdd(){
|
|
TestTableEntity testTableEntity = new TestTableEntity();
|
|
testTableEntity.setIdName("guo_test");
|
|
boolean save = testTableService.save(testTableEntity);
|
|
|
|
assertTrue(save,"创建idName为guo_test的数据成功");
|
|
}
|
|
|
|
@Test
|
|
public void testDelete(){
|
|
TestTableEntity testTableEntity = new TestTableEntity();
|
|
testTableEntity.setIdName("guo_test_delete");
|
|
testTableService.save(testTableEntity);
|
|
|
|
HashMap<String, Object> stringStringHashMap = new HashMap<>();
|
|
stringStringHashMap.put("id_name", "guo_test_delete");
|
|
boolean delete = testTableService.removeByMap(stringStringHashMap);
|
|
|
|
assertTrue(delete,"删除idName为guo_test的数据失败");
|
|
|
|
}
|
|
}
|