完成房间信息接口编写,通过单元测试

This commit is contained in:
freeebird 2018-11-13 17:33:48 +08:00
parent 8c14346247
commit ed537bd926
4 changed files with 119 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import cn.mafangui.hotel.entity.Room;
import cn.mafangui.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@ -15,11 +16,42 @@ public class RoomController {
@Autowired
private RoomService roomService;
@RequestMapping(value = "/all")
public List<Room> getAllRoom(){
List<Room> result = roomService.selectAll();
for (Room r:result) {
@RequestMapping(value = "/add")
public int addRoom(String roomNumber,int typeId,String roomType,double roomPrice,double roomDiscount,int roomStatus,String remark){
Room room = new Room(roomNumber,typeId,roomType,roomPrice,roomDiscount,roomStatus,remark);
return roomService.insert(room);
}
return result;
@RequestMapping(method = RequestMethod.POST,value = "/delete")
public int deleteRoom(int roomId){
return roomService.delete(roomId);
}
@RequestMapping(value = "/update")
public int updateRoom(int roomId,String roomNumber,int typeId,
String roomType,double roomPrice,double roomDiscount,int roomStatus,String remark){
Room room = new Room(roomNumber,typeId,roomType,roomPrice,roomDiscount,roomStatus,remark);
room.setRoomId(roomId);
return roomService.update(room);
}
@RequestMapping(value = "/withId")
public Room getById(int roomId){
return roomService.selectById(roomId);
}
@RequestMapping(value = "/withType")
public List<Room> getByType(int typeId){
return roomService.selectByType(typeId);
}
@RequestMapping(value = "/withStatus")
public List<Room> getByStatus(int roomStatus){
return roomService.selectByStatus(roomStatus);
}
@RequestMapping(value = "/all")
public List<Room> getAll(){
return roomService.selectAll();
}
}

View File

@ -22,6 +22,12 @@ public class RoomTypeController {
return roomTypeService.findAllType();
}
@RequestMapping(value = "/withId")
public RoomType getById(int typeId){
return roomTypeService.selectById(typeId);
}
@RequestMapping(method = RequestMethod.POST,value = "/add")
public int addRoomType(String roomType,Double price,Double discount,int area,
int bedNum,String bedSize,int window,String remark){

View File

@ -103,6 +103,19 @@ public class Room {
this.updateTime = updateTime;
}
public Room() {
}
public Room(String roomNumber, Integer typeId, String roomType, Double roomPrice, Double roomDiscount, Integer roomStatus, String remark) {
this.roomNumber = roomNumber;
this.typeId = typeId;
this.roomType = roomType;
this.roomPrice = roomPrice;
this.roomDiscount = roomDiscount;
this.roomStatus = roomStatus;
this.remark = remark;
}
@Override
public String toString() {
return "Room{" +

View File

@ -0,0 +1,61 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Room;
import org.junit.Assert;
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.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class RoomControllerTest {
@Autowired
RoomController rc;
@Test
public void addRoom() {
Assert.assertEquals(1,rc.addRoom("100",2,"单人房",
108.0,20.0,1,"1 person"));
}
@Test
public void deleteRoom() {
Assert.assertEquals(1,rc.deleteRoom(3));
}
@Test
public void updateRoom() {
Assert.assertEquals(1,rc.updateRoom(2,"200",2,"单人房",
108.0,20.0,1,"1 person"));
}
@Test
public void getById() {
int res = rc.getById(2).getTypeId();
Assert.assertEquals(2,res);
}
@Test
public void getByType() {
int res = rc.getByType(2).size();
Assert.assertEquals(1,res);
}
@Test
public void getByStatus() {
int res = rc.getByStatus(1).size();
Assert.assertEquals(2,res);
}
@Test
public void getAll() {
int res = rc.getAll().size();
Assert.assertEquals(2,res);
}
}