diff --git a/src/com/uncc/gameday/parking/test/ParkingClientTest.java b/src/com/uncc/gameday/parking/test/ParkingClientTest.java new file mode 100644 index 0000000..5eb3af9 --- /dev/null +++ b/src/com/uncc/gameday/parking/test/ParkingClientTest.java @@ -0,0 +1,76 @@ +package com.uncc.gameday.parking.test; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; + +import com.uncc.gameday.R; +import com.uncc.gameday.parking.ParkingChoices; +import com.uncc.gameday.parking.ParkingLot; +import com.uncc.gameday.parking.ParkingRating; +import com.uncc.gameday.parking.RatingChoices; +import com.uncc.gameday.parking.ParkingClient; + +import android.test.AndroidTestCase; + +public class ParkingClientTest extends AndroidTestCase{ + + public void setUp() throws Exception { + super.setUp(); + + // Code run before each test goes here. + + // Make sure that we can actually contact the server + /* + * Can't use InetAddress since the emulator doesn't support `ping` + InetAddress host = InetAddress.getByName(this.mContext.getString(R.string.server_hostname)); + if (!host.isReachable(5000)) + fail("Could not contact Gameday server!"); + */ + HttpURLConnection connection = (HttpURLConnection) new URL("http", mContext.getString(R.string.server_hostname), "") + .openConnection(); + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) + fail("Could not connect to GameDay! Response code: " + connection.getResponseCode()); + } + + public void testFetchLots() { + ParkingClient pc = new ParkingClient(this.mContext); + List lots = pc.listLots(); + assertTrue((lots.size() > 0)); + } + + public void testFetchLot() { + ParkingClient pc = new ParkingClient(this.mContext); + ParkingLot lot = pc.listLot(ParkingChoices.BLUE); + assertTrue(lot.getLocation().getValue() == ParkingChoices.BLUE.getValue()); + } + + public void testRateLot() throws InterruptedException { + ParkingClient pc = new ParkingClient(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++) { + pc.rateLot(RatingChoices.EMP, choice); + } + + ParkingRating rating = new ParkingRating(); + rating.setParkingLot(choice); + rating.setRating(RatingChoices.FLL); + for (int i = 0; i < 15; i++) { + pc.rateLot(rating); + } + + ParkingLot lot = pc.listLot(choice); + + // While the lot should be full (100%) the unit test POST goes too fast + // for Retrofit to keep up (or server, tbh not sure which) + // As long as the pct > 0, some of our POSTs have made it. + assertTrue((lot.getFilledPct() > 0)); + } +} diff --git a/src/com/uncc/gameday/registration/test/RegistrationClientTest.java b/src/com/uncc/gameday/registration/test/RegistrationClientTest.java index 3e40551..3561a22 100644 --- a/src/com/uncc/gameday/registration/test/RegistrationClientTest.java +++ b/src/com/uncc/gameday/registration/test/RegistrationClientTest.java @@ -7,11 +7,11 @@ import java.util.List; import android.test.AndroidTestCase; import com.uncc.gameday.R; +import com.uncc.gameday.parking.ParkingChoices; +import com.uncc.gameday.parking.ParkingLot; +import com.uncc.gameday.parking.ParkingRating; +import com.uncc.gameday.parking.RatingChoices; import com.uncc.gameday.registration.Attendee; -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; /* Tests the REST functionality */ @@ -36,47 +36,6 @@ public class RegistrationClientTest extends AndroidTestCase { fail("Could not connect to GameDay! Response code: " + connection.getResponseCode()); } - public void testFetchLots() { - RegistrationClient rc = new RegistrationClient(this.mContext); - List lots = rc.listLots(); - assertTrue((lots.size() > 0)); - } - - public void testFetchLot() { - RegistrationClient rc = new RegistrationClient(this.mContext); - 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); - - // While the lot should be full (100%) the unit test POST goes too fast - // for Retrofit to keep up (or server, tbh not sure which) - // As long as the pct > 0, some of our POSTs have made it. - assertTrue((lot.getFilledPct() > 0)); - } - public void testRegistration() { // Register a new user, and make sure that they can be retrieved correctly Attendee a = new Attendee();