Search in sources :

Example 1 with MockServerClient

use of org.mockserver.client.MockServerClient in project apm-agent-java by elastic.

the class MockServerContainer method containerIsStarted.

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
    super.containerIsStarted(containerInfo);
    client = new MockServerClient(getContainerIpAddress(), getFirstMappedPort());
}
Also used : MockServerClient(org.mockserver.client.MockServerClient)

Example 2 with MockServerClient

use of org.mockserver.client.MockServerClient in project policies-ui-backend by RedHatInsights.

the class TestLifecycleManager method setupMockEngine.

void setupMockEngine(Map<String, String> props) {
    mockEngineServer = new MockServerContainer();
    // set up mock engine
    mockEngineServer.start();
    String mockServerUrl = "http://" + mockEngineServer.getContainerIpAddress() + ":" + mockEngineServer.getServerPort();
    mockServerClient = new MockServerClient(mockEngineServer.getContainerIpAddress(), mockEngineServer.getServerPort());
    mockRbac();
    mockEngine();
    props.put("quarkus.rest-client.engine.url", mockServerUrl);
    props.put("quarkus.rest-client.rbac.url", mockServerUrl);
    props.put("quarkus.rest-client.notifications.url", mockServerUrl);
}
Also used : MockServerClient(org.mockserver.client.MockServerClient) MockServerContainer(org.testcontainers.containers.MockServerContainer)

Example 3 with MockServerClient

use of org.mockserver.client.MockServerClient in project Insights by CognizantOneDevOps.

the class MockServerImpl method startMockServerWithExpectations.

/**
 * This function will read all json files from getAllMockRequestsFromJson method
 * and create expectations from the given Paths and Response in the individual
 * tool's json.
 */
public void startMockServerWithExpectations() {
    // Starting mock server on port 1080.
    MockServerClient mockServer = startClientAndServer(1080);
    // Reading mock requests from multiple JSON files.
    List<MockRequest> mockRequests = getAllMockRequestsFromJson();
    String response = null;
    Iterator<MockRequest> mockIterator = mockRequests.iterator();
    while (mockIterator.hasNext()) {
        MockRequest request = mockIterator.next();
        List<Parameter> parameterList = new ArrayList<>();
        if (request.isResponseJson()) {
            response = request.getResponse().get(0).toString();
        } else {
            response = request.getResponse().toString();
        }
        // checking if the request has any parameters.
        if (request.getParameters() != null) {
            for (Map.Entry<String, String> paramEntry : request.getParameters().entrySet()) {
                Parameter param = new Parameter(paramEntry.getKey(), paramEntry.getValue());
                parameterList.add(param);
            }
        }
        // Creating mock Expectation
        mockServer.when(request().withPath(request.getPath()).withQueryStringParameters(parameterList)).respond(response().withStatusCode(200).withBody(response));
        log.debug("Expectation created for the path {} with query string parmeters {}", request.getPath(), parameterList);
    }
    log.info("Mock Server Started");
}
Also used : ArrayList(java.util.ArrayList) Parameter(org.mockserver.model.Parameter) MockServerClient(org.mockserver.client.MockServerClient) Map(java.util.Map)

Example 4 with MockServerClient

use of org.mockserver.client.MockServerClient in project dependency-track by DependencyTrack.

the class CsWebexPublisherTest method testPublish.

@Test
public void testPublish() {
    new MockServerClient("localhost", 1080).when(request().withMethod("POST").withPath("/mychannel")).respond(response().withStatusCode(200).withHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
    JsonObject config = Json.createObjectBuilder().add("destination", "http://localhost:1080/mychannel").build();
    Notification notification = new Notification();
    notification.setScope(NotificationScope.PORTFOLIO.name());
    notification.setGroup(NotificationGroup.NEW_VULNERABILITY.name());
    notification.setLevel(NotificationLevel.INFORMATIONAL);
    notification.setTitle("Test Notification");
    notification.setContent("This is only a test");
    CsWebexPublisher publisher = new CsWebexPublisher();
    publisher.inform(notification, config);
}
Also used : JsonObject(javax.json.JsonObject) MockServerClient(org.mockserver.client.MockServerClient) Notification(alpine.notification.Notification) PersistenceCapableTest(org.dependencytrack.PersistenceCapableTest) Test(org.junit.Test)

Example 5 with MockServerClient

use of org.mockserver.client.MockServerClient in project dependency-track by DependencyTrack.

the class WebhookPublisherTest method testPublish.

@Test
public void testPublish() {
    new MockServerClient("localhost", 1080).when(request().withMethod("POST").withPath("/mychannel")).respond(response().withStatusCode(200).withHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
    JsonObject config = Json.createObjectBuilder().add("destination", "http://localhost:1080/mychannel").build();
    Notification notification = new Notification();
    notification.setScope(NotificationScope.PORTFOLIO.name());
    notification.setGroup(NotificationGroup.NEW_VULNERABILITY.name());
    notification.setLevel(NotificationLevel.INFORMATIONAL);
    notification.setTitle("Test Notification");
    notification.setContent("This is only a test");
    WebhookPublisher publisher = new WebhookPublisher();
    publisher.inform(notification, config);
}
Also used : JsonObject(javax.json.JsonObject) MockServerClient(org.mockserver.client.MockServerClient) Notification(alpine.notification.Notification) PersistenceCapableTest(org.dependencytrack.PersistenceCapableTest) Test(org.junit.Test)

Aggregations

MockServerClient (org.mockserver.client.MockServerClient)108 Test (org.junit.Test)37 MockServer (org.mockserver.netty.MockServer)30 BeforeClass (org.junit.BeforeClass)29 Before (org.junit.Before)15 File (java.io.File)11 EchoServer (org.mockserver.echo.http.EchoServer)10 Expectation (org.mockserver.mock.Expectation)9 MockServerLogger (org.mockserver.logging.MockServerLogger)8 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 ClientAndServer (org.mockserver.integration.ClientAndServer)5 HttpResponse (org.mockserver.model.HttpResponse)5 Notification (alpine.notification.Notification)4 StreamBuildListener (hudson.model.StreamBuildListener)4 Description (io.qameta.allure.Description)4 URL (java.net.URL)4 JsonObject (javax.json.JsonObject)4 Context (org.apache.catalina.Context)4 Service (org.apache.catalina.Service)4