From 7d77913c5aa1080bb3ecb71a43d7cc36a3ebc79c Mon Sep 17 00:00:00 2001 From: Fedor Dudinsky Date: Mon, 6 May 2024 11:50:46 +0200 Subject: [PATCH] Minimal reporucer for https://github.com/quarkusio/quarkus/issues/40425 --- pom.xml | 249 +++++++-------- .../java/eu/fedinskiy/GreetingResource.java | 16 - .../java/org/acme/getting/started/Book.java | 70 +++++ .../acme/getting/started/TestResource.java | 31 ++ .../resources/META-INF/resources/index.html | 284 ------------------ src/main/resources/application.properties | 13 +- src/main/resources/postgres_import.sql | 11 + .../java/eu/fedinskiy/GreetingResourceIT.java | 8 - .../eu/fedinskiy/GreetingResourceTest.java | 21 -- .../acme/getting/started/ResourceTest.java | 29 ++ 10 files changed, 277 insertions(+), 455 deletions(-) delete mode 100644 src/main/java/eu/fedinskiy/GreetingResource.java create mode 100644 src/main/java/org/acme/getting/started/Book.java create mode 100644 src/main/java/org/acme/getting/started/TestResource.java delete mode 100644 src/main/resources/META-INF/resources/index.html create mode 100644 src/main/resources/postgres_import.sql delete mode 100644 src/test/java/eu/fedinskiy/GreetingResourceIT.java delete mode 100644 src/test/java/eu/fedinskiy/GreetingResourceTest.java create mode 100644 src/test/java/org/acme/getting/started/ResourceTest.java diff --git a/pom.xml b/pom.xml index dd5b3e6..1d20ef2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,125 +1,130 @@ - - - 4.0.0 - eu.fedinskiy - openshift-quickstart - 1.0.0-SNAPSHOT - - 3.10.1 - 17 - UTF-8 - UTF-8 - quarkus-bom - io.quarkus.platform - 3.9.1 - true - 3.0.0-M7 - - + + + 4.0.0 + + org.acme + getting-started + 1.0.0-SNAPSHOT + + + quarkus-bom + io.quarkus + 999-SNAPSHOT + 3.11.0 + 3.1.2 + UTF-8 + 17 + 17 + true + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + - - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} - pom - import - + + io.quarkus + quarkus-rest-jackson + + + io.quarkus + quarkus-hibernate-validator + + + io.quarkus + quarkus-hibernate-reactive-panache + + + io.quarkus + quarkus-reactive-pg-client + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + - - - - io.quarkus - quarkus-resteasy-reactive - - - io.quarkus - quarkus-openshift - - - io.quarkus - quarkus-smallrye-health - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - - - - ${quarkus.platform.group-id} - quarkus-maven-plugin - ${quarkus.platform.version} - true - - - - build - generate-code - generate-code-tests - - - - - - maven-compiler-plugin - ${compiler-plugin.version} - - - -parameters - - - - - maven-surefire-plugin - ${surefire-plugin.version} - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - maven-failsafe-plugin - ${surefire-plugin.version} - - - - integration-test - verify - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - - - native - - - native - - - - false - native - - - + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + + + + build + + + + + + + + + + + native + + + native + + + + native + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + diff --git a/src/main/java/eu/fedinskiy/GreetingResource.java b/src/main/java/eu/fedinskiy/GreetingResource.java deleted file mode 100644 index bea71cd..0000000 --- a/src/main/java/eu/fedinskiy/GreetingResource.java +++ /dev/null @@ -1,16 +0,0 @@ -package eu.fedinskiy; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -@Path("/hello") -public class GreetingResource { - - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "Hello from RESTEasy Reactive"; - } -} \ No newline at end of file diff --git a/src/main/java/org/acme/getting/started/Book.java b/src/main/java/org/acme/getting/started/Book.java new file mode 100644 index 0000000..6c27d08 --- /dev/null +++ b/src/main/java/org/acme/getting/started/Book.java @@ -0,0 +1,70 @@ +package org.acme.getting.started; + +import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.NamedQuery; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; + +@Entity +@Table(name = "books") +@NamedQuery(name = "find_by_title_prefix", query = "from Book where title like :prefix") +public class Book extends PanacheEntityBase { + private static final int MAX_TITLE_LENGTH = 100; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true, nullable = false) + private Integer id; + + @NotNull + @Size(max = MAX_TITLE_LENGTH) + private String title; + + @NotNull + private Integer author; + + public Book() { + } + + public Book(String title) { + this.title = title; + } + + public static Multi all() { + return Book. listAll().toMulti().flatMap(l -> Multi.createFrom().items(l.stream())); + } + + public static Uni byId(Integer id) { + return findById(id); + } + + public static Uni create(Integer author, String name) { + Book book = new Book(name); + book.setAuthor(author); + return book.persistAndFlush(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setAuthor(Integer author) { + this.author = author; + } + + public Integer getId() { + return id; + } +} diff --git a/src/main/java/org/acme/getting/started/TestResource.java b/src/main/java/org/acme/getting/started/TestResource.java new file mode 100644 index 0000000..7f6528a --- /dev/null +++ b/src/main/java/org/acme/getting/started/TestResource.java @@ -0,0 +1,31 @@ +package org.acme.getting.started; + +import io.quarkus.hibernate.reactive.panache.Panache; +import io.smallrye.mutiny.Uni; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; + +@Path("/library") +public class TestResource { + + @PUT + @Path("book/{author}/{name}") + public Uni createBook(Integer author, String name) { + return Panache.withTransaction(() -> Book.create(author, name)) + .map(book -> Response.status(Response.Status.CREATED).entity(book.getId())) + .onFailure().recoverWithItem(error -> Response.status(Response.Status.BAD_REQUEST).entity(error.getMessage())) + .map(Response.ResponseBuilder::build); + } + + @GET + @Path("book/{id}") + public Uni find(Integer id) { + return Book.byId(id) + .map(book -> book == null + ? Response.status(Response.Status.NOT_FOUND) + : Response.ok(book.getTitle())) + .map(Response.ResponseBuilder::build); + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/index.html b/src/main/resources/META-INF/resources/index.html deleted file mode 100644 index dc6dc7a..0000000 --- a/src/main/resources/META-INF/resources/index.html +++ /dev/null @@ -1,284 +0,0 @@ - - - - - openshift-quickstart - 1.0.0-SNAPSHOT - - - -
-
-
- - - - - quarkus_logo_horizontal_rgb_1280px_reverse - - - - - - - - - - - - - - - - - - -
-
-
- -
-
-
-

