提交 deb6cd23 编写于 作者: Z zyyang

change

上级 0b6e8c0a
......@@ -10,5 +10,6 @@ public class Weather {
private Timestamp ts;
private float temperature;
private int humidity;
private String location;
}
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
......@@ -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
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<Weather> 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<Weather>().eq("location", "望京"));
}
@Test
public void testDeleteByMap() {
Map<String, Object> map = new HashMap<>();
map.put("location", "望京");
int affectRows = mapper.deleteByMap(map);
// Assert.assertEquals(0, affectRows);
}
@Test
public void testSelectOne() {
QueryWrapper<Weather> 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<String, Object> map = new HashMap<>();
map.put("location", "beijing");
List<Weather> weathers = mapper.selectByMap(map);
Assert.assertEquals(1, weathers.size());
}
@Test
public void testSelectObjs() {
List<Object> 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册