Skip to content

Commit

Permalink
Add a simple codestart for hibernate orm rest data in order to genera…
Browse files Browse the repository at this point in the history
…te REST resources for a simple entity
  • Loading branch information
aureamunoz committed Feb 1, 2024
1 parent 668284e commit dbb693f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{#include readme-header /}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- 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(1, 'field-1');
-- insert into myentity (id, field) values(2, 'field-2');
-- insert into myentity (id, field) values(3, 'field-3');
-- alter sequence myentity_seq restart with 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: hibernate-orm-rest-data-codestart
ref: hibernate-orm-rest-data
tags: extension-codestart
type: code
metadata:
title: REST Data with Panache
description: Generating Jakarta REST resources with Panache
related-guide-section: https://quarkus.io/guides/rest-data-panache
language:
base:
dependencies:
- io.quarkus:quarkus-hibernate-orm-rest-data-panache
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Entity;


/**
* Example JPA entity defined as a Panache Entity.
* An ID field of Long type is provided, if you want to define your own ID field extends <code>PanacheEntityBase</code> instead.
*
* This uses the active record pattern, you can also use the repository pattern instead:
* {@see https://quarkus.io/guides/hibernate-orm-panache#solution-2-using-the-repository-pattern}.
*
* Usage (more example on the documentation)
*
* \{@code
* public void doSomething() {
* MyEntity entity1 = new MyEntity();
* entity1.field = "field-1";
* entity1.persist();
*
* List<MyEntity> entities = MyEntity.listAll();
* }
* }
*/
@Entity
public class MyEntity extends PanacheEntity {
public String field;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.acme;

import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource;

public interface MyEntityResource extends PanacheEntityResource<MyEntity, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ metadata:
- "data"
- "web"
status: "stable"
codestart:
name: "hibernate-orm-rest-data"
languages: [ "java" ]
artifact: "io.quarkus:quarkus-project-core-extension-codestarts"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;

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

public class HibernateOrmRestDataCodestartIT {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("hibernate-orm-rest-data")
.extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2"))
.extension(ArtifactKey.ga("io.quarkus", "quarkus-resteasy-reactive-jackson"))
.languages(JAVA, KOTLIN)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity");

Check failure on line 24 in integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java

View workflow job for this annotation

GitHub Actions / Build summary for dbb693fd19e0f84e994d5180786616e077312a43

Devtools Tests - JDK 17

java.lang.AssertionError: [corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] Expecting path:
Raw output
java.lang.AssertionError: 
[corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] 
Expecting path:
  /home/runner/work/quarkus/quarkus/integration-tests/devtools/target/test-classes/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java
to exist (symbolic links were followed).
	at io.quarkus.devtools.testing.SnapshotTesting.lambda$assertThatMatchSnapshot$0(SnapshotTesting.java:180)
	at io.quarkus.devtools.testing.SnapshotTesting.withSnapshotsDir(SnapshotTesting.java:97)
	at io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot(SnapshotTesting.java:160)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.assertThatGeneratedFileMatchSnapshot(QuarkusCodestartTest.java:257)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:295)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:204)
	at io.quarkus.devtools.codestarts.quarkus.HibernateOrmRestDataCodestartIT.testContent(HibernateOrmRestDataCodestartIT.java:24)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Check failure on line 24 in integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java

View workflow job for this annotation

GitHub Actions / Build summary for dbb693fd19e0f84e994d5180786616e077312a43

Devtools Tests - JDK 17

java.lang.AssertionError: [corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] Expecting path:
Raw output
java.lang.AssertionError: 
[corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] 
Expecting path:
  /home/runner/work/quarkus/quarkus/integration-tests/devtools/target/test-classes/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java
to exist (symbolic links were followed).
	at io.quarkus.devtools.testing.SnapshotTesting.lambda$assertThatMatchSnapshot$0(SnapshotTesting.java:180)
	at io.quarkus.devtools.testing.SnapshotTesting.withSnapshotsDir(SnapshotTesting.java:97)
	at io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot(SnapshotTesting.java:160)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.assertThatGeneratedFileMatchSnapshot(QuarkusCodestartTest.java:257)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:295)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:204)
	at io.quarkus.devtools.codestarts.quarkus.HibernateOrmRestDataCodestartIT.testContent(HibernateOrmRestDataCodestartIT.java:24)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Check failure on line 24 in integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java

View workflow job for this annotation

GitHub Actions / Build summary for dbb693fd19e0f84e994d5180786616e077312a43

Devtools Tests - JDK 21

java.lang.AssertionError: [corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] Expecting path:
Raw output
java.lang.AssertionError: 
[corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] 
Expecting path:
  /home/runner/work/quarkus/quarkus/integration-tests/devtools/target/test-classes/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java
to exist (symbolic links were followed).
	at io.quarkus.devtools.testing.SnapshotTesting.lambda$assertThatMatchSnapshot$0(SnapshotTesting.java:180)
	at io.quarkus.devtools.testing.SnapshotTesting.withSnapshotsDir(SnapshotTesting.java:97)
	at io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot(SnapshotTesting.java:160)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.assertThatGeneratedFileMatchSnapshot(QuarkusCodestartTest.java:257)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:295)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:204)
	at io.quarkus.devtools.codestarts.quarkus.HibernateOrmRestDataCodestartIT.testContent(HibernateOrmRestDataCodestartIT.java:24)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Check failure on line 24 in integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java

View workflow job for this annotation

GitHub Actions / Build summary for dbb693fd19e0f84e994d5180786616e077312a43

Devtools Tests - JDK 21

java.lang.AssertionError: [corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] Expecting path:
Raw output
java.lang.AssertionError: 
[corresponding snapshot file not found for HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java (Use -Dsnap to create it automatically)] 
Expecting path:
  /home/runner/work/quarkus/quarkus/integration-tests/devtools/target/test-classes/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java
to exist (symbolic links were followed).
	at io.quarkus.devtools.testing.SnapshotTesting.lambda$assertThatMatchSnapshot$0(SnapshotTesting.java:180)
	at io.quarkus.devtools.testing.SnapshotTesting.withSnapshotsDir(SnapshotTesting.java:97)
	at io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot(SnapshotTesting.java:160)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.assertThatGeneratedFileMatchSnapshot(QuarkusCodestartTest.java:257)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:295)
	at io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest.checkGeneratedSource(QuarkusCodestartTest.java:204)
	at io.quarkus.devtools.codestarts.quarkus.HibernateOrmRestDataCodestartIT.testContent(HibernateOrmRestDataCodestartIT.java:24)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql");
}

@Test
void testBuild() throws Throwable {
codestartTest.buildAllProjects();
}
}

0 comments on commit dbb693f

Please sign in to comment.