diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/README.tpl.qute.md new file mode 100644 index 00000000000000..405280158877db --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/README.tpl.qute.md @@ -0,0 +1 @@ +{#include readme-header /} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/application.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/application.yml new file mode 100644 index 00000000000000..d52d368a661ce0 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/application.yml @@ -0,0 +1,5 @@ +# drop and create the database at startup (use `update` to only update the schema) +quarkus: + hibernate-orm: + database: + generation: drop-and-create \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/import.sql b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/import.sql new file mode 100644 index 00000000000000..3afafdc356eaf4 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/import.sql @@ -0,0 +1,3 @@ +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/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/codestart.yml new file mode 100644 index 00000000000000..1028424bd4dc83 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/codestart.yml @@ -0,0 +1,12 @@ +name: hibernate-orm-codestart +ref: hibernate-orm +tags: extension-codestart +type: code +metadata: + title: Hibernate ORM + description: Create your first JPA entity + related-guide-section: https://quarkus.io/guides/hibernate-orm +language: + base: + dependencies: + - io.quarkus:quarkus-hibernate-orm 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.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.java new file mode 100644 index 00000000000000..09ee5de0a835d5 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.java @@ -0,0 +1,29 @@ +package org.acme; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class MyEntity { + private Long id; + private String field; + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/test/java/org/acme/MyEntityTest.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/test/java/org/acme/MyEntityTest.java new file mode 100644 index 00000000000000..aa110fb359188f --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/test/java/org/acme/MyEntityTest.java @@ -0,0 +1,22 @@ +package org.acme; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import java.util.List; + +@QuarkusTest +public class MyEntityTest { + @Inject + EntityManager em; + + @Test + public void testMyEntity() { + List entities = em.createQuery("from MyEntity", MyEntity.class).getResultList(); + Assertions.assertEquals(3, entities.size()); + } + +} diff --git a/extensions/hibernate-orm/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/hibernate-orm/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 7d11f7d5b4c0e3..7999550daca6b1 100644 --- a/extensions/hibernate-orm/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/hibernate-orm/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -14,3 +14,7 @@ metadata: config: - "quarkus.datasource." - "quarkus.hibernate-orm." + codestart: + name: "hibernate-orm" + languages: "java" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" 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/HibernateOrmCodestartTest.java new file mode 100644 index 00000000000000..200631028f95a2 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java @@ -0,0 +1,30 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; + +public class HibernateOrmCodestartTest { + + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("hibernate-orm") + .languages(JAVA) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.MyEntity"); + codestartTest.checkGeneratedTestSource("org.acme.MyEntityTest"); + } + + @Test + @EnabledIfSystemProperty(named = "build-projects", matches = "true") + void buildAllProjectsForLocalUse() 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__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java new file mode 100644 index 00000000000000..7217c11a9190bc --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java @@ -0,0 +1,29 @@ +package ilove.quark.us; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class MyEntity { + private Long id; + private String field; + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_test_java_ilove_quark_us_MyEntityTest.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_test_java_ilove_quark_us_MyEntityTest.java new file mode 100644 index 00000000000000..9e9eab287041eb --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_test_java_ilove_quark_us_MyEntityTest.java @@ -0,0 +1,22 @@ +package ilove.quark.us; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import java.util.List; + +@QuarkusTest +public class MyEntityTest { + @Inject + EntityManager em; + + @Test + public void testMyEntity() { + List entities = em.createQuery("from MyEntity", MyEntity.class).getResultList(); + Assertions.assertEquals(3, entities.size()); + } + +}