Browse Source

修改 mysql 的 test 日志组件为 logback

miemie 7 years ago
parent
commit
28d3a3f6ea

+ 1 - 1
mybatis-plus/build.gradle

@@ -18,5 +18,5 @@ dependencies {
     testCompile rootProject.ext.dependencies["postgresql"]
     testCompile rootProject.ext.dependencies["oracle"]
     testCompile rootProject.ext.dependencies["mysql"]
-    testCompile "org.apache.logging.log4j:log4j-slf4j-impl:2.11.0"
+    testCompile 'ch.qos.logback:logback-classic:1.2.3'
 }

+ 16 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlTestDataMapperTest.java

@@ -19,6 +19,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -70,19 +71,24 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void deleteById() {
         mapper.deleteById(1014132604940615682L);
+        logicMapper.deleteById(1014132604940615682L);
     }
 
     @Test
+    @Transactional
     public void deleteByMap() {
         Map<String, Object> map = new HashMap<>();
         map.put("id", 1014361515785568258L);
         map.put("test_int", 5);
         mapper.deleteByMap(map);
+        logicMapper.deleteByMap(map);
     }
 
     @Test
+    @Transactional
     public void delete() {
         mapper.delete(new QueryWrapper<TestData>().lambda()
             .eq(TestData::getId, 1014132604940615682L)
@@ -90,16 +96,19 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void deleteBatchIds() {
         mapper.deleteBatchIds(Arrays.asList(1014132604940615682L, 1014132604940615652L));
     }
 
     @Test
+    @Transactional
     public void updateByIdTest() {
         mapper.updateById(new TestData().setId(1014132604940615682L).setTestInt(1111111111));
     }
 
     @Test
+    @Transactional
     public void updateTest() {
         // type 1
         mapper.update(new TestData(), null);
@@ -127,16 +136,19 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void selectById() {
         mapper.selectById(1L);
     }
 
     @Test
+    @Transactional
     public void selectBatchIds() {
         mapper.selectBatchIds(Arrays.asList(1014132604940615682L, 1014132604940615652L));
     }
 
     @Test
+    @Transactional
     public void commonSelectList() {
         println(mapper.selectList(new QueryWrapper<TestData>()
             .eq("id", 1L)
@@ -145,6 +157,7 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void specialSelectList() {
         println(mapper.selectList(new QueryWrapper<TestData>().lambda()
             .nested(i -> i.eq(TestData::getId, 1L))
@@ -159,12 +172,14 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void update() {
         mapper.update(new TestData().setId(1L).setTestStr("123123"),
             new UpdateWrapper<TestData>().eq("id", 1L));
     }
 
     @Test
+    @Transactional
     public void selectByMap() {
         Map<String, Object> map = new HashMap<>();
         map.put("id", 1L);
@@ -173,6 +188,7 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
+    @Transactional
     public void selectPage() {
         IPage<TestData> page = new Page<>();
         page.setSize(5).setCurrent(1);

+ 0 - 18
mybatis-plus/src/test/resources/log4j2.xml

@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration status="WARN">
-    <!--先定义所有的appender-->
-    <Appenders>
-        <!--这个输出控制台的配置-->
-        <Console name="Console" target="SYSTEM_OUT">
-            <!--这个都知道是输出日志的格式  线程信息:[%t]-->
-            <PatternLayout pattern="%d{ABSOLUTE} [%t] %level %class %L %M - %m%n"/>
-        </Console>
-    </Appenders>
-
-    <Loggers>
-        <!--根logger-->
-        <Root level="debug">
-            <AppenderRef ref="Console"/>
-        </Root>
-    </Loggers>
-</configuration>

+ 13 - 0
mybatis-plus/src/test/resources/logback.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="false" debug="false">
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- encoder 默认配置为PatternLayoutEncoder -->
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <logger name="com.baomidou.mybatisplus.test" level="DEBUG" additivity="false">
+        <appender-ref ref="STDOUT"/>
+    </logger>
+</configuration>