static Room newRoom(RoomType type, int capacity) {

    Room room = new Room();
    room.setType(type);
    room.setCapacity(capacity);
    return room;
  }
  @Test(expected = IllegalArgumentException.class)
  public void updateRoomNegativeCapacity() {

    Room room = newRoom(RoomType.bungalow, 4);
    manager.createRoom(room);
    Long roomId = room.getId();
    room = manager.getRoom(roomId);
    room.setCapacity(-1);
    manager.updateRoom(room);
  }
Ejemplo n.º 3
0
  public void readRoom() {

    String csvFile = "Leslokalen.csv";
    BufferedReader br = null;
    String line = "";
    String cvsSplitBy = ";";

    try {
      ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-module.xml");
      Resource resource = appContext.getResource("Leslokalen.csv");
      InputStream is = resource.getInputStream();
      br = new BufferedReader(new InputStreamReader(is));
      br.readLine(); // Read first line with Header

      ArrayList<Room> roomList = new ArrayList<Room>();

      while ((line = br.readLine()) != null) {

        // use comma as separator
        String[] room = line.split(cvsSplitBy);
        Room roomObj = new Room();
        roomObj.setName(room[0]);
        roomObj.setBuilding(room[1]);
        roomObj.setFloor(room[2]);
        roomObj.setCapacity(Integer.valueOf(room[3]));
        roomObj.setPlaces(Integer.valueOf(room[4]));
        roomObj.setProjectorEquipped(room[5].equals(1));
        roomObj.setSmartBoardEquipped(room[6].equals(1));
        roomObj.setRecorderEquipped(room[7].equals(1));

        roomList.add(roomObj);

        if (Globals.DEBUG == 1) {
          System.out.println(roomObj);
        }
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    System.out.println("Done");
  }
  @Test
  public void updateRoom() {
    Room room = newRoom(RoomType.bungalow, 4);
    Room g2 = newRoom(RoomType.apartment, 2);
    manager.createRoom(room);
    manager.createRoom(g2);
    Long roomId = room.getId();

    room.setType(RoomType.apartment);
    manager.updateRoom(room);
    room = manager.getRoom(roomId);
    assertEquals(RoomType.apartment, room.getType());
    assertEquals(4, room.getCapacity());

    room.setCapacity(2);
    manager.updateRoom(room);
    room = manager.getRoom(roomId);
    assertEquals(RoomType.apartment, room.getType());
    assertEquals(2, room.getCapacity());

    // Check if updates didn't affected other records
    assertRoomDeepEquals(g2, manager.getRoom(g2.getId()));
  }