Package com.github.restdriver.clientdriver.capture

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


    }
   
    @Test
    public void waitForReturnsImmediatelyIfCaptureBodyPopulated() {
        long start = System.currentTimeMillis();
        StringBodyCapture bodyCapture = new StringBodyCapture();
        bodyCapture.setBody("some body".getBytes());
       
        waitFor(bodyCapture, 5, TimeUnit.SECONDS);
       
        assertThat(System.currentTimeMillis() - start, lessThan(100L));
    }
View Full Code Here


    }
   
    @Test
    public void waitForSpecifiedTimeIfCaptureBodyIsNotPopulated() {
        long start = System.currentTimeMillis();
        StringBodyCapture bodyCapture = new StringBodyCapture();
       
        waitFor(bodyCapture, 1, TimeUnit.SECONDS);
       
        assertThat(System.currentTimeMillis() - start, greaterThanOrEqualTo(1000L));
    }
View Full Code Here

    public ClientDriverRule clientDriver = new ClientDriverRule();
   
    @Test
    public void canCaptureRequestBodyAsString() throws Exception {
       
        StringBodyCapture capture = new StringBodyCapture();
       
        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 string"));
        HttpResponse correctResponse = client.execute(correctPost);
        EntityUtils.consume(correctResponse.getEntity());
       
        assertThat(capture.getContent(), is("a string"));
    }
View Full Code Here

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

        StringBodyCapture bodyCapture = new StringBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/api/chat.postMessage")
                        .withMethod(ClientDriverRequest.Method.POST)
                        .capturingBodyIn(bodyCapture)
                        .withHeader("accept", "application/json"),
                giveEmptyResponse());
       
        notificationService.sendNotification(check, subscription, alerts);
       
        String content = bodyCapture.getContent();

        assertThat(content, Matchers.containsString("token="));
        assertThat(content, Matchers.containsString("&channel=target"));
        assertThat(content, Matchers.containsString(encode("test-check has entered its ERROR state - [null: 1.0]")));
        assertThat(content, Matchers.containsString(encode("/#/checks/123")));
View Full Code Here

                .withFromType(AlertType.WARN)
                .withToType(AlertType.ERROR);
       
        List<Alert> alerts = Arrays.asList(alert);
       
        BodyCapture<String> bodyCapture = new StringBodyCapture();
       
        clientDriver.addExpectation(
                onRequestTo("/twilio/"+ACCOUNT_SID+"/Messages")
                        .withMethod(Method.POST)
                        .capturingBodyIn(bodyCapture),
                giveResponse("Thanks for letting me know", "text/plain"));
       
       
        // This will fail with an NotificationFailedException if anything goes wrong.
        service.sendNotification(check, subscription, alerts);
   
        String body=bodyCapture.getContent();
       
        assertThat(body, containsString("To=%2B10987654321"));
        assertThat(body, containsString("From=%2B11234567890"));
        assertThat(body, containsString("Body=ERROR+Check+check-name+has+exceeded+its+threshold"));
       
View Full Code Here

TOP

Related Classes of com.github.restdriver.clientdriver.capture.StringBodyCapture

Copyright © 2018 www.massapicom. 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.