diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java index ae11050e3e1c8..51b4a1aae3679 100644 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java @@ -31,8 +31,7 @@ public class MyEntity { public String field; } -{/if} -{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache')} +{#else} import io.quarkus.hibernate.orm.panache.PanacheEntity; import javax.persistence.Entity; diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt deleted file mode 100644 index 6ff0beb08ccda..0000000000000 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.acme - -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.Id - -/** - * Example JPA entity. - * - * To use it, get access to a JPA EntityManager via injection. - * - * ```kotlin - * @Inject - * lateinit var em:EntityManager; - * - * fun doSomething() { - * val entity1 = MyKotlinEntity(); - * entity1.field = "field-1" - * em.persist(entity1); - * - * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() - * } - * ``` - */ -@Entity -class MyKotlinEntity { - @get:GeneratedValue - @get:Id - var id: Long? = null - var field: String? = null -} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt index 71793b36ebafb..3d8a51d8c6513 100644 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt @@ -30,8 +30,7 @@ class MyKotlinEntity { var id: Long? = null var field: String? = null } -{/if} -{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')} +{#else} import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion import javax.persistence.Entity diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java similarity index 56% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java index 545c3371cb542..2e15e57133b3b 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java @@ -1,6 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -8,23 +9,25 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.dependency.ArtifactKey; -public class HibernateOrmCodestartTest { +public class HibernateOrmCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() .codestarts("hibernate-orm") .extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2")) - .languages(JAVA) + .languages(JAVA, KOTLIN) .build(); @Test void testContent() throws Throwable { - codestartTest.checkGeneratedSource("org.acme.MyEntity"); - codestartTest.checkGeneratedSource(QuarkusCodestartCatalog.Language.KOTLIN, "org.acme.MyKotlinEntity"); + codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity"); + codestartTest.checkGeneratedSource(KOTLIN, "org.acme.MyKotlinEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql"); + codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java similarity index 82% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java index 0c9c49c2e2d1e..51e1baabf7228 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java @@ -8,7 +8,7 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.ArtifactKey; -public class HibernateOrmPanacheCodestartTest { +public class HibernateOrmPanacheCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() @@ -21,10 +21,11 @@ public class HibernateOrmPanacheCodestartTest { @Test void testContent() throws Throwable { codestartTest.checkGeneratedSource("org.acme.MyEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java similarity index 82% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java index 7fe535c799a6e..7ae2f83db17b4 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java @@ -8,7 +8,7 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.ArtifactKey; -public class HibernateOrmPanacheKotlinCodestartTest { +public class HibernateOrmPanacheKotlinCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() @@ -21,10 +21,11 @@ public class HibernateOrmPanacheKotlinCodestartTest { @Test void testContent() throws Throwable { codestartTest.checkGeneratedSource("org.acme.MyKotlinEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java similarity index 100% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt similarity index 96% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt index 1bacaf93ee59b..ae6ca99d523eb 100644 --- a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt @@ -9,7 +9,7 @@ import javax.persistence.Id * * To use it, get access to a JPA EntityManager via injection. * - * ```kotlin + * {@code * @Inject * lateinit var em:EntityManager; * @@ -20,7 +20,7 @@ import javax.persistence.Id * * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() * } - * ``` + * } */ @Entity class MyKotlinEntity { @@ -28,4 +28,4 @@ class MyKotlinEntity { @get:Id var id: Long? = null var field: String? = null -} \ No newline at end of file +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java similarity index 100% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt new file mode 100644 index 0000000000000..0c21af1ce75f3 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt @@ -0,0 +1,34 @@ +package ilove.quark.us + +import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity +import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion +import javax.persistence.Entity + +/** + * Example JPA entity defined as a Kotlin Panache Entity. + * An ID field of Long type is provided, if you want to define your own ID field extends PanacheEntityBase instead. + * + * This uses the active record pattern, you can also use the repository pattern instead: + * . + * + * Usage (more example on the documentation) + * + * {@code + * + * fun doSomething() { + * val entity1 = MyKotlinEntity(); + * entity1.field = "field-1" + * entity1.persist() + * + * val entities:List = MyKotlinEntity.listAll() + * } + * } + */ +@Entity +class MyKotlinEntity: PanacheEntity() { + companion object: PanacheCompanion { + fun byName(name: String) = list("name", name) + } + + lateinit var field: String +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt deleted file mode 100644 index 1bacaf93ee59b..0000000000000 --- a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package ilove.quark.us - -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.Id - -/** - * Example JPA entity. - * - * To use it, get access to a JPA EntityManager via injection. - * - * ```kotlin - * @Inject - * lateinit var em:EntityManager; - * - * fun doSomething() { - * val entity1 = MyKotlinEntity(); - * entity1.field = "field-1" - * em.persist(entity1); - * - * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() - * } - * ``` - */ -@Entity -class MyKotlinEntity { - @get:GeneratedValue - @get:Id - var id: Long? = null - var field: String? = null -} \ No newline at end of file