@Test public void test() throws IOException { server.getUrlMapping() .append("/hello", HelloController.class, "hello"); Assert.assertEquals("hello!", makeRequest("/hello").get().asString()); Assert.assertEquals("GET, HEAD, POST, PUT, DELETE, OPTIONS", makeRequest("/hello").options().header("Allow")); }
@Test public void test_only_get() throws IOException { server.getUrlMapping() .append("/hello", HelloController.class, "hello", GET); Assert.assertEquals("hello!", makeRequest("/hello").get().asString()); Assert.assertEquals("GET, HEAD, OPTIONS", makeRequest("/hello").options().header("Allow")); Assert.assertEquals(405, makeRequest("/hello").delete().getResponseCode()); }
@Test public void test_allowPostAndPut() throws IOException { handler = new UrlHandler() .append("/rest", new RestHandler() .post( (request, response) -> response.setBody("post") ) .put( (request, response) -> response.setBody("put") )) ; Assert.assertEquals("post", makeRequest("/rest").post().asString()); Assert.assertEquals("put", makeRequest("/rest").method(ConnectionMethod.PUT).execute().asString()); Assert.assertEquals(405, makeRequest("/rest").get().getResponseCode()); Assert.assertEquals("POST, PUT, OPTIONS", makeRequest("/rest").get().header("Allow")); Assert.assertEquals("POST, PUT, OPTIONS", makeRequest("/rest").options().header("Allow")); }