
driven-adapter.consumer-rest.rest-consumer.rest-consumer.test.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaffold-clean-architecture Show documentation
Show all versions of scaffold-clean-architecture Show documentation
Gradle plugin to create a clean application in Java that already works, It follows our best practices!
package {{package}}.consumer;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.jupiter.api.*;
import org.springframework.test.util.ReflectionTestUtils;
import java.io.IOException;
public class RestConsumerTest {
private static RestConsumer restConsumer;
private static MockWebServer mockBackEnd;
@BeforeAll
static void setUp() throws IOException {
mockBackEnd = new MockWebServer();
mockBackEnd.start();
OkHttpClient client = new OkHttpClient.Builder().build();
String url = mockBackEnd.url("url").toString();
restConsumer = new RestConsumer(url, client, new ObjectMapper());
}
@AfterAll
static void tearDown() throws IOException {
mockBackEnd.shutdown();
}
@Test
@DisplayName("Validate the function testGet.")
void validateTestGet() throws IOException {
mockBackEnd.enqueue(new MockResponse()
.setHeader("Content-Type", "application/json")
.setResponseCode(200)
.setBody("{\"state\" : \"ok\"}"));
var response = restConsumer.testGet();
Assertions.assertEquals("ok", response.getState());
}
@Test
@DisplayName("Validate the function testPost.")
void validateTestPost() throws IOException {
mockBackEnd.enqueue(new MockResponse()
.setHeader("Content-Type", "application/json")
.setResponseCode(200)
.setBody("{\"state\" : \"ok\"}"));
var response = restConsumer.testPost();
Assertions.assertEquals("ok", response.getState());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy