From b2cc225bd7194701caef44ee2970352845603cb4 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Thu, 23 Dec 2021 09:21:49 +0100 Subject: [PATCH] Oracle JDBC extension is now able to handle presence of other JDBC drivers in native Resolved in https://github.com/quarkusio/quarkus/pull/22255 --- pom.xml | 1 - sql-db/sql-app-oracle/pom.xml | 67 ------- .../oracle/ApplicationExceptionMapper.java | 28 --- .../quarkus/ts/sqldb/sqlapp/oracle/Book.java | 17 -- .../ts/sqldb/sqlapp/oracle/BookResource.java | 78 -------- .../oracle/NotFoundExceptionMapper.java | 16 -- .../oracle/ValidationExceptionMapper.java | 36 ---- .../src/main/resources/application.properties | 3 - .../src/main/resources/oracle_import.sql | 7 - .../sqlapp/oracle/AbstractSqlDatabaseIT.java | 179 ------------------ .../oracle/OpenShiftOracleDatabaseIT.java | 10 - .../sqldb/sqlapp/oracle/OracleDatabaseIT.java | 25 --- .../src/test/resources/test.properties | 4 - sql-db/sql-app/pom.xml | 23 +-- .../ts/sqldb/sqlapp/OracleDatabaseIT.java | 3 - 15 files changed, 4 insertions(+), 493 deletions(-) delete mode 100644 sql-db/sql-app-oracle/pom.xml delete mode 100644 sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ApplicationExceptionMapper.java delete mode 100644 sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/Book.java delete mode 100644 sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/BookResource.java delete mode 100644 sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/NotFoundExceptionMapper.java delete mode 100644 sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ValidationExceptionMapper.java delete mode 100644 sql-db/sql-app-oracle/src/main/resources/application.properties delete mode 100644 sql-db/sql-app-oracle/src/main/resources/oracle_import.sql delete mode 100644 sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/AbstractSqlDatabaseIT.java delete mode 100644 sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OpenShiftOracleDatabaseIT.java delete mode 100644 sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OracleDatabaseIT.java delete mode 100644 sql-db/sql-app-oracle/src/test/resources/test.properties diff --git a/pom.xml b/pom.xml index 555db83be..bda686048 100644 --- a/pom.xml +++ b/pom.xml @@ -454,7 +454,6 @@ sql-db/hibernate sql-db/sql-app - sql-db/sql-app-oracle sql-db/multiple-pus sql-db/panache-flyway sql-db/vertx-sql diff --git a/sql-db/sql-app-oracle/pom.xml b/sql-db/sql-app-oracle/pom.xml deleted file mode 100644 index ea14049e5..000000000 --- a/sql-db/sql-app-oracle/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - 4.0.0 - - io.quarkus.ts.qe - parent - 1.0.0-SNAPSHOT - ../.. - - sqldb-sqlapp-oracle - jar - Quarkus QE TS: SQL Database: Oracle Application - - - io.quarkus - quarkus-hibernate-orm-panache - - - io.quarkus - quarkus-hibernate-validator - - - io.quarkus - quarkus-resteasy - - - io.quarkus - quarkus-resteasy-jackson - - - io.quarkus - quarkus-jdbc-oracle - - - io.quarkus.qe - quarkus-test-service-database - test - - - - - - skip-tests-on-windows - - - windows - - - - - - maven-surefire-plugin - - true - - - - maven-failsafe-plugin - - true - - - - - - - diff --git a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ApplicationExceptionMapper.java b/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ApplicationExceptionMapper.java deleted file mode 100644 index e9c9db3fb..000000000 --- a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ApplicationExceptionMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import com.fasterxml.jackson.databind.ObjectMapper; - -@Provider -public class ApplicationExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(Exception exception) { - int code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); - if (exception instanceof WebApplicationException) { - code = ((WebApplicationException) exception).getResponse().getStatus(); - } - - return Response.status(code) - .type(MediaType.APPLICATION_JSON) - .entity(new ObjectMapper().createObjectNode() - .put("code", code) - .put("error", exception.getMessage()) - .toString()) - .build(); - } -} diff --git a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/Book.java b/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/Book.java deleted file mode 100644 index 64da8d8b0..000000000 --- a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/Book.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.validation.constraints.NotBlank; - -import io.quarkus.hibernate.orm.panache.PanacheEntity; - -@Entity -@Table(name = "book") -public class Book extends PanacheEntity { - @NotBlank(message = "book title must be set") - public String title; - - @NotBlank(message = "book author must be set") - public String author; -} diff --git a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/BookResource.java b/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/BookResource.java deleted file mode 100644 index 917a9754b..000000000 --- a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/BookResource.java +++ /dev/null @@ -1,78 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import java.util.List; - -import javax.transaction.Transactional; -import javax.validation.Valid; -import javax.ws.rs.ClientErrorException; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.NotFoundException; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import io.quarkus.panache.common.Sort; - -@Path("/book") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class BookResource { - - @GET - public List getAll() { - return Book.listAll(Sort.by("title")); - } - - @GET - @Path("/{id}") - public Book get(@PathParam("id") Long id) { - Book book = Book.findById(id); - if (book == null) { - throw new NotFoundException("book '" + id + "' not found"); - } - return book; - } - - @POST - @Transactional - public Response create(@Valid Book book) { - if (book.id != null) { - throw new ClientErrorException("unexpected ID in request", ValidationExceptionMapper.UNPROCESSABLE_ENTITY); - } - - book.persist(); - return Response.ok(book).status(Response.Status.CREATED).build(); - } - - @PUT - @Path("/{id}") - @Transactional - public Book update(@PathParam("id") Long id, @Valid Book newBook) { - Book book = Book.findById(id); - if (book == null) { - throw new NotFoundException("book '" + id + "' not found"); - } - - book.title = newBook.title; - book.author = newBook.author; - return book; - } - - @DELETE - @Path("/{id}") - @Transactional - public Response delete(@PathParam("id") Long id) { - Book book = Book.findById(id); - if (book == null) { - throw new NotFoundException("book '" + id + "' not found"); - } - book.delete(); - return Response.noContent().build(); - } -} diff --git a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/NotFoundExceptionMapper.java b/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/NotFoundExceptionMapper.java deleted file mode 100644 index 3b026fdc8..000000000 --- a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/NotFoundExceptionMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import javax.ws.rs.NotFoundException; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -// workaround for Quarkus providing its own NotFoundExceptionMapper -// which is more specific than our ApplicationExceptionMapper -@Provider -public class NotFoundExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(NotFoundException exception) { - return new ApplicationExceptionMapper().toResponse(exception); - } -} diff --git a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ValidationExceptionMapper.java b/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ValidationExceptionMapper.java deleted file mode 100644 index d2530cbaa..000000000 --- a/sql-db/sql-app-oracle/src/main/java/io/quarkus/ts/sqldb/sqlapp/oracle/ValidationExceptionMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; - -@Provider -public class ValidationExceptionMapper implements ExceptionMapper { - - public static final int UNPROCESSABLE_ENTITY = 422; - - @Override - public Response toResponse(ConstraintViolationException exception) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode errors = mapper.createArrayNode(); - - for (ConstraintViolation constraintViolation : exception.getConstraintViolations()) { - errors.addObject() - .put("path", constraintViolation.getPropertyPath().toString()) - .put("message", constraintViolation.getMessage()); - } - - return Response.status(UNPROCESSABLE_ENTITY) - .type(MediaType.APPLICATION_JSON) - .entity(mapper.createObjectNode() - .put("code", UNPROCESSABLE_ENTITY) - .set("error", errors)) - .build(); - } -} diff --git a/sql-db/sql-app-oracle/src/main/resources/application.properties b/sql-db/sql-app-oracle/src/main/resources/application.properties deleted file mode 100644 index ba1b853b1..000000000 --- a/sql-db/sql-app-oracle/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -quarkus.datasource.db-kind=oracle -quarkus.hibernate-orm.sql-load-script=oracle_import.sql -quarkus.hibernate-orm.database.generation=create diff --git a/sql-db/sql-app-oracle/src/main/resources/oracle_import.sql b/sql-db/sql-app-oracle/src/main/resources/oracle_import.sql deleted file mode 100644 index 3e89f794e..000000000 --- a/sql-db/sql-app-oracle/src/main/resources/oracle_import.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Foundation', 'Isaac Asimov'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Ender''s Game', 'Orson Scott Card'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Hyperion', 'Dan Simmons'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Anathem', 'Neal Stephenson'); -INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Perdido Street Station', 'China MiƩville'); diff --git a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/AbstractSqlDatabaseIT.java b/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/AbstractSqlDatabaseIT.java deleted file mode 100644 index db3cf4982..000000000 --- a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/AbstractSqlDatabaseIT.java +++ /dev/null @@ -1,179 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; - -import org.apache.http.HttpStatus; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -import io.restassured.http.ContentType; - -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public abstract class AbstractSqlDatabaseIT { - - private static final int EXPECTED_SIZE = 7; - - private static final int VALID_ID = 8; - private static final int INVALID_ID = 999; - - @Test - @Order(1) - public void getAll() { - given() - .get("/book") - .then() - .statusCode(HttpStatus.SC_OK) - .body("", hasSize(EXPECTED_SIZE)); - } - - @Test - @Order(2) - public void get() { - given() - .get("/book/7") - .then() - .statusCode(HttpStatus.SC_OK) - .body("title", equalTo("Perdido Street Station")) - .body("author", equalTo("China MiƩville")); - } - - @Test - @Order(3) - public void getWithUnknownId() { - given() - .get("/book/" + INVALID_ID) - .then() - .statusCode(HttpStatus.SC_NOT_FOUND) - .body("code", equalTo(HttpStatus.SC_NOT_FOUND)) - .body("error", equalTo(String.format("book '%d' not found", INVALID_ID))); - } - - @Test - @Order(4) - public void create() { - Book book = new Book(); - book.title = "Neuromancer"; - book.author = "William Gibson"; - - given() - .contentType(ContentType.JSON) - .body(book) - .post("/book") - .then() - .statusCode(HttpStatus.SC_CREATED) - .body("id", equalTo(VALID_ID)) - .body("title", equalTo(book.title)) - .body("author", equalTo(book.author)); - - given() - .get("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_OK) - .body("title", equalTo(book.title)) - .body("author", equalTo(book.author)); - } - - @Test - @Order(5) - public void createInvalidPayload() { - given() - .contentType(ContentType.TEXT) - .body("") - .post("/book") - .then() - .statusCode(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE) - .body("code", equalTo(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE)); - } - - @Test - @Order(6) - public void createBadPayload() { - Book book = new Book(); - book.id = Long.valueOf(INVALID_ID); - book.title = "foo"; - book.author = "bar"; - - given() - .contentType(ContentType.JSON) - .body(book) - .post("/book") - .then() - .statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY) - .body("code", equalTo(HttpStatus.SC_UNPROCESSABLE_ENTITY)) - .body("error", equalTo("unexpected ID in request")); - } - - @Test - @Order(7) - public void update() { - Book book = new Book(); - book.id = Long.valueOf(VALID_ID); - book.title = "Schismatrix"; - book.author = "Bruce Sterling"; - - given() - .contentType(ContentType.JSON) - .body(book) - .put("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_OK) - .body("id", equalTo(VALID_ID)) - .body("title", equalTo(book.title)) - .body("author", equalTo(book.author)); - - given() - .get("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_OK) - .body("title", equalTo(book.title)) - .body("author", equalTo(book.author)); - } - - @Test - @Order(8) - public void updateInvalidPayload() { - given() - .contentType(ContentType.TEXT) - .body("") - .put("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE) - .body("code", equalTo(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE)); - } - - @Test - @Order(9) - public void updateBadPayload() { - Book book = new Book(); - - given() - .contentType(ContentType.JSON) - .body(book) - .put("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY) - .body("code", equalTo(HttpStatus.SC_UNPROCESSABLE_ENTITY)) - .body("error.message", containsInAnyOrder("book title must be set", "book author must be set")); - } - - @Test - @Order(10) - public void delete() { - given() - .delete("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_NO_CONTENT); - - given() - .get("/book/" + VALID_ID) - .then() - .statusCode(HttpStatus.SC_NOT_FOUND) - .body("code", equalTo(HttpStatus.SC_NOT_FOUND)) - .body("error", equalTo(String.format("book '%d' not found", VALID_ID))); - } -} diff --git a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OpenShiftOracleDatabaseIT.java b/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OpenShiftOracleDatabaseIT.java deleted file mode 100644 index 17865c016..000000000 --- a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OpenShiftOracleDatabaseIT.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import org.junit.jupiter.api.Disabled; - -import io.quarkus.test.scenarios.OpenShiftScenario; - -@Disabled("https://github.com/quarkus-qe/quarkus-test-suite/issues/246") -@OpenShiftScenario -public class OpenShiftOracleDatabaseIT extends OracleDatabaseIT { -} diff --git a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OracleDatabaseIT.java b/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OracleDatabaseIT.java deleted file mode 100644 index f35297fd9..000000000 --- a/sql-db/sql-app-oracle/src/test/java/io/quarkus/ts/sqldb/sqlapp/oracle/OracleDatabaseIT.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.quarkus.ts.sqldb.sqlapp.oracle; - -import org.junit.jupiter.api.Tag; - -import io.quarkus.test.bootstrap.OracleService; -import io.quarkus.test.bootstrap.RestService; -import io.quarkus.test.scenarios.QuarkusScenario; -import io.quarkus.test.services.Container; -import io.quarkus.test.services.QuarkusApplication; - -@Tag("QUARKUS-1164") -@QuarkusScenario -public class OracleDatabaseIT extends AbstractSqlDatabaseIT { - - static final int ORACLE_PORT = 1521; - - @Container(image = "${oracle.image}", port = ORACLE_PORT, expectedLog = "DATABASE IS READY TO USE!") - static OracleService database = new OracleService(); - - @QuarkusApplication - static RestService app = new RestService() - .withProperty("quarkus.datasource.username", database.getUser()) - .withProperty("quarkus.datasource.password", database.getPassword()) - .withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl); -} diff --git a/sql-db/sql-app-oracle/src/test/resources/test.properties b/sql-db/sql-app-oracle/src/test/resources/test.properties deleted file mode 100644 index c17f8458b..000000000 --- a/sql-db/sql-app-oracle/src/test/resources/test.properties +++ /dev/null @@ -1,4 +0,0 @@ -ts.app.log.enable=true -ts.database.log.enable=true -ts.database.container.delete.image.on.stop=true -ts.database.openshift.use-internal-service-as-url=true diff --git a/sql-db/sql-app/pom.xml b/sql-db/sql-app/pom.xml index fadff9c11..f9505afad 100644 --- a/sql-db/sql-app/pom.xml +++ b/sql-db/sql-app/pom.xml @@ -47,6 +47,10 @@ io.quarkus quarkus-jdbc-postgresql + + io.quarkus + quarkus-jdbc-oracle + io.quarkus.qe quarkus-test-service-database @@ -54,25 +58,6 @@ - - - default - - true - - - - io.quarkus - quarkus-jdbc-oracle - - - native diff --git a/sql-db/sql-app/src/test/java/io/quarkus/ts/sqldb/sqlapp/OracleDatabaseIT.java b/sql-db/sql-app/src/test/java/io/quarkus/ts/sqldb/sqlapp/OracleDatabaseIT.java index d6ac10763..c100c2b0e 100644 --- a/sql-db/sql-app/src/test/java/io/quarkus/ts/sqldb/sqlapp/OracleDatabaseIT.java +++ b/sql-db/sql-app/src/test/java/io/quarkus/ts/sqldb/sqlapp/OracleDatabaseIT.java @@ -3,12 +3,9 @@ import io.quarkus.test.bootstrap.OracleService; import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.scenarios.QuarkusScenario; -import io.quarkus.test.scenarios.annotations.DisabledOnNative; import io.quarkus.test.services.Container; import io.quarkus.test.services.QuarkusApplication; -// TODO: https://github.com/quarkusio/quarkus/issues/22476, see related info in pom.xml (sqldb-sqlapp) -@DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/22476") @QuarkusScenario public class OracleDatabaseIT extends AbstractSqlDatabaseIT {