<commit_before>package controllers;

import java.util.List;

import models.Bed;
import models.Booking;
import models.Cabin;
import models.LargeCabin;
import models.RDate;
import models.SmallCabin;
import models.User;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.junit.*;

import com.fasterxml.jackson.databind.JsonNode;

import JSONFormatters.JsonHelper;
import flexjson.JSONSerializer;
import static org.junit.Assert.*;
import play.mvc.Result;
import play.test.FakeRequest;
import play.test.WithApplication;
import static play.test.Helpers.*;

public class BookingControllerTest extends WithApplication {

	SmallCabin sCabin;
	LargeCabin lCabin;
	User userOk;
	User userBad;
	final static String authToken = "<PASSWORD>";

	@SuppressWarnings("deprecation")
	@Before
	public void setUp() {
		start(fakeApplication(inMemoryDatabase()));
		sCabin = new SmallCabin("AvailabilityTestSmallCabin");

		lCabin = new LargeCabin("AvailabilityTestLargeCabin", 8);
		userOk = new User("q@t","w", "t");
		userBad = new User("<EMAIL>", "w", "t");

		sCabin.save();
		lCabin.save();
		userOk.save();
		
		Booking b1 = Booking.createBooking(userOk.id, RDate.fDt, RDate.fDt.plusDays(3), lCabin.id, lCabin.beds);
		b1.save();
	}

	@Test
	/**
	 * Test that empty request returns null result
	 * Test that booking with only minors/babies returns badRequest
	 * Test that termsAndConditions false returns badRequest
	 * http://www.playframework.com/documentation/2.1.x/api/java/play/test/FakeRequest.html
	 */
	public void testSubmitBooking() {

		//Normal booking, OK
		FakeRequest fkRequest = new FakeRequest(POST, "/api/bookings/");
		fkRequest.withHeader(authToken, userOk.createToken());
		JsonNode node = JsonHelper.getOkBooking();
		fkRequest.withJsonBody(node);
		System.out.println("DEBUGGIN: \n");
		System.out.println(node);
		System.out.println("#############");
		
		Result resOk = route(fkRequest);
		System.out.println("########### RESULT SUBMITBOOKING OK IS\n"+contentAsString(resOk));
		assertEquals("SHOULD BE OK", OK, status(resOk));
		//TODO this says guestList invalid, where does that error come from?
		//Can't be because JSON isn't read right, because I had to fix dates being wrong, so it can read
		//the first part, it just doesn't like the guests part?
		
		//Only babies booking
		fkRequest = new FakeRequest(POST, "/api/bookings/");
		fkRequest.withHeader(authToken, userOk.createToken());
		fkRequest.withJsonBody(JsonHelper.getOnlyMemberBabiesBookingJSON());
		
		Result resBad = route(fkRequest);
		System.out.println("########### RESULT SUBMITBOOKING BAD IS\n"+contentAsString(resBad));
		assertEquals("SHOULD BE BAD", BAD_REQUEST, status(resBad));
	}

	@Test
	public void testCancelBooking()  {
		//cancel booking as other user
		FakeRequest fkRequest = new FakeRequest(DELETE, "/api/bookings/1");
		fkRequest.withHeader(authToken, userBad.createToken());
		
		Result resBad = route(fkRequest);
		assertEquals(BAD_REQUEST, status(resBad));
		System.out.println("########### RESULT FAKEREQUEST BAD DELETE IS\n"+status(resBad));

		//cancel booking as actual owner of booking
		fkRequest = new FakeRequest(DELETE, "/api/bookings/1"); //Add id here?
		fkRequest.withHeader(authToken, userOk.createToken());
		
		Result resOk = route(fkRequest);
		assertEquals(OK, status(resOk));
		System.out.println("########### RESULT FAKEREQUEST OK DELETE IS\n"+status(resOk));
		
	}

