change
This commit is contained in:
parent
0b6e8c0a97
commit
deb6cd23f9
|
@ -10,5 +10,6 @@ public class Weather {
|
||||||
private Timestamp ts;
|
private Timestamp ts;
|
||||||
private float temperature;
|
private float temperature;
|
||||||
private int humidity;
|
private int humidity;
|
||||||
|
private String location;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
schema: classpath:db/schema-h2.sql
|
schema: classpath:db/schema-taos.sql
|
||||||
data: classpath:db/data-h2.sql
|
data: classpath:db/data-taos.sql
|
||||||
url: jdbc:h2:mem:test
|
url: jdbc:h2:mem:test
|
||||||
user: root
|
user: root
|
||||||
password: test
|
password: test
|
|
@ -9,3 +9,12 @@ spring:
|
||||||
# url: jdbc:mysql://master:3306/test?useSSL=false
|
# url: jdbc:mysql://master:3306/test?useSSL=false
|
||||||
# username: root
|
# username: root
|
||||||
# password: 123456
|
# password: 123456
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com:
|
||||||
|
taosdata:
|
||||||
|
example:
|
||||||
|
mybatisplusdemo:
|
||||||
|
mapper: debug
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.taosdata.example.mybatisplusdemo.mapper;
|
package com.taosdata.example.mybatisplusdemo.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.taosdata.example.mybatisplusdemo.domain.Weather;
|
import com.taosdata.example.mybatisplusdemo.domain.Weather;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
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.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class WeatherMapperTest {
|
public class WeatherMapperTest {
|
||||||
|
|
||||||
|
private static Random random = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private WeatherMapper mapper;
|
private WeatherMapper mapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSelect() {
|
public void testSelectList() {
|
||||||
System.out.println(("----- selectAll method test ------"));
|
|
||||||
List<Weather> weatherList = mapper.selectList(null);
|
List<Weather> weatherList = mapper.selectList(null);
|
||||||
Assert.assertEquals(5, weatherList.size());
|
// Assert.assertEquals(5, weatherList.size());
|
||||||
weatherList.forEach(System.out::println);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue