org.eclipse.jetty.http.HttpTester Java Examples
The following examples show how to use
org.eclipse.jetty.http.HttpTester.
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: ServletTestUtils.java From java-slack-sdk with MIT License | 6 votes |
public static HttpTester.Request prepareRequest(String signingSecret, String requestBody) { HttpTester.Request request = HttpTester.newRequest(); request.setMethod("POST"); request.setHeader("Host", "tester"); // must be "tester" request.setURI("/"); request.setVersion("HTTP/1.1"); request.setHeader("content-type", "application/json"); request.setHeader("Connection", "close"); String timestamp = String.valueOf((System.currentTimeMillis() / 1000)); SlackSignature.Generator signatureGenerator = new SlackSignature.Generator(signingSecret); String signature = signatureGenerator.generate(timestamp, requestBody); request.setHeader(SlackSignature.HeaderNames.X_SLACK_REQUEST_TIMESTAMP, timestamp); request.setHeader(SlackSignature.HeaderNames.X_SLACK_SIGNATURE, signature); request.setContent(requestBody); return request; }
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 goodbye() 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\": \"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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: EventsApiHandlerTest.java From java-slack-sdk with MIT License | 6 votes |
@Ignore @Test public void urlVerification() throws Exception { ServletTester tester = getServletTester(); HttpTester.Request request = 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(equalTo("text/plain"))); }
Example #11
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 #12
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 #13
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 #14
Source File: EventsApiHandlerTest.java From java-slack-sdk with MIT License | 5 votes |
private static HttpTester.Request prepareRequest() { HttpTester.Request request = HttpTester.newRequest(); request.setMethod("POST"); request.setHeader("Host", "tester"); // should be "tester" request.setURI("/"); request.setVersion("HTTP/1.1"); request.setHeader("content-type", "application/json"); request.setHeader("Connection", "close"); return request; }
Example #15
Source File: UsernameFunctionProcessorTest.java From knox with Apache License 2.0 | 5 votes |
private void testSetup(String username, Map<String,String> initParams ) throws Exception { String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); Log.setLog( new NoOpLogger() ); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter( username ) ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example #16
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 #17
Source File: UrlRewriteServletFilterTest.java From knox with Apache License 2.0 | 5 votes |
private void testSetUp(Map<String,String> initParams ) throws Exception { String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter() ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example #18
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 #19
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
private HttpTester.Request buildRequest(String method, String uri) { HttpTester.Request request = HttpTester.newRequest(); request.setMethod(method); request.setHeader("Host", "tester"); // must be "tester" request.setURI(uri); request.setVersion("HTTP/1.1"); request.setHeader("Connection", "close"); return request; }
Example #20
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void foo_towards_bar() throws Exception { ServletTester tester = TestUtils.getServletTester(barApp); 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 #21
Source File: WebEndpointTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void bar_POST() throws Exception { ServletTester tester = TestUtils.getServletTester(barApp); HttpTester.Request request = buildRequest("POST", "/bar"); HttpTester.Response response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertThat(response.getContent(), is(equalTo("Thanks!"))); assertThat(response.getStatus(), is(equalTo(200))); }
Example #22
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 #23
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 #24
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 #25
Source File: TestUtils.java From java-slack-sdk with MIT License | 5 votes |
public static HttpTester.Request prepareRequest() { HttpTester.Request request = HttpTester.newRequest(); request.setMethod("POST"); request.setHeader("Host", "tester"); // must be "tester" request.setURI("/"); request.setVersion("HTTP/1.1"); request.setHeader("content-type", "application/json"); request.setHeader("Connection", "close"); return request; }
Example #26
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 #27
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 #28
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 #29
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 #30
Source File: AssetServletTest.java From dropwizard-configurable-assets-bundle with Apache License 2.0 | 4 votes |
private HttpTester.Response makeRequest(String uri) throws Exception { request.setURI(uri); return makeRequest(); }