From 3eb8903197f4f2ff6fec9552d449f4b0b9ec38a4 Mon Sep 17 00:00:00 2001 From: bspeice Date: Fri, 18 Oct 2013 21:57:10 -0400 Subject: [PATCH] Tests for the RegistrationClient are now up to date. --- .../test/RegistrationClientTest.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/com/uncc/gameday/registration/test/RegistrationClientTest.java b/src/com/uncc/gameday/registration/test/RegistrationClientTest.java index 247f927..99479c5 100644 --- a/src/com/uncc/gameday/registration/test/RegistrationClientTest.java +++ b/src/com/uncc/gameday/registration/test/RegistrationClientTest.java @@ -4,14 +4,16 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; +import android.test.AndroidTestCase; +import android.util.Log; + import com.uncc.gameday.R; import com.uncc.gameday.registration.ParkingChoices; import com.uncc.gameday.registration.ParkingLot; +import com.uncc.gameday.registration.ParkingRating; +import com.uncc.gameday.registration.RatingChoices; import com.uncc.gameday.registration.RegistrationClient; -import android.net.http.AndroidHttpClient; -import android.test.AndroidTestCase; - /* Tests the REST functionality */ public class RegistrationClientTest extends AndroidTestCase { @@ -30,7 +32,7 @@ public class RegistrationClientTest extends AndroidTestCase { */ HttpURLConnection connection = (HttpURLConnection) new URL("http", mContext.getString(R.string.server_hostname), "") .openConnection(); - if (connection.getResponseCode() != connection.HTTP_OK) + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) fail("Could not connect to GameDay! Response code: " + connection.getResponseCode()); } @@ -45,5 +47,30 @@ public class RegistrationClientTest extends AndroidTestCase { ParkingLot lot = rc.listLot(ParkingChoices.BLUE); assertTrue(lot.getLocation().getValue() == ParkingChoices.BLUE.getValue()); } + + public void testRateLot() throws InterruptedException { + RegistrationClient rc = new RegistrationClient(this.mContext); + ParkingChoices choice = ParkingChoices.BLUE; + + // To test and make sure this works: + // Rate a lot empty 10 times to flush out any other ratings, + // then rate it full 15 times. Check to make sure the value is correct. + // Technically, should only need 10 POSTs, but been having some strange + // issues where they don't seem to all make it to the server. + // Sometimes the test will pass, sometimes it won't... + for (int i = 0; i < 10; i++) { + rc.rateLot(RatingChoices.EMP, choice); + } + + ParkingRating rating = new ParkingRating(); + rating.setParkingLot(choice); + rating.setRating(RatingChoices.FLL); + for (int i = 0; i < 15; i++) { + rc.rateLot(rating); + } + + ParkingLot lot = rc.listLot(choice); + assertEquals(100, lot.getFilledPct()); // FULL -> 100% + } }