Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resteasy-reactive #7

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '17', '21' ]
java: [ '21' ]
name: Build with Java ${{ matrix.Java }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
Expand Down
8 changes: 8 additions & 0 deletions _idea/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions _idea/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions _idea/.idea/runConfigurations/all__rewrite_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions code-first-openapi-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@

<!-- The Java release (the 'de facto' Java major version number, e.g. 8 for Java 1.8, and 9 for Java 9), -->
<!-- supported in the compiler plugin as `<release>` for JDK 9 and later, see also JEP223 -->
<java.release>17</java.release>
<java.release>21</java.release>

<!-- artifact versions -->
<lombok.version>1.18.30</lombok.version>
<quarkus.version>3.5.0</quarkus.version>
<lombok.version>1.18.32</lombok.version>
<quarkus.version>3.8.3</quarkus.version>

<!-- testing artifact versions -->
<hamcrest.version>2.2</hamcrest.version>
<json.unit.version>3.2.2</json.unit.version>
<json.unit.version>3.2.7</json.unit.version>

<!-- apache maven plugin versions (in alphabetical order) -->
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.2.1</maven.surefire.plugin.version>
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>
</properties>

<dependencyManagement>
Expand All @@ -43,9 +43,17 @@

<dependencies>
<!-- Jakarta EE and MP dependencies -->
<dependency>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
<artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -77,12 +85,6 @@
<artifactId>rest-assured</artifactId>
<!-- rest-assured.version managed by quarkus -->
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package ch.schlau.pesche.apidocs.openapi.codefirst.rest;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Instance;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;

import ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model.PanJsonAdapter;
import lombok.experimental.UtilityClass;
import io.quarkus.jsonb.JsonbConfigCustomizer;

@UtilityClass
public class JsonConfiguration {

public static final JsonbConfig JSON_CONFIG = new JsonbConfig()
public static JsonbConfig createJsonbConfig() {
return new JsonbConfig()
.withAdapters(new PanJsonAdapter())
;
}

public static final Jsonb JSONB = JsonbBuilder.create(JSON_CONFIG);
public static Jsonb createJsonb() {
return JsonbBuilder.create(createJsonbConfig());
}

// Replaces the CDI producer for JsonbConfig built into Quarkus
@Dependent
JsonbConfig jsonConfig(Instance<JsonbConfigCustomizer> customizers) {
JsonbConfig config = createJsonbConfig();

// Apply all JsonbConfigCustomizer beans (incl. Quarkus)
for (JsonbConfigCustomizer customizer : customizers) {
customizer.customize(config);
}

return config;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ void pincheck_ok() {
// @formatter:off
given()
.header("Content-Type", MediaType.APPLICATION_JSON)
.body("{\"uuid\": \"aaaaaaaa-bbbb-cccc-dddd-012345678901\", \"pinBlock\": \"magic\"}")
.body("""
{
"uuid": "aaaaaaaa-bbbb-cccc-dddd-012345678901",
"pinBlock": "magic"
}
""")
.when()
.post("/api/txproc/pincheck")
.then()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ void purchase_ok() {
// @formatter:off
given()
.header("Content-Type", MediaType.APPLICATION_JSON)
.body("{\"uuid\": \"aaaaaaaa-bbbb-cccc-dddd-012345678901\","
+" \"pan\": \"4244333322221111\","
+" \"emvTags\": { \"84\": \"A0000000041010\", \"x9F1A\": \"250\" } }")
.body("""
{
"uuid": "aaaaaaaa-bbbb-cccc-dddd-012345678901",
"pan": "4244333322221111",
"emvTags": { "84": "A0000000041010", "x9F1A": "250" }
}
""")
.when()
.post("/api/txproc/purchase")
.then()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package ch.schlau.pesche.apidocs.openapi.codefirst.txproc;

import static ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration.JSONB;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.UUID;

import jakarta.json.bind.Jsonb;

import org.junit.jupiter.api.Test;

import ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration;
import ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model.Pan;

class PinCheckRequestTest {

@Test
void json_roundtrip() {

Jsonb jsonb = JsonConfiguration.createJsonb();

PinCheckRequest request = new PinCheckRequest();
request.setUuid(UUID.fromString("abcdabcd-1234-5678-aaaa-cccccccccccc"));

// JSON serialization
String jsonString1 = JSONB.toJson(request);
String jsonString1 = jsonb.toJson(request);
assertThat(jsonString1, is("{\"uuid\":\"abcdabcd-1234-5678-aaaa-cccccccccccc\"}"));

// set the other properties as well
request.setPan(new Pan("111222333444"));
request.setPinBlock("-secret-");
String jsonString2 = JSONB.toJson(request);
String jsonString2 = jsonb.toJson(request);
assertThat(jsonString2, is("{\"pan\":\"111222333444\",\"pinBlock\":\"-secret-\",\"uuid\":\"abcdabcd-1234-5678-aaaa-cccccccccccc\"}"));

// JSON deserialization
PinCheckRequest roundtrip = JSONB.fromJson(jsonString2, PinCheckRequest.class);
PinCheckRequest roundtrip = jsonb.fromJson(jsonString2, PinCheckRequest.class);
assertThat(roundtrip.getUuid().toString(), is("abcdabcd-1234-5678-aaaa-cccccccccccc"));
assertThat(roundtrip.getPan().getPan(), is("111222333444"));
assertThat(roundtrip.getPinBlock(), is("-secret-"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ch.schlau.pesche.apidocs.openapi.codefirst.txproc;

import static ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration.JSONB;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.UUID;

import jakarta.json.bind.Jsonb;

import org.junit.jupiter.api.Test;

import ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration;
import ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model.EmvTags;
import ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model.Pan;

Expand All @@ -16,6 +18,8 @@ class PurchaseAuthRequestTest {
@Test
void json_roundtrip() {

Jsonb jsonb = JsonConfiguration.createJsonb();

PurchaseAuthRequest request = new PurchaseAuthRequest();
request.setUuid(UUID.fromString("abcdabcd-1234-5678-aaaa-cccccccccccc"));
request.setPan(new Pan("42"));
Expand All @@ -24,11 +28,11 @@ void json_roundtrip() {
request.setEmvTags(emvTags);

// JSON serialization
String jsonString = JSONB.toJson(request);
String jsonString = jsonb.toJson(request);
assertThat(jsonString, is("{\"emvTags\":{\"84\":\"A0000000041010\"},\"pan\":\"42\",\"uuid\":\"abcdabcd-1234-5678-aaaa-cccccccccccc\"}"));

// JSON deserialization
PurchaseAuthRequest roundtrip = JSONB.fromJson(jsonString, PurchaseAuthRequest.class);
PurchaseAuthRequest roundtrip = jsonb.fromJson(jsonString, PurchaseAuthRequest.class);
assertThat(roundtrip.getUuid().toString(), is("abcdabcd-1234-5678-aaaa-cccccccccccc"));
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model;

import static ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration.JSONB;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import jakarta.json.bind.Jsonb;

import org.junit.jupiter.api.Test;

import ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration;

class EmvTagsTest {

@Test
void json_roundtrip() {

Jsonb jsonb = JSONB;
Jsonb jsonb = JsonConfiguration.createJsonb();

EmvTags emv = new EmvTags();
emv.setX84("A0000000043060");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.schlau.pesche.apidocs.openapi.codefirst.txproc.model;

import static ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration.JSONB;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -9,6 +8,8 @@

import org.junit.jupiter.api.Test;

import ch.schlau.pesche.apidocs.openapi.codefirst.rest.JsonConfiguration;

class PanTest {

@Test
Expand All @@ -29,7 +30,7 @@ void asMaskedPan_invalid() {
@Test
void json_roundtrip() {

Jsonb jsonb = JSONB;
Jsonb jsonb = JsonConfiguration.createJsonb();

Pan pan = new Pan("4444333322221111");

Expand Down
Loading