From 92ef0e8d03a5607426966c6a6b296674d374d9f6 Mon Sep 17 00:00:00 2001 From: cristhiank Date: Tue, 9 Apr 2019 19:04:08 -0500 Subject: [PATCH] Moved everything to java and new bug with kotlin https://github.com/quarkusio/quarkus/issues/1969 --- .gitignore | 8 ++++ README.md | 9 ++-- pom.xml | 41 ++++++++-------- .../java/org/acme/rest/GreetingResource.java | 30 ++++++++++++ .../java/org/acme/rest/GreetingService.java | 40 ++++++++++++++++ src/main/java/org/acme/rest/OtherService.java | 22 +++++++++ .../panache/EntityRepositoryEndpoint.java | 27 +++++++++++ .../org/acme/rest/panache/TestEntity.java | 14 ++++++ .../rest/panache/TestEntityRepository.java | 14 ++++++ .../kotlin/org/acme/rest/GreetingResource.kt | 26 ---------- .../kotlin/org/acme/rest/GreetingService.kt | 37 --------------- src/main/kotlin/org/acme/rest/OtherService.kt | 23 --------- src/main/resources/application.properties | 3 +- .../org/acme/rest/GreetingResourceTest.java | 45 ++++++++++++++++++ .../acme/rest/NativeGreetingResourceIT.java | 8 ++++ .../acme/rest/PanacheResourceKotlinTest.kt | 25 ++++++++++ .../org/acme/rest/PanacheResourceTest.java | 47 +++++++++++++++++++ .../org/acme/rest/GreetingResourceTest.kt | 42 ----------------- .../org/acme/rest/NativeGreetingResourceIT.kt | 6 --- 19 files changed, 308 insertions(+), 159 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/org/acme/rest/GreetingResource.java create mode 100644 src/main/java/org/acme/rest/GreetingService.java create mode 100644 src/main/java/org/acme/rest/OtherService.java create mode 100644 src/main/java/org/acme/rest/panache/EntityRepositoryEndpoint.java create mode 100644 src/main/java/org/acme/rest/panache/TestEntity.java create mode 100644 src/main/java/org/acme/rest/panache/TestEntityRepository.java delete mode 100644 src/main/kotlin/org/acme/rest/GreetingResource.kt delete mode 100644 src/main/kotlin/org/acme/rest/GreetingService.kt delete mode 100644 src/main/kotlin/org/acme/rest/OtherService.kt create mode 100644 src/test/java/org/acme/rest/GreetingResourceTest.java create mode 100644 src/test/java/org/acme/rest/NativeGreetingResourceIT.java create mode 100644 src/test/java/org/acme/rest/PanacheResourceKotlinTest.kt create mode 100644 src/test/java/org/acme/rest/PanacheResourceTest.java delete mode 100644 src/test/kotlin/org/acme/rest/GreetingResourceTest.kt delete mode 100644 src/test/kotlin/org/acme/rest/NativeGreetingResourceIT.kt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f93a4f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +target/ +*.iml +.idea/ +.DS_Store +.classpath +.factorypath +.project +.settings/ \ No newline at end of file diff --git a/README.md b/README.md index 2111a3f..8f6403c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ Test project for reported quarkus bugs List: -- https://stackoverflow.com/questions/55233662/how-add-flyway-dependency-and-build-native-image-quarkus-java-lang-classnotfound -- https://github.com/quarkusio/quarkus/issues/1575 -- https://github.com/quarkusio/quarkus/issues/1650 -- https://github.com/quarkusio/quarkus/issues/1828 +- ~~https://stackoverflow.com/questions/55233662/how-add-flyway-dependency-and-build-native-image-quarkus-java-lang-classnotfound~~ +- ~~https://github.com/quarkusio/quarkus/issues/1575 Flyway support~~ +- ~~https://github.com/quarkusio/quarkus/issues/1650 MP-Config Multiple injection~~ +- ~~https://github.com/quarkusio/quarkus/issues/1828 Test instance per class JUnit~~ +- https://github.com/quarkusio/quarkus/issues/1969 Panache repository in Kotlin test diff --git a/pom.xml b/pom.xml index bcd5f66..db72024 100644 --- a/pom.xml +++ b/pom.xml @@ -8,11 +8,10 @@ 1.0-SNAPSHOT 2.22.0 - 1.8 + 11 + 11 1.3.21 - 1.8 - - 0.11.0 + 0.13.1 UTF-8 @@ -33,45 +32,45 @@ io.quarkus - quarkus-arc + quarkus-kotlin org.jetbrains.kotlin kotlin-stdlib-jdk8 + ${kotlin.version} io.quarkus - quarkus-junit5 - - - io.rest-assured - rest-assured - test + quarkus-resteasy-jsonb io.quarkus - quarkus-kotlin + quarkus-arc - - org.flywaydb - flyway-core - 5.2.4 + io.quarkus + quarkus-hibernate-orm-panache com.h2database h2 + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin io.quarkus @@ -125,6 +124,8 @@ + + diff --git a/src/main/java/org/acme/rest/GreetingResource.java b/src/main/java/org/acme/rest/GreetingResource.java new file mode 100644 index 0000000..d80aa81 --- /dev/null +++ b/src/main/java/org/acme/rest/GreetingResource.java @@ -0,0 +1,30 @@ +package org.acme.rest; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/bug") +public class GreetingResource { + + @Inject + GreetingService service; + @Inject + OtherService otherService; + + @GET + @Path("/1575") + @Produces(MediaType.TEXT_PLAIN) + public String helloBug1575() { + return service.helloBug1575(); + } + + @GET + @Path("/1650") + @Produces(MediaType.TEXT_PLAIN) + public String helloBug1650() { + return otherService.helloBug1650(); + } +} \ No newline at end of file diff --git a/src/main/java/org/acme/rest/GreetingService.java b/src/main/java/org/acme/rest/GreetingService.java new file mode 100644 index 0000000..900041d --- /dev/null +++ b/src/main/java/org/acme/rest/GreetingService.java @@ -0,0 +1,40 @@ +package org.acme.rest; + +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.flywaydb.core.Flyway; + +@Dependent +class GreetingService { + + @Inject + @ConfigProperty(name = "quarkus.datasource.url") + String dbURL; + @Inject + @ConfigProperty(name = "quarkus.datasource.username") + String user; + @Inject + @ConfigProperty(name = "quarkus.datasource.password") + String pass; + // INJECTION (repeated) bug #1650 + @Inject + @ConfigProperty(name = "custom.config") + String custom; + + + String helloBug1575() { + var flyway = Flyway.configure() + .dataSource( dbURL, user, pass ) + .baselineOnMigrate( true ) + .load(); + flyway.baseline(); + flyway.migrate(); + return "Hello ITS OK"; + } + + String helloBug1828() { + return "IT WORKS"; + } +} \ No newline at end of file diff --git a/src/main/java/org/acme/rest/OtherService.java b/src/main/java/org/acme/rest/OtherService.java new file mode 100644 index 0000000..05c06d0 --- /dev/null +++ b/src/main/java/org/acme/rest/OtherService.java @@ -0,0 +1,22 @@ +package org.acme.rest; + +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +/** + * @author cristhiank on 2019-03-22 + **/ +@Dependent +class OtherService { + // INJECTION (repeated) bug #1650 + @Inject + @ConfigProperty(name = "custom.config") + String customConfig; + + String helloBug1650() { + System.out.println( "Config=" + customConfig ); + return customConfig; + } +} \ No newline at end of file diff --git a/src/main/java/org/acme/rest/panache/EntityRepositoryEndpoint.java b/src/main/java/org/acme/rest/panache/EntityRepositoryEndpoint.java new file mode 100644 index 0000000..03277f0 --- /dev/null +++ b/src/main/java/org/acme/rest/panache/EntityRepositoryEndpoint.java @@ -0,0 +1,27 @@ +package org.acme.rest.panache; + +import java.util.UUID; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * @author cristhiank on 2019-04-09 + **/ +@Path("/test-entity") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class EntityRepositoryEndpoint { + @Inject + TestEntityRepository repository; + + @GET + @Path("/{id}") + public TestEntity findById(@PathParam("id") UUID id) { + return repository.findById( id ); + } +} \ No newline at end of file diff --git a/src/main/java/org/acme/rest/panache/TestEntity.java b/src/main/java/org/acme/rest/panache/TestEntity.java new file mode 100644 index 0000000..517be88 --- /dev/null +++ b/src/main/java/org/acme/rest/panache/TestEntity.java @@ -0,0 +1,14 @@ +package org.acme.rest.panache; + +import java.util.UUID; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class TestEntity { + @Id + @GeneratedValue + public UUID id; + public String name; +} \ No newline at end of file diff --git a/src/main/java/org/acme/rest/panache/TestEntityRepository.java b/src/main/java/org/acme/rest/panache/TestEntityRepository.java new file mode 100644 index 0000000..b4d8539 --- /dev/null +++ b/src/main/java/org/acme/rest/panache/TestEntityRepository.java @@ -0,0 +1,14 @@ +package org.acme.rest.panache; + +import java.util.UUID; +import javax.enterprise.context.Dependent; + +import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; + +/** + * @author cristhiank on 2019-04-09 + * + **/ +@Dependent +public class TestEntityRepository implements PanacheRepositoryBase { +} diff --git a/src/main/kotlin/org/acme/rest/GreetingResource.kt b/src/main/kotlin/org/acme/rest/GreetingResource.kt deleted file mode 100644 index cb93e66..0000000 --- a/src/main/kotlin/org/acme/rest/GreetingResource.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.acme.rest - -import javax.inject.Inject -import javax.ws.rs.GET -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.MediaType - -@Path("/bug") -class GreetingResource { - - @Inject - lateinit var service: GreetingService - @Inject - lateinit var otherService: OtherService - - @GET - @Path("/1575") - @Produces(MediaType.TEXT_PLAIN) - fun helloBug1575() = service.helloBug1575() - - @GET - @Path("/1650") - @Produces(MediaType.TEXT_PLAIN) - fun helloBug1650() = otherService.helloBug1650() -} \ No newline at end of file diff --git a/src/main/kotlin/org/acme/rest/GreetingService.kt b/src/main/kotlin/org/acme/rest/GreetingService.kt deleted file mode 100644 index 689d1bd..0000000 --- a/src/main/kotlin/org/acme/rest/GreetingService.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.acme.rest; - -import org.eclipse.microprofile.config.inject.ConfigProperty -import org.flywaydb.core.Flyway -import javax.enterprise.context.Dependent -import javax.inject.Inject - -@Dependent -open class GreetingService { - - @Inject - @ConfigProperty(name = "quarkus.datasource.url") - lateinit var dbURL: String - @Inject - @ConfigProperty(name = "quarkus.datasource.username") - lateinit var user: String - @Inject - @ConfigProperty(name = "quarkus.datasource.password") - lateinit var pass: String - // INJECTION (repeated) bug #1650 - @Inject - @ConfigProperty(name = "custom.config") - lateinit var custom: String - - - fun helloBug1575(): String { - val flyway = Flyway.configure() - .dataSource(dbURL, user, pass) - .load() - flyway.migrate() - return "Hello ITS OK" - } - - fun helloBug1828(): String { - return "IT WORKS" - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/acme/rest/OtherService.kt b/src/main/kotlin/org/acme/rest/OtherService.kt deleted file mode 100644 index 04ec248..0000000 --- a/src/main/kotlin/org/acme/rest/OtherService.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.acme.rest - -import org.eclipse.microprofile.config.inject.ConfigProperty -import javax.enterprise.context.Dependent -import javax.inject.Inject - -/** - * - * @author cristhiank on 2019-03-22 - * - **/ -@Dependent -class OtherService { - // INJECTION (repeated) bug #1650 - @Inject - @ConfigProperty(name = "custom.config") - lateinit var customConfig: String - - fun helloBug1650(): String { - println("Config=$customConfig") - return customConfig - } -} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4ba268..b43ac02 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,4 +2,5 @@ quarkus.datasource.url:jdbc:h2:mem:quarked_flyway quarkus.datasource.driver:org.h2.Driver quarkus.datasource.username:sa quarkus.datasource.password:sa -custom.config=CUSTOMIZED \ No newline at end of file +custom.config=CUSTOMIZED +quarkus.hibernate-orm.database.generation=drop-and-create \ No newline at end of file diff --git a/src/test/java/org/acme/rest/GreetingResourceTest.java b/src/test/java/org/acme/rest/GreetingResourceTest.java new file mode 100644 index 0000000..b44d85d --- /dev/null +++ b/src/test/java/org/acme/rest/GreetingResourceTest.java @@ -0,0 +1,45 @@ +package org.acme.rest; + +import javax.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import io.quarkus.test.junit.QuarkusTest; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) // Bug #1828 +@QuarkusTest +public class GreetingResourceTest { + + @Inject + GreetingService service; + + @Test + void testBug1575() { + given() + .when().get( "/bug/1575" ) + .then() + .statusCode( 200 ) + .body( is( "Hello ITS OK" ) ); + } + + @Test + void testBug1650() { + given() + .when().get( "/bug/1650" ) + .then() + .statusCode( 200 ) + .body( is( "CUSTOMIZED" ) ); + } + + @Test + void testBug1828() { + var test = service.helloBug1828(); + assertEquals( "IT WORKS", test ); + } + +} \ No newline at end of file diff --git a/src/test/java/org/acme/rest/NativeGreetingResourceIT.java b/src/test/java/org/acme/rest/NativeGreetingResourceIT.java new file mode 100644 index 0000000..2e71a3b --- /dev/null +++ b/src/test/java/org/acme/rest/NativeGreetingResourceIT.java @@ -0,0 +1,8 @@ +package org.acme.rest; + +import io.quarkus.test.junit.SubstrateTest; + +@SubstrateTest +class NativeGreetingResourceIT extends GreetingResourceTest { + +} \ No newline at end of file diff --git a/src/test/java/org/acme/rest/PanacheResourceKotlinTest.kt b/src/test/java/org/acme/rest/PanacheResourceKotlinTest.kt new file mode 100644 index 0000000..857917c --- /dev/null +++ b/src/test/java/org/acme/rest/PanacheResourceKotlinTest.kt @@ -0,0 +1,25 @@ +package org.acme.rest + +import io.quarkus.test.junit.QuarkusTest +import org.acme.rest.panache.TestEntity +import org.acme.rest.panache.TestEntityRepository +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import javax.inject.Inject + +@QuarkusTest +class PanacheResourceKotlinTest { + @Inject + lateinit var repository: TestEntityRepository + + @Test + fun testBug1969() { + val entity = TestEntity() + entity.name = "TEST" + repository.persist(entity) + Assertions.assertNotNull(entity.id) + println("Entity id is: ${entity.id}") + val found = repository.findById(entity.id) + Assertions.assertNotNull(found) + } +} \ No newline at end of file diff --git a/src/test/java/org/acme/rest/PanacheResourceTest.java b/src/test/java/org/acme/rest/PanacheResourceTest.java new file mode 100644 index 0000000..98c08fa --- /dev/null +++ b/src/test/java/org/acme/rest/PanacheResourceTest.java @@ -0,0 +1,47 @@ +package org.acme.rest; + +import java.util.UUID; +import javax.inject.Inject; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import org.acme.rest.panache.TestEntity; +import org.acme.rest.panache.TestEntityRepository; + +import static io.restassured.RestAssured.given; +import static org.wildfly.common.Assert.assertNotNull; + +@QuarkusTest +class PanacheResourceTest { + @Inject + TestEntityRepository repository; + + @Test + void testBug1969() { + var entity = new TestEntity(); + entity.name = "TEST"; + repository.persist( entity ); + Assertions.assertNotNull( entity.id ); + System.out.println( "Entity id is: " + entity.id ); + var found = repository.findById( entity.id ); + Assertions.assertNotNull( found ); + } + + @Test + void testBug1969Rest() { + var entity = new TestEntity(); + entity.id = UUID.randomUUID(); + entity.name = "TEST"; + //repository.persist(entity) + assertNotNull( entity.id ); + System.out.println( "Entity id is: ${entity.id}" ); + given().when() + .get( "/test-entity/{0}", entity.id ) + .then() + .assertThat() + .statusCode( 204 ); // 204 is ok.. doesn't exist + } + +} \ No newline at end of file diff --git a/src/test/kotlin/org/acme/rest/GreetingResourceTest.kt b/src/test/kotlin/org/acme/rest/GreetingResourceTest.kt deleted file mode 100644 index 2ab2617..0000000 --- a/src/test/kotlin/org/acme/rest/GreetingResourceTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -package org.acme.rest - -import io.quarkus.test.junit.QuarkusTest -import io.restassured.RestAssured.given -import org.hamcrest.CoreMatchers.`is` -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance -import javax.inject.Inject - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) // Bug #1828 -@QuarkusTest -open class GreetingResourceTest { - - @Inject - lateinit var service: GreetingService - - @Test - fun testBug1575() { - given() - .`when`().get("/bug/1575") - .then() - .statusCode(200) - .body(`is`("Hello ITS OK")) - } - - @Test - fun testBug1650() { - given() - .`when`().get("/bug/1650") - .then() - .statusCode(200) - .body(`is`("CUSTOMIZED")) - } - - @Test - fun testBug1828() { - val test = service.helloBug1828() - assertEquals("IT WORKS", test) - } - -} \ No newline at end of file diff --git a/src/test/kotlin/org/acme/rest/NativeGreetingResourceIT.kt b/src/test/kotlin/org/acme/rest/NativeGreetingResourceIT.kt deleted file mode 100644 index 562efd5..0000000 --- a/src/test/kotlin/org/acme/rest/NativeGreetingResourceIT.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.acme.rest - -import io.quarkus.test.junit.SubstrateTest - -@SubstrateTest -open class NativeGreetingResourceIT : GreetingResourceTest() \ No newline at end of file