Java Code Examples for org.eclipse.jetty.http.HttpTester#parseResponse()
The following examples show how to use
org.eclipse.jetty.http.HttpTester#parseResponse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void urlVerification() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); UrlVerificationPayload payload = new UrlVerificationPayload(); payload.setChallenge("cha-xxxxxx"); payload.setToken("token-xxxx"); request.setContent(GsonFactory.createSnakeCase().toJson(payload)); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("cha-xxxxxx"))); assertThat(response.getStatus(), is(equalTo(200))); assertThat(response.get("Content-Type"), is(startsWith("text/plain"))); }
Example 2
Source File: EventsApiHandlerTest.java From java-slack-sdk with MIT License | 6 votes |
@Ignore @Test public void goodbye() throws Exception { ServletTester tester = getServletTester(); HttpTester.Request request = prepareRequest(); request.setContent("{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"goodbye\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(200))); assertThat(GOODBYE_CALL_COUNTER.get(), is(1)); }
Example 3
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void app_uninstalled() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); request.setContent("{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"app_uninstalled\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(200))); assertThat(appUninstallsCalls.get(), is(1)); }
Example 4
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void invalid() throws Exception { ServletTester tester = ServletTestUtils.getServletTester(webApp); HttpTester.Request request = ServletTestUtils.prepareRequest("invalid", "{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"goodbye\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(401))); assertThat(goodbyeCalls.get(), is(0)); }
Example 5
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void goodbye() throws Exception { ServletTester tester = ServletTestUtils.getServletTester(webApp); HttpTester.Request request = ServletTestUtils.prepareRequest(signingSecret, "{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"goodbye\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(200))); assertThat(goodbyeCalls.get(), is(1)); }
Example 6
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void app_uninstalled() throws Exception { ServletTester tester = ServletTestUtils.getServletTester(webApp); HttpTester.Request request = ServletTestUtils.prepareRequest(signingSecret, "{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"app_uninstalled\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(200))); assertThat(appUninstallsCalls.get(), is(1)); }
Example 7
Source File: EventsApiHandlerTest.java From java-slack-sdk with MIT License | 6 votes |
@Ignore @Test public void app_uninstalled() throws Exception { ServletTester tester = getServletTester(); HttpTester.Request request = prepareRequest(); request.setContent("{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"app_uninstalled\"\n" + " },\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response.getStatus(), is(equalTo(200))); assertThat(APP_UNINSTALLED_CALL_COUNTER.get(), is(1)); }
Example 8
Source File: EventsApiHandlerTest.java From java-slack-sdk with MIT License | 5 votes |
@Ignore @Test public void message() throws Exception { ServletTester tester = getServletTester(); HttpTester.Request request = prepareRequest(); request.setContent("{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"message\",\n" + " \"channel\": \"C2147483705\",\n" + " \"user\": \"U2147483697\",\n" + " \"text\": \"Hello world\",\n" + " \"ts\": \"1355517523.000005\"\n" + "} ,\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response1 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response2 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response3 = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response1.getStatus(), is(equalTo(200))); assertThat(response2.getStatus(), is(equalTo(200))); assertThat(response3.getStatus(), is(equalTo(200))); assertThat(MESSAGE_CALL_COUNTER.get(), is(3)); }
Example 9
Source File: SlashCommandTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void weather() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); // https://api.slack.com/slash-commands request.setContent("token=gIkuvaNzQIHg97ATvDxqgjtO" + "&team_id=T0001" + "&team_domain=example" + "&enterprise_id=E0001" + "&enterprise_name=Globular%20Construct%20Inc" + "&channel_id=C2147483705" + "&channel_name=test" + "&user_id=U2147483697" + "&user_name=Steve" + "&command=/weather" + "&text=94070" + "&response_url=https://hooks.slack.com/commands/1234/5678" + "&trigger_id=13345224609.738474920.8088930838d88f008e0"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("{\"text\":\"It\\u0027s rainy in the area: 94070\"}"))); assertThat(response.getStatus(), is(equalTo(200))); assertThat(response.get("Content-Type"), is(startsWith("application/json"))); assertThat(weatherCalls.get(), is(1)); }
Example 10
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void message() throws Exception { ServletTester tester = ServletTestUtils.getServletTester(webApp); HttpTester.Request request = ServletTestUtils.prepareRequest(signingSecret, "{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"message\",\n" + " \"channel\": \"C2147483705\",\n" + " \"user\": \"U2147483697\",\n" + " \"text\": \"Hello world\",\n" + " \"ts\": \"1355517523.000005\"\n" + "} ,\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response1 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response2 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response3 = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response1.getStatus(), is(equalTo(200))); assertThat(response2.getStatus(), is(equalTo(200))); assertThat(response3.getStatus(), is(equalTo(200))); assertThat(messageCalls.get(), is(3)); }
Example 11
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void urlVerification() throws Exception { ServletTester tester = ServletTestUtils.getServletTester(webApp); UrlVerificationPayload payload = new UrlVerificationPayload(); payload.setChallenge("cha-xxxxxx"); payload.setToken("token-xxxx"); HttpTester.Request request = ServletTestUtils.prepareRequest(signingSecret, GsonFactory.createSnakeCase().toJson(payload)); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("cha-xxxxxx"))); assertThat(response.getStatus(), is(equalTo(200))); assertThat(response.get("Content-Type"), is(startsWith("text/plain"))); }
Example 12
Source File: TestUtils.java From knox with Apache License 2.0 | 5 votes |
public static HttpTester.Response execute( ServletTester server, HttpTester.Request request ) throws Exception { LOG.debug( "execute: request=" + request ); ByteBuffer requestBuffer = request.generate(); LOG.trace( "execute: requestBuffer=[" + new String(requestBuffer.array(),0,requestBuffer.limit(), StandardCharsets.UTF_8) + "]" ); ByteBuffer responseBuffer = server.getResponses( requestBuffer, 30, TimeUnit.SECONDS ); HttpTester.Response response = HttpTester.parseResponse( responseBuffer ); LOG.trace( "execute: responseBuffer=[" + new String(responseBuffer.array(),0,responseBuffer.limit(), StandardCharsets.UTF_8) + "]" ); LOG.debug( "execute: reponse=" + response ); return response; }
Example 13
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void bar_GET() throws Exception { ServletTester tester = TestUtils.getServletTester(barApp); HttpTester.Request request = buildRequest("GET", "/bar"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("{\"error\":\"Not found\"}"))); assertThat(response.getStatus(), is(equalTo(404))); }
Example 14
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void foo_POST() throws Exception { ServletTester tester = TestUtils.getServletTester(fooApp); HttpTester.Request request = buildRequest("POST", "/foo"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("{\"error\":\"Not found\"}"))); assertThat(response.getStatus(), is(equalTo(404))); }
Example 15
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void foo_GET() throws Exception { ServletTester tester = TestUtils.getServletTester(fooApp); HttpTester.Request request = buildRequest("GET", "/foo"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("Thanks!"))); assertThat(response.getStatus(), is(equalTo(200))); }
Example 16
Source File: EventsApiTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void message() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); request.setContent("{\n" + " \"token\": \"XXYYZZ\",\n" + " \"team_id\": \"TXXXXXXXX\",\n" + " \"api_app_id\": \"AXXXXXXXXX\",\n" + " \"event\": {\n" + " \"type\": \"message\",\n" + " \"channel\": \"C2147483705\",\n" + " \"user\": \"U2147483697\",\n" + " \"text\": \"Hello world\",\n" + " \"ts\": \"1355517523.000005\"\n" + "} ,\n" + " \"type\": \"event_callback\",\n" + " \"event_id\": \"EvXXXXXXXX\",\n" + " \"event_time\": 1234567890\n" + "}"); HttpTester.Response response1 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response2 = HttpTester.parseResponse(tester.getResponses(request.generate())); HttpTester.Response response3 = HttpTester.parseResponse(tester.getResponses(request.generate())); // wait for the async execution Thread.sleep(200L); assertThat(response1.getStatus(), is(equalTo(200))); assertThat(response2.getStatus(), is(equalTo(200))); assertThat(response3.getStatus(), is(equalTo(200))); assertThat(messageCalls.get(), is(3)); }
Example 17
Source File: SlashCommandTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void echo() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); // https://api.slack.com/slash-commands request.setContent("token=gIkuvaNzQIHg97ATvDxqgjtO" + "&team_id=T0001" + "&team_domain=example" + "&enterprise_id=E0001" + "&enterprise_name=Globular%20Construct%20Inc" + "&channel_id=C2147483705" + "&channel_name=test" + "&user_id=U2147483697" + "&user_name=Steve" + "&command=/echo" + "&text=Can I ask you a favor?" + "&response_url=https://hooks.slack.com/commands/1234/5678" + "&trigger_id=13345224609.738474920.8088930838d88f008e0"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo(""))); assertThat(response.getStatus(), is(equalTo(200))); assertThat(response.get("Content-Type"), is(startsWith("plain/text"))); assertThat(echoCalls.get(), is(1)); verify(echoSenderMock, times(1)).send(Mockito.any(SlashCommandResponse.class)); }
Example 18
Source File: DialogTest.java From java-slack-sdk with MIT License | 4 votes |
@Test public void submission_ok() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); String payload = "{\n" + " \"type\": \"dialog_submission\",\n" + " \"submission\": {\n" + " \"name\": \"Sigourney Dreamweaver\",\n" + " \"email\": \"[email protected]\",\n" + " \"phone\": \"+1 800-555-1212\",\n" + " \"meal\": \"burrito\",\n" + " \"comment\": \"No sour cream please\",\n" + " \"team_channel\": \"C0LFFBKPB\",\n" + " \"who_should_sing\": \"U0MJRG1AL\"\n" + " },\n" + " \"callback_id\": \"ok-submission-callback-id\",\n" + " \"state\": \"vegetarian\",\n" + " \"team\": {\n" + " \"id\": \"T1ABCD2E12\",\n" + " \"domain\": \"coverbands\"\n" + " },\n" + " \"user\": {\n" + " \"id\": \"W12A3BCDEF\",\n" + " \"name\": \"dreamweaver\"\n" + " },\n" + " \"channel\": {\n" + " \"id\": \"C1AB2C3DE\",\n" + " \"name\": \"coverthon-1999\"\n" + " },\n" + " \"action_ts\": \"936893340.702759\",\n" + " \"token\": \"legacy-fixed-value\",\n" + " \"response_url\": \"https://hooks.slack.com/app/T012AB0A1/123456789/JpmK0yzoZDeRiqfeduTBYXWQ\"\n" + "}"; request.setContent("payload=" + URLEncoder.encode(payload, "UTF-8")); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo(""))); assertThat(response.getStatus(), is(equalTo(200))); verify(submissionSenderMock, times(1)).send(Mockito.any(ActionResponse.class)); }
Example 19
Source File: DialogTest.java From java-slack-sdk with MIT License | 4 votes |
@Test public void submission_error() throws Exception { ServletTester tester = TestUtils.getServletTester(webApp); HttpTester.Request request = TestUtils.prepareRequest(); String payload = "{\n" + " \"type\": \"dialog_submission\",\n" + " \"submission\": {\n" + " \"name\": \"Sigourney Dreamweaver\",\n" + " \"email\": \"sigdre\",\n" + " \"phone\": \"+1 800-555-1212\",\n" + " \"meal\": \"burrito\",\n" + " \"comment\": \"No sour cream please\",\n" + " \"team_channel\": \"C0LFFBKPB\",\n" + " \"who_should_sing\": \"U0MJRG1AL\"\n" + " },\n" + " \"callback_id\": \"ng-submission-callback-id\",\n" + " \"state\": \"vegetarian\",\n" + " \"team\": {\n" + " \"id\": \"T1ABCD2E12\",\n" + " \"domain\": \"coverbands\"\n" + " },\n" + " \"user\": {\n" + " \"id\": \"W12A3BCDEF\",\n" + " \"name\": \"dreamweaver\"\n" + " },\n" + " \"channel\": {\n" + " \"id\": \"C1AB2C3DE\",\n" + " \"name\": \"coverthon-1999\"\n" + " },\n" + " \"action_ts\": \"936893340.702759\",\n" + " \"token\": \"legacy-fixed-value\",\n" + " \"response_url\": \"https://hooks.slack.com/app/T012AB0A1/123456789/JpmK0yzoZDeRiqfeduTBYXWQ\"\n" + "}"; request.setContent("payload=" + URLEncoder.encode(payload, "UTF-8")); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("{\"errors\":[{\"name\":\"email\",\"error\":\"must be an email!\"}]}"))); assertThat(response.getStatus(), is(equalTo(200))); }
Example 20
Source File: AssetServletTest.java From dropwizard-configurable-assets-bundle with Apache License 2.0 | 4 votes |
private HttpTester.Response makeRequest() throws Exception { return HttpTester.parseResponse(servletTester.getResponses(request.generate())); }