You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
misp/mispmock/src/actor/UserMock.java

73 lines
1.8 KiB

package actor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import core.*;
import exchange.ExchangeMock;
public class UserMock extends ActorRunnable {
int requestCount = 0;
public UserMock(MockSet mockSet){
super(mockSet);
mockSet.userMock = this;
}
@Override
public void run() {
while (true){
try {
Thread.sleep(Main.REQUEST_SPEED);
sendGetRequest();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
}
/**
* # send GET (Request)
* Generated by Loop
*/
void sendGetRequest() throws IOException, InterruptedException {
// Mock Exchange
ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("GET");
exchange.request.setContentType("application/json");
String requestBody = "REQUEST-"+(++requestCount);
String jsonString = "{\"request\":\""+requestBody+ "\"}";
exchange.request.setContent(jsonString.getBytes());
synchronized (exchange){
// Mock GET (Request)
exchange.notify();
mockSet.bridgeMock.doGet(exchange.request,exchange.response);
exchange.wait();
// handle OK (Data)
String data = exchange.response.getContentAsString();
System.out.println(data + " of REQUEST-"+requestCount);
exchange.notify();
}
}
}