	@Test
	/** Note: Doesn't test the actual controller, just copied the entire code and testing within here TODO **/
	public void TestGetAvailabilityForTimePeriodSmallCabin() {
		//make smallCabin with zero bookings

		/** add different bookings and test **/
		DateTime s1 = new DateTime("2015-03-01");
		DateTime e1 = new DateTime("2015-03-03");
<commit_msg>Small todo in test<commit_after>package controllers;

import java.util.List;

import models.Bed;
import models.Booking;
import models.Cabin;
import models.LargeCabin;
import models.RDate;
import models.SmallCabin;
import models.User;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.junit.*;

import com.fasterxml.jackson.databind.JsonNode;

import JSONFormatters.JsonHelper;
import flexjson.JSONSerializer;
import static org.junit.Assert.*;
import play.mvc.Result;
import play.test.FakeRequest;
import play.test.WithApplication;
import static play.test.Helpers.*;

public class BookingControllerTest extends WithApplication {

	SmallCabin sCabin;
	LargeCabin lCabin;
	User userOk;
	User userBad;
	final static String authToken = "X-AUTH-TOKEN";

	@SuppressWarnings("deprecation")
	@Before
	public void setUp() {
		start(fakeApplication(inMemoryDatabase()));
		sCabin = new SmallCabin("AvailabilityTestSmallCabin");

		lCabin = new LargeCabin("AvailabilityTestLargeCabin", 8);
		userOk = new User("q@t","w", "t");
		userBad = new User("<EMAIL>", "w", "t");

		sCabin.save();
		lCabin.save();
		userOk.save();
		
		Booking b1 = Booking.createBooking(userOk.id, RDate.fDt, RDate.fDt.plusDays(3), lCabin.id, lCabin.beds);
		b1.save();
	}

	@Test
	/**
	 * Test that empty request returns null result
	 * Test that booking with only minors/babies returns badRequest
	 * Test that termsAndConditions false returns badRequest
	 * http://www.playframework.com/documentation/2.1.x/api/java/play/test/FakeRequest.html
	 */
	public void testSubmitBooking() {

		//Normal booking, OK
		FakeRequest fkRequest = new FakeRequest(POST, "/api/bookings/");
		fkRequest.withHeader(authToken, userOk.createToken());
		JsonNode node = JsonHelper.getOkBooking();
		fkRequest.withJsonBody(node);
		System.out.println("DEBUGGIN: \n");
		System.out.println(node);
		System.out.println("#############");
		
		Result resOk = route(fkRequest);
		System.out.println("########### RESULT SUBMITBOOKING OK IS\n"+contentAsString(resOk));
		assertEquals("SHOULD BE OK", OK, status(resOk));
		//TODO this says guestList invalid, where does that error come from?
		//Can't be because JSON isn't read right, because I had to fix dates being wrong, so it can read
		//the first part, it just doesn't like the guests part?
		
		//Only babies booking
		fkRequest = new FakeRequest(POST, "/api/bookings/");
		fkRequest.withHeader(authToken, userOk.createToken());
		fkRequest.withJsonBody(JsonHelper.getOnlyMemberBabiesBookingJSON());
		
		Result resBad = route(fkRequest);
		System.out.println("########### RESULT SUBMITBOOKING BAD IS\n"+contentAsString(resBad));
		assertEquals("SHOULD BE BAD", BAD_REQUEST, status(resBad));
	}

	@Test
	public void testCancelBooking()  {
		//cancel booking as other user
		FakeRequest fkRequest = new FakeRequest(DELETE, "/api/bookings/1");
		fkRequest.withHeader(authToken, userBad.createToken());
		
		Result resBad = route(fkRequest);
		assertEquals(BAD_REQUEST, status(resBad));
		System.out.println("########### RESULT FAKEREQUEST BAD DELETE IS\n"+status(resBad));

		//cancel booking as actual owner of booking
		fkRequest = new FakeRequest(DELETE, "/api/bookings/1"); //Add id here?
		fkRequest.withHeader(authToken, userOk.createToken());
		
		Result resOk = route(fkRequest);
		assertEquals(OK, status(resOk));
		System.out.println("########### RESULT FAKEREQUEST OK DELETE IS\n"+status(resOk));
		
	}
	
	@Test
	/**
	 * 
	 */
	public void testGetOrderSummary() {
		
	}

	@Test
	/** Note: Doesn't test the actual controller, just copied the entire code and testing within here TODO **/
	public void TestGetAvailabilityForTimePeriodSmallCabin() {
		//make smallCabin with zero bookings

		/** add different bookings and test **/
		DateTime s1 = new DateTime("2015-03-01");
		DateTime e1 = new DateTime("2015-03-03");

{'fraction_non_alphanumeric': 0.13739153300026294, 'fraction_numerical': 0.0068367078622140415, 'mean_word_length': 4.865073245952197, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310281', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2408, 'n_words': 617}