81 lines
2.3 KiB

package com.yipin.liuwanr;
import com.yipin.liuwanr.entity.City;
import com.yipin.liuwanr.mapper.CityMapper;
import com.yipin.liuwanr.service.CityService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CityServiceTest {
@Autowired
private CityService cityService;
@Autowired
private CityMapper cityMapper;
/**
* 新增城市信息方法测试
*/
/*@Test
@Transactional
public void testAddCity() {
City city = new City();
city.setCityName("hhhh");
city.setProvinceId(2);
HashMap<String, Object> map = cityService.addCity(city);
map.forEach((key, value) -> System.out.println("key = " + key + " ===> value = " + value));
}*/
/**
* 查询城市信息方法测试
*/
@Test
public void testQueryCity() {
HashMap<String, Object> map = cityService.queryCity(1);
Integer retcode = (Integer) map.get("retcode");
System.out.println(retcode);
if (retcode == 200) {
List<City> cities = (List<City>) map.get("retvalue");
cities.forEach(item -> {
System.out.println(item.toString());
});
} else {
String msg = (String) map.get("retvalue");
System.out.println(msg);
}
}
/**
* 删除城市信息方法测试
*/
@Test
@Transactional
public void testDeleteCity() {
HashMap<String, Object> map = cityService.deleteCity(1);
map.forEach((key, value) -> System.out.println("key = " + key + " ===> value = " + value.toString()));
}
/**
* 删除城市信息方法测试
*/
@Test
@Transactional
public void testUpdateCity() {
City city = new City();
city.setCityId(1);
city.setCityName("hhhh");
city.setProvinceId(2);
HashMap<String, Object> map = cityService.updateCity(city);
map.forEach((key, value) -> System.out.println("key = " + key + " ===> value = " + value.toString()));
}
}