From 887368b941f4e98be101afcc260c863d884b851a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20Mauricio=20Falla=20Casta=C3=B1eda?= Date: Mon, 29 Aug 2022 15:04:41 -0500 Subject: [PATCH] Abstraccion unit test --- .../java/conekta/io/CustomersClientTest.java | 59 ++++-------- .../java/conekta/io/OrdersClientTest.java | 95 +++++-------------- src/test/java/conekta/io/Utils.java | 13 +++ .../java/conekta/io/WebhooksClientTest.java | 49 ++++------ 4 files changed, 73 insertions(+), 143 deletions(-) diff --git a/src/test/java/conekta/io/CustomersClientTest.java b/src/test/java/conekta/io/CustomersClientTest.java index 2af73d8..945e549 100644 --- a/src/test/java/conekta/io/CustomersClientTest.java +++ b/src/test/java/conekta/io/CustomersClientTest.java @@ -4,13 +4,11 @@ import conekta.io.client.impl.CustomersClient; import conekta.io.config.ConektaAuthenticator; import conekta.io.config.ConektaObjectMapper; -import conekta.io.config.Constants; import conekta.io.error.ConektaErrorResponse; import conekta.io.model.PaginatedConektaObject; import conekta.io.model.impl.Customer; import conekta.io.model.submodel.Event; import conekta.io.model.submodel.PaymentSource; -import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -39,11 +37,8 @@ void createCustomer() throws URISyntaxException, IOException { // Arrange String customerJson = Utils.readFile("clients/customer.json"); Customer cus = ConektaObjectMapper.getInstance().stringJsonToObject(customerJson, Customer.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(customerJson) - .setResponseCode(201)); + + Utils.buildMockServer(this.mockWebServer, customerJson, 201); // Act ConektaResponse customerConektaResponse = customersClient.createCustomer(cus); @@ -60,11 +55,8 @@ void createCustomerWithError() throws URISyntaxException, IOException { String errorJson = Utils.readFile("clients/errorMail.json"); Customer cus = ConektaObjectMapper.getInstance().stringJsonToObject(customerJson, Customer.class); ConektaErrorResponse error = ConektaObjectMapper.getInstance().stringJsonToObject(errorJson, ConektaErrorResponse.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(errorJson) - .setResponseCode(404)); + + Utils.buildMockServer(this.mockWebServer, errorJson, 404); // Act ConektaResponse customerConektaResponse = customersClient.createCustomer(cus); @@ -79,11 +71,8 @@ void retrieveCustomer() throws IOException, URISyntaxException { // Arrange String customerJson = Utils.readFile("clients/customer.json"); Customer cus = ConektaObjectMapper.getInstance().stringJsonToObject(customerJson, Customer.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(customerJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, customerJson, 200); // Act ConektaResponse customerConektaResponse = customersClient.retrieveCustomer("1"); @@ -99,11 +88,8 @@ void getCustomers() throws IOException, URISyntaxException { PaginatedConektaObject paginatedConektaObject = new PaginatedConektaObject<>(); paginatedConektaObject.setData(List.of(cus)); String s = ConektaObjectMapper.getInstance().conektaObjectToString(paginatedConektaObject); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(s) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, s, 200); // Act ConektaResponse> customers = customersClient.getCustomers(null); @@ -118,11 +104,8 @@ void updateCustomer() throws IOException, URISyntaxException { String customerJsonModified = Utils.readFile("clients/customerModified.json"); Customer cus = ConektaObjectMapper.getInstance().stringJsonToObject(customerJson, Customer.class); Customer cusModified = ConektaObjectMapper.getInstance().stringJsonToObject(customerJsonModified, Customer.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(customerJsonModified) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, customerJsonModified, 200); // Act ConektaResponse customerConektaResponse = customersClient.updateCustomer("1", cusModified); @@ -141,11 +124,8 @@ void deleteCustomer() throws IOException, URISyntaxException { Customer cus = ConektaObjectMapper.getInstance().stringJsonToObject(customerJson, Customer.class); cus.setDeleted(true); String deletedJson = ConektaObjectMapper.getInstance().conektaObjectToString(cus); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(deletedJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, deletedJson, 200); // Act ConektaResponse customerConektaResponse = customersClient.deleteCustomer("1"); @@ -162,11 +142,8 @@ void getCustomerEvents() throws IOException, URISyntaxException { PaginatedConektaObject paginatedConektaObject = new PaginatedConektaObject<>(); paginatedConektaObject.setData(List.of(event)); String s = ConektaObjectMapper.getInstance().conektaObjectToString(paginatedConektaObject); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(s) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, s, 200); // Act ConektaResponse> customerEvents = customersClient.getCustomerEvents("1", null); @@ -183,11 +160,9 @@ void getCustomerPaymentSources() throws IOException, URISyntaxException { PaginatedConektaObject paginatedConektaObject = new PaginatedConektaObject<>(); paginatedConektaObject.setData(List.of(paymentSource)); String s = ConektaObjectMapper.getInstance().conektaObjectToString(paginatedConektaObject); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(s) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, s, 200); + // Act ConektaResponse> customerPaymentSources = customersClient.getCustomerPaymentSources("1", null); // Assert diff --git a/src/test/java/conekta/io/OrdersClientTest.java b/src/test/java/conekta/io/OrdersClientTest.java index 37cb492..60dd1f1 100644 --- a/src/test/java/conekta/io/OrdersClientTest.java +++ b/src/test/java/conekta/io/OrdersClientTest.java @@ -1,17 +1,15 @@ -package conekta.io; +package conekta.io.client.impl; +import conekta.io.Utils; import conekta.io.client.ConektaResponse; -import conekta.io.client.impl.OrdersClient; import conekta.io.config.ConektaAuthenticator; import conekta.io.config.ConektaObjectMapper; -import conekta.io.config.Constants; import conekta.io.error.ConektaError; import conekta.io.model.PaginatedConektaObject; import conekta.io.model.request.OrderRefundReq; import conekta.io.model.request.OrderReq; import conekta.io.model.response.Order; import conekta.io.model.submodel.Charge; -import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -41,11 +39,8 @@ void createOrder() throws URISyntaxException, IOException, InterruptedException String orderResponseJson = Utils.readFile("orders/orderResponse.json"); OrderReq orderReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderRequestJson, OrderReq.class); Order orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderResponseJson, Order.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderResponseJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderResponseJson, 200); // Act ConektaResponse order = ordersClient.createOrder(orderReq); @@ -61,11 +56,8 @@ void createOrderFail() throws URISyntaxException, IOException, InterruptedExcept String orderResponseFailJson = Utils.readFile("orders/orderCreateResponseFail.json"); OrderReq orderReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderRequestJson, OrderReq.class); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderResponseFailJson, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderResponseFailJson) - .setResponseCode(404)); + + Utils.buildMockServer(this.mockWebServer, orderResponseFailJson, 404); // Act ConektaResponse order = ordersClient.createOrder(orderReq); @@ -81,11 +73,8 @@ void updateOrder() throws IOException, InterruptedException, URISyntaxException String orderJsonModified = Utils.readFile("orders/orderModified.json"); OrderReq orderReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderUpdateRequest, OrderReq.class); Order ordModified = ConektaObjectMapper.getInstance().stringJsonToObject(orderJsonModified, Order.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderJsonModified) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderJsonModified, 200); // Act ConektaResponse order = ordersClient.updateOrder("1", orderReq); @@ -103,11 +92,8 @@ void updateOrderFail() throws IOException, InterruptedException, URISyntaxExcept String orderUpdateRespFailJson = Utils.readFile("orders/orderUpdateResponseFail.json"); OrderReq orderReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderRequestJson, OrderReq.class); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderUpdateRespFailJson, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderUpdateRespFailJson) - .setResponseCode(404)); + + Utils.buildMockServer(this.mockWebServer, orderUpdateRespFailJson, 404); // Act ConektaResponse order = ordersClient.updateOrder("1", orderReq); @@ -121,11 +107,9 @@ void updateOrderFail() throws IOException, InterruptedException, URISyntaxExcept void getOrder() throws IOException, InterruptedException, URISyntaxException { String orderJson = Utils.readFile("orders/orderResponse.json"); Order order = ConektaObjectMapper.getInstance().stringJsonToObject(orderJson, Order.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderJson, 200); + // Act ConektaResponse orderResponse = ordersClient.retrieveOrder("1"); // Assert @@ -139,11 +123,8 @@ void getChargesOrder() throws IOException, URISyntaxException { String orderCharge = Utils.readFile("orders/orderCharge.json"); Charge charge = ConektaObjectMapper.getInstance().stringJsonToObject(orderCharge, Charge.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderChargesResponse) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderChargesResponse, 200); // Act ConektaResponse> order = ordersClient.getOrderCharges("1", null); @@ -159,11 +140,7 @@ void getChargesOrderFail() throws IOException, URISyntaxException { String orderChargesFailResponse = Utils.readFile("orders/orderChargesFail.json"); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderChargesFailResponse, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderChargesFailResponse) - .setResponseCode(404)); + Utils.buildMockServer(this.mockWebServer, orderChargesFailResponse, 404); // Act ConektaResponse> order = ordersClient.getOrderCharges("1", null); @@ -180,11 +157,8 @@ void getChargeOrder() throws IOException, URISyntaxException { String orderCharge = Utils.readFile("Orders/orderCharge.json"); Charge charge = ConektaObjectMapper.getInstance().stringJsonToObject(orderCharge, Charge.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderChargeResponse) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderChargeResponse, 200); // Act ConektaResponse order = ordersClient.getOrderCharge("1", "anything"); @@ -200,11 +174,7 @@ void getChargeOrderFail() throws IOException, URISyntaxException { String orderChargeFailResponse = Utils.readFile("Orders/orderChargeFailResponse.json"); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderChargeFailResponse, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderChargeFailResponse) - .setResponseCode(404)); + Utils.buildMockServer(this.mockWebServer, orderChargeFailResponse, 404); // Act ConektaResponse order = ordersClient.getOrderCharge("1", "nothing"); @@ -221,11 +191,9 @@ void getOrders() throws IOException, URISyntaxException { String orderStr = Utils.readFile("orders/orderData.json"); Order order = ConektaObjectMapper.getInstance().stringJsonToObject(orderStr, Order.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderListResponse) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderListResponse, 200); + // Act ConektaResponse> orderResponse = ordersClient.getOrders(null); // Assert @@ -239,11 +207,7 @@ void getOrdersFail() throws IOException, URISyntaxException { String orderChargesFailResponse = Utils.readFile("orders/orderChargesFail.json"); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderChargesFailResponse, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderChargesFailResponse) - .setResponseCode(404)); + Utils.buildMockServer(this.mockWebServer, orderChargesFailResponse, 404); // Act ConektaResponse> orderResponse = ordersClient.getOrders(null); @@ -260,11 +224,8 @@ void refundOrder() throws URISyntaxException, IOException, InterruptedException String orderRefundResponseJson = Utils.readFile("orders/orderRefundResponse.json"); OrderRefundReq orderRefundReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderRefundRequestJson, OrderRefundReq.class); Order orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderRefundResponseJson, Order.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderRefundResponseJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, orderRefundResponseJson, 200); // Act ConektaResponse order = ordersClient.refundOrder("anything", orderRefundReq); @@ -281,11 +242,7 @@ void refundOrdersFail() throws IOException, URISyntaxException { OrderRefundReq orderRefundReq = ConektaObjectMapper.getInstance().stringJsonToObject(orderRefundRequestJson, OrderRefundReq.class); ConektaError orderResp = ConektaObjectMapper.getInstance().stringJsonToObject(orderRefundFailResponse, ConektaError.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(orderRefundFailResponse) - .setResponseCode(404)); + Utils.buildMockServer(this.mockWebServer, orderRefundFailResponse, 404); // Act ConektaResponse orderResponse = ordersClient.refundOrder("anything", orderRefundReq); diff --git a/src/test/java/conekta/io/Utils.java b/src/test/java/conekta/io/Utils.java index bfcbba2..98868ae 100644 --- a/src/test/java/conekta/io/Utils.java +++ b/src/test/java/conekta/io/Utils.java @@ -1,5 +1,9 @@ package conekta.io; +import conekta.io.config.Constants; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; @@ -15,4 +19,13 @@ public static String readFile(String path, Charset encoding) throws IOException, public static String readFile(String path) throws IOException, URISyntaxException { return readFile(path, Charset.defaultCharset()); } + + public static void buildMockServer(MockWebServer mockWebServer, String responseBodyJson, int statusCode) { + mockWebServer.enqueue(new MockResponse() + .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) + .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) + .setBody(responseBodyJson) + .setResponseCode(statusCode)); + } + } diff --git a/src/test/java/conekta/io/WebhooksClientTest.java b/src/test/java/conekta/io/WebhooksClientTest.java index bd4c52d..7e9e541 100644 --- a/src/test/java/conekta/io/WebhooksClientTest.java +++ b/src/test/java/conekta/io/WebhooksClientTest.java @@ -4,11 +4,9 @@ import conekta.io.client.impl.WebhooksClient; import conekta.io.config.ConektaAuthenticator; import conekta.io.config.ConektaObjectMapper; -import conekta.io.config.Constants; import conekta.io.error.ConektaErrorResponse; import conekta.io.model.PaginatedConektaObject; import conekta.io.model.impl.Webhook; -import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -37,11 +35,9 @@ void createWebhook() throws IOException, URISyntaxException { // Arrange String webhookJson = Utils.readFile("webhooks/webhook.json"); Webhook webhook = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJson, Webhook.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(webhookJson) - .setResponseCode(201)); + + Utils.buildMockServer(this.mockWebServer, webhookJson, 201); + // Act ConektaResponse webhookConektaResponse = webhooksClient.createWebhook(webhook); // Assert @@ -54,11 +50,9 @@ void retrieveWebhook() throws IOException, URISyntaxException { // Arrange String webhookJson = Utils.readFile("webhooks/webhook.json"); Webhook webhook = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJson, Webhook.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(webhookJson) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, webhookJson, 200); + // Act ConektaResponse webhookConektaResponse = webhooksClient.retrieveWebhook(webhook.getId()); // Assert @@ -74,11 +68,9 @@ void getWebhooks() throws IOException, URISyntaxException { PaginatedConektaObject paginatedConektaObject = new PaginatedConektaObject<>(); paginatedConektaObject.setData(List.of(webhook)); String s = ConektaObjectMapper.getInstance().conektaObjectToString(paginatedConektaObject); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(s) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, s, 200); + // Act ConektaResponse> webhooksConektaResponse = webhooksClient.getWebhooks(null); // Assert @@ -93,11 +85,9 @@ void updateWebhook() throws IOException, URISyntaxException { String webhookJsonUpdated = Utils.readFile("webhooks/webhookUpdated.json"); Webhook webhook = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJson, Webhook.class); Webhook webhookUpdated = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJsonUpdated, Webhook.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(webhookJsonUpdated) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, webhookJsonUpdated, 200); + // Act ConektaResponse webhookConektaResponse = webhooksClient.updateWebhook(webhook.getId(), webhook); // Assert @@ -113,11 +103,9 @@ void deleteWebhook() throws IOException, URISyntaxException { String webhookJsonDeleted = Utils.readFile("webhooks/webhookDeleted.json"); Webhook webhook = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJson, Webhook.class); webhook.setDeleted(true); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(webhookJsonDeleted) - .setResponseCode(200)); + + Utils.buildMockServer(this.mockWebServer, webhookJsonDeleted, 200); + // Act ConektaResponse webhookConektaResponse = webhooksClient.deleteWebhook(webhook.getId()); // Assert @@ -132,11 +120,8 @@ void createWithError() throws IOException, URISyntaxException { ConektaErrorResponse error = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJsonError, ConektaErrorResponse.class); Webhook webhook = ConektaObjectMapper.getInstance().stringJsonToObject(webhookJsonError, Webhook.class); - mockWebServer.enqueue(new MockResponse() - .addHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8) - .addHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON) - .setBody(webhookJsonError) - .setResponseCode(404)); + Utils.buildMockServer(this.mockWebServer, webhookJsonError, 404); + // Act ConektaResponse webhookConektaResponse = webhooksClient.createWebhook(webhook); // Assert