You just made a Quarkus application.

-

This page is served by Quarkus.

- Visit the Dev UI -

This page: src/main/resources/META-INF/resources/index.html

-

App configuration: src/main/resources/application.properties

-

Static assets: src/main/resources/META-INF/resources/

-

Code: src/main/java

-

Generated starter code:

-
    -
  • - RESTEasy Reactive Easily start your Reactive RESTful Web Services -
    @Path: /hello -
    Related guide -
  • - -
-
-
-

Selected extensions

-
    -
  • RESTEasy Reactive (guide)
  • -
  • OpenShift (guide)
  • -
-
Documentation
-

Practical step-by-step guides to help you achieve a specific goal. Use them to help get your work - done.

-
Set up your IDE
-

Everyone has a favorite IDE they like to use to code. Learn how to configure yours to maximize your - Quarkus productivity.

-
-
-
- - diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4783bc4..0b88726 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,9 @@ -quarkus.management.enabled=true -quarkus.kubernetes.deploy=true -quarkus.openshift.route.expose=true -quarkus.kubernetes-client.trust-certs=true \ No newline at end of file +quarkus.hibernate-orm.database.charset=utf-8 +quarkus.hibernate-orm.database.generation=drop-and-create +quarkus.datasource.db-kind=postgresql + +quarkus.datasource.devservices.image-name=docker.io/library/postgres:16.1 +quarkus.datasource.devservices.username=quarkus_test +quarkus.datasource.devservices.password=quarkus_test +quarkus.datasource.devservices.db-name=quarkus_test +quarkus.hibernate-orm.sql-load-script=postgres_import.sql \ No newline at end of file diff --git a/src/main/resources/postgres_import.sql b/src/main/resources/postgres_import.sql new file mode 100644 index 0000000..0f38b46 --- /dev/null +++ b/src/main/resources/postgres_import.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS authors CASCADE; +CREATE TABLE authors(id SERIAL PRIMARY KEY, name TEXT NOT NULL); +INSERT INTO authors(id,name) VALUES (1, 'Homer'); +INSERT INTO authors(id,name) VALUES (2, 'Vern'); +INSERT INTO authors(id,name) VALUES (3, 'Dlugi'); +INSERT INTO authors(id,name) VALUES (4, 'Kahneman'); +DROP TABLE IF EXISTS books CASCADE; +CREATE TABLE books(id SERIAL PRIMARY KEY, author int references authors(id) , title TEXT NOT NULL); +INSERT INTO books(author, title) VALUES (3, 'SlovnĂ­k'); +INSERT INTO books(author, title) VALUES (4, 'Thinking fast and slow'); +INSERT INTO books(author, title) VALUES (4, 'Attention and Effort'); diff --git a/src/test/java/eu/fedinskiy/GreetingResourceIT.java b/src/test/java/eu/fedinskiy/GreetingResourceIT.java deleted file mode 100644 index f1adf71..0000000 --- a/src/test/java/eu/fedinskiy/GreetingResourceIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package eu.fedinskiy; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class GreetingResourceIT extends GreetingResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/test/java/eu/fedinskiy/GreetingResourceTest.java b/src/test/java/eu/fedinskiy/GreetingResourceTest.java deleted file mode 100644 index 37f1af5..0000000 --- a/src/test/java/eu/fedinskiy/GreetingResourceTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.fedinskiy; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; - -@QuarkusTest -public class GreetingResourceTest { - - @Test - public void testHelloEndpoint() { - given() - .when().get("/hello") - .then() - .statusCode(200) - .body(is("Hello from RESTEasy Reactive")); - } - -} \ No newline at end of file diff --git a/src/test/java/org/acme/getting/started/ResourceTest.java b/src/test/java/org/acme/getting/started/ResourceTest.java new file mode 100644 index 0000000..b912c0e --- /dev/null +++ b/src/test/java/org/acme/getting/started/ResourceTest.java @@ -0,0 +1,29 @@ +package org.acme.getting.started; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasItem; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.restassured.response.Response; +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class ResourceTest { + + @Test + public void testGreetingEndpoint() { + Response creation=given().put("library/book/2/Around_the_World_in_Eighty_Days"); + assertEquals(HttpStatus.SC_CREATED, creation.statusCode()); + assertEquals("4", creation.getBody().asString()); + + Response response = given() + .when().get("library/book/4"); + assertEquals(HttpStatus.SC_OK, response.statusCode()); + assertEquals("Around_the_World_in_Eighty_Days", response.getBody().asString()); + } + +}