|
|
@ -1,6 +1,7 @@
|
|
|
|
package core;
|
|
|
|
package core;
|
|
|
|
|
|
|
|
|
|
|
|
import exchange.ExchangeMock;
|
|
|
|
import exchange.ExchangeMock;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
@ -55,31 +56,27 @@ public class ClientMock extends ClientServlet {
|
|
|
|
* # send GET (Request) to App
|
|
|
|
* # send GET (Request) to App
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
void sendGetRequest(Ride ride) throws IOException {
|
|
|
|
void sendGetRequest(Ride ride) throws IOException, ServletException, InterruptedException {
|
|
|
|
|
|
|
|
|
|
|
|
HttpURLConnection connection = ConnectionHelper.make("GET", ClientServlet.APP_URL);
|
|
|
|
// Mock Exchange
|
|
|
|
|
|
|
|
ExchangeMock exchange = new ExchangeMock();
|
|
|
|
|
|
|
|
|
|
|
|
// send GET (Request)
|
|
|
|
exchange.request.setMethod("GET");
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
exchange.request.setContentType("application/json");
|
|
|
|
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
|
|
|
exchange.request.setContent(ride.json().getBytes());
|
|
|
|
outputStream.writeBytes(ride.getRequest());
|
|
|
|
|
|
|
|
outputStream.flush();
|
|
|
|
synchronized (exchange){
|
|
|
|
outputStream.close();
|
|
|
|
// Mock GET (Request)
|
|
|
|
|
|
|
|
exchange.notify();
|
|
|
|
|
|
|
|
mockSet.appMock.doGet(exchange.request,exchange.response);
|
|
|
|
|
|
|
|
exchange.wait();
|
|
|
|
|
|
|
|
|
|
|
|
// handle OK (Data)
|
|
|
|
// handle OK (Data)
|
|
|
|
// remove Ride from BookedRides
|
|
|
|
Ride parsedRide = new Ride(exchange.response.getContentAsString());
|
|
|
|
// add Ride to LoadedRides
|
|
|
|
ride.setData(parsedRide.getData());
|
|
|
|
// send GET (Ride)(Data)
|
|
|
|
|
|
|
|
if (connection.getResponseCode() == 200) {
|
|
|
|
|
|
|
|
String parsedData = ConnectionHelper.parseString(connection);
|
|
|
|
|
|
|
|
ride.setData(parsedData);
|
|
|
|
|
|
|
|
ride.setState(State.LOADED);
|
|
|
|
ride.setState(State.LOADED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendGetRideRequestData(ride);
|
|
|
|
sendGetRideRequestData(ride);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -88,24 +85,24 @@ public class ClientMock extends ClientServlet {
|
|
|
|
* # send GET (Ride)(Request)(Data)
|
|
|
|
* # send GET (Ride)(Request)(Data)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
void sendGetRideRequestData(Ride ride) throws IOException {
|
|
|
|
void sendGetRideRequestData(Ride ride) throws IOException, ServletException, InterruptedException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mock Exchange
|
|
|
|
|
|
|
|
ExchangeMock exchange = new ExchangeMock();
|
|
|
|
|
|
|
|
|
|
|
|
HttpURLConnection connection = ConnectionHelper.make("GET", ClientServlet.MISP_BRIDGE_URL);
|
|
|
|
exchange.request.setMethod("GET");
|
|
|
|
|
|
|
|
exchange.request.setContentType("application/json");
|
|
|
|
|
|
|
|
exchange.request.setContent(ride.json().getBytes());
|
|
|
|
|
|
|
|
|
|
|
|
// send GET (Ride)(Request)(Data)
|
|
|
|
synchronized (exchange){
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
// Mock GET (Ride)(Request)(Data)
|
|
|
|
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
|
|
|
exchange.notify();
|
|
|
|
outputStream.writeBytes(ride.json());
|
|
|
|
mockSet.bridgeMock.doGet(exchange.request,exchange.response);
|
|
|
|
outputStream.flush();
|
|
|
|
exchange.wait();
|
|
|
|
outputStream.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// handle OK (Ride)
|
|
|
|
// handle OK (Ride)
|
|
|
|
// remove Ride from LoadedRides
|
|
|
|
Ride parsedRide = new Ride(exchange.response.getContentAsString());
|
|
|
|
if (connection.getResponseCode() == 200) {
|
|
|
|
rideMap.remove(parsedRide.getID());
|
|
|
|
Ride shellIdRide = ConnectionHelper.parseRide(connection);
|
|
|
|
|
|
|
|
if (shellIdRide.getID() != null) {
|
|
|
|
|
|
|
|
rideMap.remove(ride.getID());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|