// Path: src/test/java/com/scorpiac/javarant/services/MockRequestHandler.java
// public class MockRequestHandler extends RequestHandler {
//     private final URI local;
// 
//     public MockRequestHandler(int port) {
//         super(new ObjectMapperResponseHandlerFactory(new ObjectMapperService()));
//         local = URI.create("http://localhost:" + port);
//     }
// 
//     @Override
//     URI resolve(String endpoint) {
//         return local.resolve(endpoint);
//     }
// }


import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.MappingBuilder;
import com.scorpiac.javarant.services.MockRequestHandler;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import java.io.IOException;
import java.util.Scanner;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
                        .dynamicPort()
        );
        server.start();

        devRant = new DevRant();
        devRant.setRequestHandler(new MockRequestHandler(server.port()));
    }

    @AfterClass
    public void stopServer() {
        server.stop();
    }

    @AfterMethod
    public void resetServer() {
        server.resetAll();
    }

    protected MappingBuilder stubGet(MappingBuilder stub, String resource) throws IOException {
        return stubPost(stub, resource)
                .withQueryParam("app", equalTo("3"))
                .withQueryParam("plat", equalTo("3"));
    }

    protected MappingBuilder stubPost(MappingBuilder stub, String resource) throws IOException {
        String responseString;
        try (Scanner scanner = new Scanner(getClass().getResourceAsStream(resource))) {
            responseString = scanner.useDelimiter("\\A").next();
        }

// Path: src/test/java/com/scorpiac/javarant/services/MockRequestHandler.java
// public class MockRequestHandler extends RequestHandler {
//     private final URI local;
// 
//     public MockRequestHandler(int port) {
//         super(new ObjectMapperResponseHandlerFactory(new ObjectMapperService()));
//         local = URI.create("http://localhost:" + port);
//     }
// 
//     @Override
//     URI resolve(String endpoint) {
//         return local.resolve(endpoint);
//     }
// }


// Path: src/test/java/com/scorpiac/javarant/ITHelper.java
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.MappingBuilder;
import com.scorpiac.javarant.services.MockRequestHandler;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import java.io.IOException;
import java.util.Scanner;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

                        .dynamicPort()
        );
        server.start();

        devRant = new DevRant();
        devRant.setRequestHandler(new MockRequestHandler(server.port()));
    }

    @AfterClass
    public void stopServer() {
        server.stop();
    }

    @AfterMethod
    public void resetServer() {
        server.resetAll();
    }

    protected MappingBuilder stubGet(MappingBuilder stub, String resource) throws IOException {
        return stubPost(stub, resource)
                .withQueryParam("app", equalTo("3"))
                .withQueryParam("plat", equalTo("3"));
    }

    protected MappingBuilder stubPost(MappingBuilder stub, String resource) throws IOException {
        String responseString;
        try (Scanner scanner = new Scanner(getClass().getResourceAsStream(resource))) {
            responseString = scanner.useDelimiter("\\A").next();
        }

        return stub.willReturn(aResponse().withBody(responseString));