@Test public void bookingNumber106() { HttpClient httpClient = null; HttpGet httpGet = null; HttpPost httpPost = null; HttpResponse httpResponse = null; ArrayList<Booking> bookingsArray; Booking booking = new Booking(); String jsonResult; Converters converters = new Converters(); try { JSONObject bookingJS = new JSONObject(); bookingJS.put("room_name", "1.06 Meeting Room"); bookingsArray = new ArrayList<Booking>(); httpPost = new HttpPost("https://zeno.computing.dundee.ac.uk/2014-msc/aralzaim/getBookings.php"); httpPost.setEntity(new StringEntity(bookingJS.toString())); HttpResponse bookingResponse = httpClient.execute(httpPost); jsonResult = converters.inputStreamToString(httpResponse.getEntity().getContent()).toString(); JSONObject jsonObj = new JSONObject(jsonResult); if (jsonObj != null) { JSONArray bookings = jsonObj.getJSONArray("bookings"); for (int i = 0; i < bookings.length(); i++) { JSONObject catObj = (JSONObject) bookings.get(i); booking = new Booking(); booking.setBookedBy(catObj.getString("booked_by")); booking.setBookingStart(converters.stringToDate(catObj.getString("booking_start"))); booking.setBookingEnd(converters.stringToDate(catObj.getString("booking_end"))); booking.setBookingName(catObj.getString("name_purpose")); bookingsArray.add(booking); } } Assert.assertEquals(bookingsArray.size(), 27); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } }
@Test public void searchRoomNoResults() { String emptyRoom; Converters converters = new Converters(); HttpPost httpPost = null; HttpClient httpClient = new DefaultHttpClient(); ArrayList<String> resultList = new ArrayList<String>(); JSONObject newBookingJS = new JSONObject(); try { newBookingJS.put("booking_start", "2015-08-12 09:00:00"); newBookingJS.put("booking_end", "2015-08-12 09:30:00"); newBookingJS.put("moveable_table", false); newBookingJS.put("projector", 1); newBookingJS.put("multiple_computer", 1); newBookingJS.put("capacity", -1); httpPost = new HttpPost("https://zeno.computing.dundee.ac.uk/2014-msc/aralzaim/searchRoom.php"); httpPost.setEntity(new StringEntity(newBookingJS.toString())); HttpResponse httpResponse = httpClient.execute(httpPost); String jsonResult = converters.inputStreamToString(httpResponse.getEntity().getContent()).toString(); System.out.println(jsonResult); JSONObject jsonObj = new JSONObject(jsonResult); if (jsonObj != null) { JSONArray jsonBookings = jsonObj.getJSONArray("resultrooms"); for (int i = 0; i < jsonBookings.length(); i++) { JSONObject catObj = (JSONObject) jsonBookings.get(i); emptyRoom = (catObj.getString("booked_room")); resultList.add(emptyRoom); } } Assert.assertEquals(resultList.size(), 0); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } }