@Test public void shouldWorkWithQueryStringParams() { Request request = new Request(Verb.GET, "http://stackoverflow.com/search?q=oauth+authentication&more=stuff"); assertEquals(2, request.getQueryStringParams().size()); assertEquals("http://stackoverflow.com/search", request.getSanitizedUrl()); Response response = request.send(); assertEquals(200, response.getCode()); assertTrue(response.getBody().length() > 0); }
@Get("/injection/:param1/:param2") public String route( String param1, String param2, Context context, Request request, Response response, Cookies cookies) { return String.join( "/", param1, param2, context.getClass().getSimpleName(), request.getClass().getSimpleName(), response.getClass().getSimpleName(), cookies.getClass().getSimpleName()); }
@Test public void shouldFollowRedirects() { Response response = new Request(Verb.GET, "http://bit.ly/whatsup").send(); assertEquals(200, response.getCode()); assertTrue(response.getBody().length() > 0); }
@Test public void shouldReturn404ForUnexistentUrls() { Response response = new Request(Verb.GET, "http://xkcd.com/404").send(); assertEquals(404, response.getCode()); }
@Test public void shouldReturn200WhenRequestIsOk() { Response response = new Request(Verb.GET, "http://www.google.com").send(); assertEquals(200, response.getCode()); assertTrue(response.getBody().length() > 0); }
@Test public void createTransactionReturnsOk() { // create "cars" transaction Response response = client .path("/transactionservice/transaction/10") .request() .put(Entity.json(new Transaction("cars", new BigDecimal(5000), 0l))); assertEquals(200, response.getStatus()); assertEquals( TransactionService.OperationResult.OK, response.readEntity(TransactionService.OperationResult.class)); // create "shopping" transaction response = client .path("/transactionservice/transaction/11") .request() .put(Entity.json(new Transaction("shopping", new BigDecimal(10000), 10l))); assertEquals(200, response.getStatus()); assertEquals( TransactionService.OperationResult.OK, response.readEntity(TransactionService.OperationResult.class)); // get "cars" transactions response = client.path("/transactionservice/type/cars").request().get(); assertEquals(200, response.getStatus()); @SuppressWarnings("unchecked") List<Integer> ids = response.readEntity(List.class); assertEquals(1, ids.size()); assertEquals(10, ids.get(0).intValue()); // get "sum" for transaction 10 response = client.path("/transactionservice/sum/10").request().get(); assertEquals(200, response.getStatus()); AggregatorService.Sum sum = response.readEntity(AggregatorService.Sum.class); assertEquals(15000, sum.getSum().intValue()); // get "sum" for transaction 11 response = client.path("/transactionservice/sum/11").request().get(); assertEquals(200, response.getStatus()); sum = response.readEntity(AggregatorService.Sum.class); assertEquals(10000, sum.getSum().intValue()); }