public Response collectMoney(MoneyCollect moneyCollect) { Gson gson = new Gson(); String payload = gson.toJson(moneyCollect); WebTarget moneyTarget = appTarget.path("money"); WebTarget collectMoneyTarget = moneyTarget.path("collect"); return collectMoneyTarget .request() .accept(MediaType.APPLICATION_JSON) .post(Entity.entity(payload, MediaType.APPLICATION_JSON), Response.class); }
public Response sendMoney(MoneySend moneySend) { Gson gson = new Gson(); String payload = gson.toJson(moneySend); WebTarget moneyTarget = appTarget.path("money"); WebTarget sendMoneyTarget = moneyTarget.path("send"); return sendMoneyTarget .request() .accept(MediaType.APPLICATION_JSON) .post(Entity.entity(payload, MediaType.APPLICATION_JSON), Response.class); }
@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()); }
public PaymentNotification[] getNotifications(String userId) { WebTarget notificationTarget = appTarget.path("notification/user/" + userId); Invocation.Builder setupBuilder = notificationTarget.request(MediaType.APPLICATION_JSON); Response response = setupBuilder.get(); Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss.SSS").create(); String json = response.readEntity(String.class); return gson.fromJson(json, PaymentNotification[].class); }
public static String checkLogin(Userinfo ui) { Client client = ClientBuilder.newClient(config); WebTarget target = client.target(getBaseUri()); return target .path("users") .path("role=" + ui.getUsertype()) .path("email=" + ui.getUsername()) .path("password=" + ui.getPassword()) .request() .accept(MediaType.TEXT_HTML) .get(String.class); }
public Response backdoorTeardown() { WebTarget backdoorTarget = appTarget.path("backdoor"); WebTarget setupTarget = backdoorTarget.path("teardown"); Invocation.Builder setupBuilder = setupTarget.request(MediaType.TEXT_PLAIN_TYPE); return setupBuilder.get(); }