-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
489 additions
and
78 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
client/src/main/java/com/gdevxy/blog/client/contentful/ContentfulCMAClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.gdevxy.blog.client.contentful; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import com.gdevxy.blog.client.contentful.model.PageBlogModel; | ||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(configKey = "contentful-cma") | ||
public interface ContentfulCMAClient { | ||
|
||
@GET | ||
@Retry(maxRetries = 2) | ||
@Path("/content_types/pageBlogPost") | ||
PageBlogModel findPageBlogModel(); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
client/src/main/java/com/gdevxy/blog/client/contentful/model/PageBlogModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.gdevxy.blog.client.contentful.model; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@ToString | ||
public class PageBlogModel { | ||
|
||
@Builder.Default | ||
private final List<Field> fields = List.of(); | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@ToString | ||
public static class Field { | ||
|
||
private final String id; | ||
private final Items items; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@ToString | ||
public static class Items { | ||
|
||
private final List<Validation> validations; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@ToString | ||
public static class Validation { | ||
|
||
@Builder.Default | ||
private List<String> in = List.of(); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
client/src/test/java/com/gdevxy/blog/client/contentful/ContentfulCMAClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.gdevxy.blog.client.contentful; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import com.gdevxy.blog.client.contentful.model.PageBlogModel; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import io.quarkiverse.wiremock.devservice.ConnectWireMock; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@QuarkusTest | ||
@ConnectWireMock | ||
class ContentfulCMAClientTest { | ||
|
||
private WireMock wiremock; | ||
|
||
@RestClient | ||
ContentfulCMAClient client; | ||
|
||
@Test | ||
void findPageBlogModel() { | ||
// given | ||
wiremock.register(get(urlPathEqualTo("/content_types/pageBlogPost")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer CMA_TOKEN")) | ||
.willReturn(ok().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBodyFile("find-page-blog-model.json"))); | ||
|
||
// when | ||
var actual = client.findPageBlogModel(); | ||
|
||
// then | ||
assertThat(actual.getFields()).usingRecursiveFieldByFieldElementComparator() | ||
.contains(PageBlogModel.Field.builder() | ||
.id("tags") | ||
.items(PageBlogModel.Field.Items.builder() | ||
.validations(List.of(PageBlogModel.Field.Items.Validation.builder().in(List.of("About Me", "Agile")).build())) | ||
.build()) | ||
.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.