parent
9ebe5575fa
commit
2f6e088480
@ -1,4 +1,4 @@
|
||||
package com.olexyn.mispl.adapter;
|
||||
package com.olexyn.misp.adapter;
|
||||
|
||||
public class Main {
|
||||
|
@ -1,100 +0,0 @@
|
||||
package com.olexyn.misp.mock;
|
||||
|
||||
import com.olexyn.misp.client.ClientServlet;
|
||||
import com.olexyn.misp.helper.Ride;
|
||||
import com.olexyn.misp.mock.exchange.ExchangeMock;
|
||||
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps a ClientServlet so it can be debugged easily, i.e. without running Tomcat.
|
||||
*/
|
||||
public class ClientMock extends ClientServlet {
|
||||
|
||||
private MockSet mockSet;
|
||||
|
||||
|
||||
public ClientMock(MockSet mockSet) {
|
||||
super();
|
||||
mockSet.clientMock = this;
|
||||
this.mockSet = mockSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send POST (Ride).
|
||||
* Parse response.
|
||||
*/
|
||||
@Override
|
||||
protected Ride doSendPostRide(Ride ride) throws IOException, ServletException, InterruptedException {
|
||||
|
||||
// Mock Exchange
|
||||
final ExchangeMock exchange = new ExchangeMock();
|
||||
exchange.request.setMethod("POST");
|
||||
exchange.request.setContentType("application/json");
|
||||
exchange.request.setContent(ride.json().getBytes());
|
||||
|
||||
synchronized (exchange) {
|
||||
// Mock POST (Ride)
|
||||
exchange.notify();
|
||||
mockSet.bridgeMock.doPost(exchange.request, exchange.response);
|
||||
exchange.wait();
|
||||
exchange.notify();
|
||||
}
|
||||
|
||||
// handle OK (Ride)(Request)
|
||||
return new Ride(exchange.response.getContentAsString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send GET (Request) to App.
|
||||
* Parse response.
|
||||
*/
|
||||
@Override
|
||||
protected String doSendGetRequest(String request) throws IOException, InterruptedException {
|
||||
|
||||
// Mock Exchange
|
||||
final ExchangeMock exchange = new ExchangeMock();
|
||||
|
||||
exchange.request.setMethod("GET");
|
||||
exchange.request.setContent(request.getBytes());
|
||||
|
||||
synchronized (exchange) {
|
||||
// Mock GET (Request)
|
||||
exchange.notify();
|
||||
mockSet.appMock.doGet(exchange.request, exchange.response);
|
||||
|
||||
// handle OK (Data)
|
||||
exchange.notify();
|
||||
}
|
||||
|
||||
return exchange.response.getContentAsString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send GET (Ride)(Request)(Data).
|
||||
* Parse response.
|
||||
*/
|
||||
@Override
|
||||
protected void doSendGetRideRequest(Ride ride) throws IOException, InterruptedException {
|
||||
|
||||
// Mock Exchange
|
||||
final ExchangeMock exchange = new ExchangeMock();
|
||||
exchange.request.setMethod("GET");
|
||||
exchange.request.setContentType("application/json");
|
||||
exchange.request.setContent(ride.json().getBytes());
|
||||
|
||||
synchronized (exchange) {
|
||||
// Mock GET (Ride)(Request)(Data)
|
||||
exchange.notify();
|
||||
mockSet.bridgeMock.doGet(exchange.request, exchange.response);
|
||||
exchange.wait();
|
||||
exchange.notify();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.olexyn.misp.mock;
|
||||
|
||||
/**
|
||||
* Pass the MockSet.
|
||||
* Provide a Runnable.
|
||||
*/
|
||||
public class ClientRunnable implements Runnable {
|
||||
|
||||
private MockSet mockSet;
|
||||
|
||||
public ClientRunnable(MockSet mockSet){
|
||||
super();
|
||||
this.mockSet = mockSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new ClientMock(mockSet);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue