Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Replace spring-cloud-contract-wiremock with wiremock-spring-boot
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Oct 15, 2024
1 parent e9c1738 commit 03df417
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
16 changes: 3 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@
<notion-sdk-jvm.version>1.11.1</notion-sdk-jvm.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Compile -->
<dependency>
Expand Down Expand Up @@ -107,8 +96,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-wiremock</artifactId>
<groupId>org.wiremock.integrations</groupId>
<artifactId>wiremock-spring-boot</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.springframework.batch.test.context.SpringBatchTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import org.wiremock.spring.EnableWireMock;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
Expand All @@ -29,7 +29,7 @@
@Retention(RUNTIME)
@SpringBootTest(properties = "spring.batch.job.enabled=false")
@SpringBatchTest
@AutoConfigureWireMock(port = 0)
@EnableWireMock
public @interface IntegrationTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.github.scordio.springframework.batch.extensions.notion.it.pagination.MultiplePagesDescendingTests.PaginatedDescendingJob.Item;
import io.github.scordio.springframework.batch.extensions.notion.mapping.RecordPropertyMapper;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
Expand Down Expand Up @@ -76,8 +75,9 @@ class MultiplePagesDescendingTests {
@Autowired
ListItemWriter<Item> itemWriter;

@BeforeAll
static void wiremockStubbing() {
@Test
void should_succeed() throws Exception {
// GIVEN
UUID thirdResultId = randomUUID();

JSONObject firstResult = result(randomUUID(), DATABASE_ID,
Expand All @@ -100,12 +100,10 @@ static void wiremockStubbing() {
.withHeader(NOTION_VERSION, equalTo(NOTION_VERSION_VALUE))
.withRequestBody(equalToJson(queryRequest(thirdResultId, PAGE_SIZE, sortByProperty("Name", DESCENDING))))
.willReturn(okJson(queryResponse(thirdResult))));
}

@Test
void should_succeed() throws Exception {
// WHEN
JobExecution jobExecution = launcher.launchJob();

// THEN
then(jobExecution.getExitStatus()).isEqualTo(COMPLETED);

Expand All @@ -119,8 +117,8 @@ void should_succeed() throws Exception {
@SpringBootApplication
static class PaginatedDescendingJob {

@Value("${wiremock.server.port}")
private int wiremockPort;
@Value("${wiremock.server.baseUrl}")
private String wiremockBaseUrl;

@Bean
Job job(JobRepository jobRepository, Step step) {
Expand All @@ -143,7 +141,7 @@ NotionDatabaseItemReader<Item> itemReader() {
reader.setSaveState(false);

reader.setToken("token");
reader.setBaseUrl("http://localhost:" + wiremockPort);
reader.setBaseUrl(wiremockBaseUrl);
reader.setDatabaseId(DATABASE_ID.toString());

reader.setPageSize(PAGE_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.github.scordio.springframework.batch.extensions.notion.it.pagination.MultiplePagesTests.PaginatedJob.Item;
import io.github.scordio.springframework.batch.extensions.notion.mapping.RecordPropertyMapper;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
Expand Down Expand Up @@ -73,8 +72,9 @@ class MultiplePagesTests {
@Autowired
ListItemWriter<Item> itemWriter;

@BeforeAll
static void wiremockStubbing() {
@Test
void should_succeed() throws Exception {
// GIVEN
UUID thirdResultId = randomUUID();

JSONObject firstResult = result(randomUUID(), DATABASE_ID,
Expand All @@ -97,10 +97,7 @@ static void wiremockStubbing() {
.withHeader(NOTION_VERSION, equalTo(NOTION_VERSION_VALUE))
.withRequestBody(equalToJson(queryRequest(thirdResultId, PAGE_SIZE)))
.willReturn(okJson(queryResponse(thirdResult))));
}

@Test
void should_succeed() throws Exception {
// WHEN
JobExecution jobExecution = launcher.launchJob();

Expand All @@ -117,8 +114,8 @@ void should_succeed() throws Exception {
@SpringBootApplication
static class PaginatedJob {

@Value("${wiremock.server.port}")
private int wiremockPort;
@Value("${wiremock.server.baseUrl}")
private String wiremockBaseUrl;

@Bean
Job job(JobRepository jobRepository, Step step) {
Expand All @@ -141,7 +138,7 @@ NotionDatabaseItemReader<Item> itemReader() {
reader.setSaveState(false);

reader.setToken("token");
reader.setBaseUrl("http://localhost:" + wiremockPort);
reader.setBaseUrl(wiremockBaseUrl);
reader.setDatabaseId(DATABASE_ID.toString());

reader.setPageSize(PAGE_SIZE);
Expand Down

0 comments on commit 03df417

Please sign in to comment.