Examples of JsonBodyCapture


Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

    }
   
    @Test
    public void canCaptureRequestBodyAsJson() throws Exception {
       
        JsonBodyCapture capture = new JsonBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/foo").withMethod(Method.POST).capturingBodyIn(capture),
                giveEmptyResponse().withStatus(201));
       
        HttpClient client = new DefaultHttpClient();
        HttpPost correctPost = new HttpPost(clientDriver.getBaseUrl() + "/foo");
        correctPost.setEntity(new StringEntity("{\"a\": \"A\"}"));
        HttpResponse correctResponse = client.execute(correctPost);
        EntityUtils.consume(correctResponse.getEntity());
       
        assertThat(capture.getContent(), hasJsonPath("$.a", equalTo("A")));
    }
View Full Code Here

Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

                .withFromType(AlertType.WARN)
                .withToType(AlertType.ERROR);
       
        List<Alert> alerts = Arrays.asList(alert);
       
        BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/hubot/seyren/alert")
                        .withMethod(Method.POST)
                        .capturingBodyIn(bodyCapture),
                giveResponse("Thanks for letting me know", "text/plain"));
       
        service.sendNotification(check, subscription, alerts);
       
        JsonNode node = bodyCapture.getContent();
       
        assertThat(node, hasJsonPath("$.seyrenUrl", is(seyrenUrl)));
        assertThat(node, hasJsonPath("$.check.name", is("check-name")));
        assertThat(node, hasJsonPath("$.check.state", is("ERROR")));
        assertThat(node, hasJsonPath("$.alerts", hasSize(1)));
View Full Code Here

Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

                .withTimestamp(new DateTime())
                .withFromType(AlertType.OK)
                .withToType(AlertType.ERROR);
        List<Alert> alerts = Arrays.asList(alert);

        BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();

        clientDriver.addExpectation(
                onRequestTo("/generic/2010-04-15/create_event.json")
                        .withMethod(ClientDriverRequest.Method.POST)
                        .capturingBodyIn(bodyCapture)
                        .withHeader("content-Type", "application/json"),
                giveEmptyResponse());

        notificationService.sendNotification(check, subscription, alerts);

        JsonNode node = bodyCapture.getContent();

        assertThat(node, hasJsonPath("$.service_key", is("servicekey123")));
        assertThat(node, hasJsonPath("$.incident_key", is("MonitoringAlerts_123")));
        assertThat(node, hasJsonPath("$.event_type", is("trigger")));
        assertThat(node, hasJsonPath("$.description", is("Check 'test-check' has exceeded its threshold.")));
View Full Code Here

Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

                .withEnabled(true)
                .withType(SubscriptionType.PAGERDUTY)
                .withTarget("servicekey123");
        List<Alert> alerts = new ArrayList<Alert>();

        BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();

        clientDriver.addExpectation(
                onRequestTo("/generic/2010-04-15/create_event.json")
                        .withMethod(ClientDriverRequest.Method.POST)
                        .capturingBodyIn(bodyCapture)
                        .withHeader("content-Type", "application/json"),
                giveEmptyResponse());

        notificationService.sendNotification(check, subscription, alerts);

        JsonNode node = bodyCapture.getContent();

        assertThat(node, hasJsonPath("$.service_key", is("servicekey123")));
        assertThat(node, hasJsonPath("$.incident_key", is("MonitoringAlerts_123")));
        assertThat(node, hasJsonPath("$.event_type", is("resolve")));
        assertThat(node, hasJsonPath("$.description", is("Check 'test-check' has been resolved.")));
View Full Code Here

Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

                .withTimestamp(new DateTime())
                .withFromType(AlertType.OK)
                .withToType(AlertType.ERROR);
        List<Alert> alerts = Arrays.asList(alert);
       
        BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/v1/messages/chat/target")
                        .withMethod(ClientDriverRequest.Method.POST)
                        .capturingBodyIn(bodyCapture)
                        .withHeader("Content-Type", "application/json")
                        .withHeader("accept", "application/json"),
                giveEmptyResponse());
       
        notificationService.sendNotification(check, subscription, alerts);
       
        JsonNode node = bodyCapture.getContent();
       
        assertThat(node, hasJsonPath("$.content", containsString("test-check")));
        assertThat(node, hasJsonPath("$.content", containsString("ERROR")));
        assertThat(node, hasJsonPath("$.content", containsString(value.toString())));
        assertThat(node, hasJsonPath("$.content", containsString("/#/checks/123")));
View Full Code Here

Examples of com.github.restdriver.clientdriver.capture.JsonBodyCapture

                .withFromType(AlertType.WARN)
                .withToType(AlertType.ERROR);
       
        List<Alert> alerts = Arrays.asList(alert);
       
        BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/myendpoint/thatdoesstuff")
                        .withMethod(Method.POST)
                        .capturingBodyIn(bodyCapture),
                giveResponse("success", "text/plain"));
       
        service.sendNotification(check, subscription, alerts);
       
        JsonNode node = bodyCapture.getContent();
       
       
        assertThat(node, hasJsonPath("$.seyrenUrl", is(seyrenUrl)));
        assertThat(node, hasJsonPath("$.check.name", is("check-name")));
        assertThat(node, hasJsonPath("$.check.state", is("ERROR")));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.