diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Weather.java b/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Weather.java index ade926feb2a0e444b286da26da337c14b59b8cb1..361757411a15d29e742a07a92060e20190921223 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Weather.java +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Weather.java @@ -10,5 +10,6 @@ public class Weather { private Timestamp ts; private float temperature; private int humidity; + private String location; } diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-dev.yml b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-dev.yml index e794fd9fbcef13db5a1486857b7906629bd8cfe5..bc60de586063621fc36952ea0688489dda8717da 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-dev.yml +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-dev.yml @@ -1,8 +1,8 @@ spring: datasource: driver-class-name: org.h2.Driver - schema: classpath:db/schema-h2.sql - data: classpath:db/data-h2.sql + schema: classpath:db/schema-taos.sql + data: classpath:db/data-taos.sql url: jdbc:h2:mem:test user: root password: test \ No newline at end of file diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml index 9eb2ee66ebe8126db86b60905fcfdd32887b1356..c1d51ea8b980211c99ccf63f047c9bb42e1d9b15 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml @@ -9,3 +9,12 @@ spring: # url: jdbc:mysql://master:3306/test?useSSL=false # username: root # password: 123456 + +logging: + level: + com: + taosdata: + example: + mybatisplusdemo: + mapper: debug + diff --git a/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java b/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java index 4354de883db72b9c36003337f92fe1f3834ba7d7..50a0c12b1541865fe6a472b85a32c0747298280d 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java +++ b/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java @@ -1,5 +1,6 @@ package com.taosdata.example.mybatisplusdemo.mapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.taosdata.example.mybatisplusdemo.domain.Weather; import org.junit.Assert; import org.junit.Test; @@ -8,22 +9,83 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.sql.Timestamp; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Random; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class WeatherMapperTest { + private static Random random = new Random(System.currentTimeMillis()); + @Autowired private WeatherMapper mapper; @Test - public void testSelect() { - System.out.println(("----- selectAll method test ------")); + public void testSelectList() { List weatherList = mapper.selectList(null); - Assert.assertEquals(5, weatherList.size()); +// Assert.assertEquals(5, weatherList.size()); weatherList.forEach(System.out::println); } + @Test + public void testInsert() { + Weather weather = new Weather(); + weather.setTs(new Timestamp(System.currentTimeMillis())); + weather.setTemperature(random.nextFloat() * 50); + weather.setHumidity(random.nextInt(100)); + weather.setLocation("望京"); + int affectRows = mapper.insert(weather); + Assert.assertEquals(1, affectRows); + } + + @Test + public void testDelete() { + mapper.delete(new QueryWrapper().eq("location", "望京")); + } + + @Test + public void testDeleteByMap() { + Map map = new HashMap<>(); + map.put("location", "望京"); + int affectRows = mapper.deleteByMap(map); +// Assert.assertEquals(0, affectRows); + } + + @Test + public void testSelectOne() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("location", "beijing"); + Weather weather = mapper.selectOne(wrapper); + System.out.println(weather); + Assert.assertEquals(12.22f, weather.getTemperature(), 0.00f); + Assert.assertEquals(45, weather.getHumidity()); + Assert.assertEquals("beijing", weather.getLocation()); + } + + @Test + public void testSelectByMap() { + Map map = new HashMap<>(); + map.put("location", "beijing"); + List weathers = mapper.selectByMap(map); + Assert.assertEquals(1, weathers.size()); + } + + @Test + public void testSelectObjs() { + List ts = mapper.selectObjs(null); + System.out.println(ts); +// Assert.assertEquals(5, ts.size()); + } + + @Test + public void testSelectCount() { + int count = mapper.selectCount(null); + Assert.assertEquals(5, count); + } + } \ No newline at end of file