Search in sources :

Example 1 with Request

use of com.github.tomakehurst.wiremock.http.Request in project opennms by OpenNMS.

the class AbstractMeasurementQueryExecutorTest method verifyHttpCalls.

protected void verifyHttpCalls(int number) {
    // ensure a request was actually made and was only made <number> times
    WireMock.verify(number, WireMock.postRequestedFor(WireMock.urlMatching("/opennms/rest/measurements")).withoutHeader("Authorization").withHeader("Content-Type", WireMock.equalTo("application/xml")));
    // VERIFY that the Request Body is a valid QueryRequest
    Assert.assertEquals(number, requestList.size());
    for (Request eachRequest : requestList) {
        QueryRequest queryRequest = JAXB.unmarshal(new ByteArrayInputStream(eachRequest.getBody()), QueryRequest.class);
        try {
            new QueryRequestValidator().validate(queryRequest);
        } catch (ValidationException e) {
            Throwables.propagate(e);
        }
    }
}
Also used : ValidationException(org.opennms.netmgt.measurements.api.exceptions.ValidationException) QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) QueryRequestValidator(org.opennms.netmgt.measurements.api.QueryRequestValidator) QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Request(com.github.tomakehurst.wiremock.http.Request) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest)

Example 2 with Request

use of com.github.tomakehurst.wiremock.http.Request in project opennms by OpenNMS.

the class AbstractMeasurementQueryExecutorTest method before.

@Before
public void before() throws IOException {
    requestList.clear();
    // we listen to all requests and verify that the POST data can be parsed as a Query Request
    wireMockRule.addMockServiceRequestListener(new RequestListener() {

        @Override
        public void requestReceived(Request request, Response response) {
            requestList.add(LoggedRequest.createFrom(request));
        }
    });
    new File("target/reports").mkdirs();
}
Also used : Response(com.github.tomakehurst.wiremock.http.Response) RequestListener(com.github.tomakehurst.wiremock.http.RequestListener) QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Request(com.github.tomakehurst.wiremock.http.Request) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) File(java.io.File) Before(org.junit.Before)

Aggregations

Request (com.github.tomakehurst.wiremock.http.Request)2 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)2 QueryRequest (org.opennms.netmgt.measurements.model.QueryRequest)2 RequestListener (com.github.tomakehurst.wiremock.http.RequestListener)1 Response (com.github.tomakehurst.wiremock.http.Response)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Before (org.junit.Before)1 QueryRequestValidator (org.opennms.netmgt.measurements.api.QueryRequestValidator)1 ValidationException (org.opennms.netmgt.measurements.api.exceptions.ValidationException)1