Skip to content

Commit e28b200

Browse files
authored
Merge pull request #30501 from ia3andy/fix-panache-codestart-test
Fix HibernateOrmCodestart
2 parents 15065dd + 277b190 commit e28b200

File tree

14 files changed

+68
-78
lines changed

14 files changed

+68
-78
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public class MyEntity {
3131

3232
public String field;
3333
}
34-
{/if}
35-
{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache')}
34+
{#else}
3635
import io.quarkus.hibernate.orm.panache.PanacheEntity;
3736
import javax.persistence.Entity;
3837

devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt

-31
This file was deleted.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class MyKotlinEntity {
3030
var id: Long? = null
3131
var field: String? = null
3232
}
33-
{/if}
34-
{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')}
33+
{#else}
3534
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
3635
import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
3736
import javax.persistence.Entity
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
package io.quarkus.devtools.codestarts.quarkus;
22

33
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA;
4+
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN;
45

56
import org.junit.jupiter.api.Test;
67
import org.junit.jupiter.api.extension.RegisterExtension;
78

89
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
910
import io.quarkus.maven.dependency.ArtifactKey;
1011

11-
public class HibernateOrmCodestartTest {
12+
public class HibernateOrmCodestartIT {
1213

1314
@RegisterExtension
1415
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
1516
.codestarts("hibernate-orm")
1617
.extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2"))
17-
.languages(JAVA)
18+
.languages(JAVA, KOTLIN)
1819
.build();
1920

2021
@Test
2122
void testContent() throws Throwable {
22-
codestartTest.checkGeneratedSource("org.acme.MyEntity");
23-
codestartTest.checkGeneratedSource(QuarkusCodestartCatalog.Language.KOTLIN, "org.acme.MyKotlinEntity");
23+
codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity");
24+
codestartTest.checkGeneratedSource(KOTLIN, "org.acme.MyKotlinEntity");
25+
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql");
26+
codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql");
2427
}
2528

2629
@Test
27-
void buildAllProjectsForLocalUse() throws Throwable {
30+
void testBuild() throws Throwable {
2831
codestartTest.buildAllProjects();
2932
}
3033
}
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
99
import io.quarkus.maven.ArtifactKey;
1010

11-
public class HibernateOrmPanacheCodestartTest {
11+
public class HibernateOrmPanacheCodestartIT {
1212

1313
@RegisterExtension
1414
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
@@ -21,10 +21,11 @@ public class HibernateOrmPanacheCodestartTest {
2121
@Test
2222
void testContent() throws Throwable {
2323
codestartTest.checkGeneratedSource("org.acme.MyEntity");
24+
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql");
2425
}
2526

2627
@Test
27-
void buildAllProjectsForLocalUse() throws Throwable {
28+
void testBuild() throws Throwable {
2829
codestartTest.buildAllProjects();
2930
}
3031
}
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
99
import io.quarkus.maven.ArtifactKey;
1010

11-
public class HibernateOrmPanacheKotlinCodestartTest {
11+
public class HibernateOrmPanacheKotlinCodestartIT {
1212

1313
@RegisterExtension
1414
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
@@ -21,10 +21,11 @@ public class HibernateOrmPanacheKotlinCodestartTest {
2121
@Test
2222
void testContent() throws Throwable {
2323
codestartTest.checkGeneratedSource("org.acme.MyKotlinEntity");
24+
codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql");
2425
}
2526

2627
@Test
27-
void buildAllProjectsForLocalUse() throws Throwable {
28+
void testBuild() throws Throwable {
2829
codestartTest.buildAllProjects();
2930
}
3031
}
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import javax.persistence.Id
99
*
1010
* To use it, get access to a JPA EntityManager via injection.
1111
*
12-
* ```kotlin
12+
* {@code
1313
* @Inject
1414
* lateinit var em:EntityManager;
1515
*
@@ -20,12 +20,12 @@ import javax.persistence.Id
2020
*
2121
* val entities:List<MyKotlinEntity> = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList()
2222
* }
23-
* ```
23+
* }
2424
*/
2525
@Entity
2626
class MyKotlinEntity {
2727
@get:GeneratedValue
2828
@get:Id
2929
var id: Long? = null
3030
var field: String? = null
31-
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file allow to write SQL commands that will be emitted in test and dev.
2+
-- The commands are commented as their support depends of the database
3+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1');
4+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
5+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file allow to write SQL commands that will be emitted in test and dev.
2+
-- The commands are commented as their support depends of the database
3+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1');
4+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
5+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ilove.quark.us
2+
3+
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
4+
import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
5+
import javax.persistence.Entity
6+
7+
/**
8+
* Example JPA entity defined as a Kotlin Panache Entity.
9+
* An ID field of Long type is provided, if you want to define your own ID field extends <code>PanacheEntityBase</code> instead.
10+
*
11+
* This uses the active record pattern, you can also use the repository pattern instead:
12+
* .
13+
*
14+
* Usage (more example on the documentation)
15+
*
16+
* {@code
17+
*
18+
* fun doSomething() {
19+
* val entity1 = MyKotlinEntity();
20+
* entity1.field = "field-1"
21+
* entity1.persist()
22+
*
23+
* val entities:List<MyKotlinEntity> = MyKotlinEntity.listAll()
24+
* }
25+
* }
26+
*/
27+
@Entity
28+
class MyKotlinEntity: PanacheEntity() {
29+
companion object: PanacheCompanion<MyKotlinEntity> {
30+
fun byName(name: String) = list("name", name)
31+
}
32+
33+
lateinit var field: String
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file allow to write SQL commands that will be emitted in test and dev.
2+
-- The commands are commented as their support depends of the database
3+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1');
4+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
5+
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');

integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt

-31
This file was deleted.

0 commit comments

Comments
 (0)