-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DataMapping for creating bean from JsonObject
- Loading branch information
Showing
11 changed files
with
247 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
3 changes: 2 additions & 1 deletion
3
...se/roq/data/deployment/JsonConverter.java → .../deployment/converters/JsonConverter.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
4 changes: 3 additions & 1 deletion
4
.../data/deployment/JsonObjectConverter.java → ...yment/converters/JsonObjectConverter.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
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
28 changes: 28 additions & 0 deletions
28
...yment/src/main/java/io/quarkiverse/roq/data/deployment/items/RoqDataMappingBuildItem.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,28 @@ | ||
package io.quarkiverse.roq.data.deployment.items; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class RoqDataMappingBuildItem extends MultiBuildItem { | ||
|
||
private final String name; | ||
private final String className; | ||
private final Object jsonObject; | ||
|
||
public RoqDataMappingBuildItem(String name, String className, Object jsonObject) { | ||
this.name = name; | ||
this.className = className; | ||
this.jsonObject = jsonObject; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public Object getJsonObject() { | ||
return this.jsonObject; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../deployment/src/test/java/io/quarkiverse/roq/data/test/RoqDataBindingEnforceBeanTest.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,50 @@ | ||
package io.quarkiverse.roq.data.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.roq.data.test.util.Foo; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class RoqDataBindingEnforceBeanTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest quarkusUnitTest = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(Foo.class) | ||
.add(new StringAsset("quarkus.roq.site-dir=src/test/site\nquarkus.roq.data.enforce-bean=true"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void foo() { | ||
RestAssured.given() | ||
.get("/bar") | ||
.then() | ||
.statusCode(200) | ||
.body(Matchers.equalTo("Super Heroes from Yaml")); | ||
} | ||
|
||
@ApplicationScoped | ||
@Path("/bar") | ||
public static class PersonResource { | ||
|
||
@Inject | ||
@Named("bar") | ||
JsonObject bar; | ||
|
||
@GET | ||
public String getFoo() { | ||
return bar.getString("name"); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
roq-data/deployment/src/test/java/io/quarkiverse/roq/data/test/RoqDataBindingTest.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,47 @@ | ||
package io.quarkiverse.roq.data.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.roq.data.test.util.Foo; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class RoqDataBindingTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest quarkusUnitTest = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(Foo.class) | ||
.add(new StringAsset("quarkus.roq.site-dir=src/test/site"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void foo() { | ||
RestAssured.given() | ||
.get("/foo") | ||
.then() | ||
.statusCode(200) | ||
.body(Matchers.equalTo("Super Heroes from Json")); | ||
} | ||
|
||
@ApplicationScoped | ||
@Path("/foo") | ||
public static class PersonResource { | ||
|
||
@Inject | ||
Foo foo; | ||
|
||
@GET | ||
public String getFoo() { | ||
return foo.toString(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
roq-data/deployment/src/test/java/io/quarkiverse/roq/data/test/util/Foo.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,12 @@ | ||
package io.quarkiverse.roq.data.test.util; | ||
|
||
import io.quarkiverse.roq.data.runtime.annotations.DataMapping; | ||
|
||
@DataMapping("foo") | ||
public record Foo(String name) { | ||
@Override | ||
public String toString() { | ||
// Original is Foo[name=Super Heroes from Json] | ||
return this.name; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
roq-data/runtime/src/main/java/io/quarkiverse/roq/data/runtime/annotations/DataMapping.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,17 @@ | ||
package io.quarkiverse.roq.data.runtime.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation used to indicate that a class is a data mapping. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE }) | ||
@Documented | ||
public @interface DataMapping { | ||
String value(); | ||
} |