HHH-17772 add tests

This commit is contained in:
Gavin King 2024-02-23 21:36:06 +01:00
parent 0bc198f265
commit 83595ea461
6 changed files with 153 additions and 0 deletions

View File

@ -140,6 +140,7 @@ dependencyResolutionManagement {
def elVersion = version "el", "5.0.0"
def injectVersion = version "inject", "2.0.1"
def interceptorsVersion = version "interceptors", "2.1.0"
def dataVersion = version "data", "1.0.0-M3"
def jaccVersion = version "jacc", "2.1.0"
def jaxbApiVersion = version "jaxbApi", "4.0.0"
def jaxbRuntimeVersion = version "jaxbRuntime", "4.0.2"
@ -157,6 +158,7 @@ dependencyResolutionManagement {
library( "cdi", "jakarta.enterprise", "jakarta.enterprise.cdi-api" ).versionRef( cdiVersion )
library( "annotation", "jakarta.annotation", "jakarta.annotation-api" ).versionRef( annotationVersion )
library( "interceptors", "jakarta.interceptor", "jakarta.interceptor-api" ).versionRef( interceptorsVersion )
library( "data", "jakarta.data", "jakarta.data-api" ).versionRef( dataVersion )
library( "jsonbApi", "jakarta.json.bind", "jakarta.json.bind-api" ).versionRef( jsonbApiVersion )
library( "jsonb", "org.eclipse", "yasson" ).versionRef( jsonbRuntimeVersion )
library( "inject", "jakarta.inject", "jakarta.inject-api" ).versionRef( injectVersion )

View File

@ -25,6 +25,7 @@ dependencies {
api jakartaLibs.jaxb
api jakartaLibs.validation
api jakartaLibs.annotation
api jakartaLibs.data
api libs.antlrRuntime
api libs.byteBuddy

View File

@ -0,0 +1,21 @@
package org.hibernate.jpamodelgen.test.data;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import java.util.Set;
@Entity
public class Author {
@Id
String ssn;
String name;
// @Embedded
// Address address;
@ManyToMany
Set<Book> books;
}

View File

@ -0,0 +1,39 @@
package org.hibernate.jpamodelgen.test.data;
import jakarta.persistence.*;
import org.hibernate.annotations.NaturalId;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;
@Entity
@Table(name = "books")
public class Book {
@Id
String isbn;
@NaturalId
@Basic(optional = false)
String title;
@Basic(optional = false)
String text;
@NaturalId
LocalDate publicationDate;
@ManyToMany(mappedBy = "books")
Set<Author> authors;
BigDecimal price;
int pages;
public Book(String isbn, String title, String text) {
this.isbn = isbn;
this.title = title;
this.text = text;
}
Book() {}
}

View File

@ -0,0 +1,60 @@
package org.hibernate.jpamodelgen.test.data;
import jakarta.data.Limit;
import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.repository.By;
import jakarta.data.repository.Delete;
import jakarta.data.repository.Find;
import jakarta.data.repository.Insert;
import jakarta.data.repository.OrderBy;
import jakarta.data.repository.Param;
import jakarta.data.repository.Query;
import jakarta.data.repository.Repository;
import jakarta.data.repository.Update;
import org.hibernate.StatelessSession;
import java.time.LocalDate;
import java.util.List;
@Repository(dataStore = "myds")
public interface BookAuthorRepository {
StatelessSession session();
@Find
Book book(String isbn);
@Find
Book bookById(@By("isbn") String id);
@Find
@OrderBy(value = "title", ignoreCase = true)
List<Book> byPubDate0(LocalDate publicationDate);
@Find
@OrderBy(value = "title", ignoreCase = true)
@OrderBy(value = "isbn", descending = true)
List<Book> byPubDate1(LocalDate publicationDate, Limit limit, Sort<? super Book> order);
@Find
List<Book> byPubDate2(LocalDate publicationDate, Order<? super Book> order);
@Insert
void create(Book book);
@Update
void update(Book book);
@Delete
void delete(Book book);
@Query("from Book where title like :title")
List<Book> books0(String title);
@Query("from Book where title like :title")
List<Book> books1(@Param("title") String titlePattern, Order<Book> order);
@Query("from Book where title like :title")
List<Book> books2(@Param("title") String titlePattern, Limit limit);
}

View File

@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.data;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
import org.hibernate.jpamodelgen.test.util.WithClasses;
import org.junit.Test;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetaModelSourceAsString;
/**
* @author Gavin King
*/
public class DataTest extends CompilationTest {
@Test
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class })
public void test() {
System.out.println( getMetaModelSourceAsString( Author.class ) );
System.out.println( getMetaModelSourceAsString( Book.class ) );
System.out.println( getMetaModelSourceAsString( BookAuthorRepository.class ) );
assertMetamodelClassGeneratedFor( Author.class );
assertMetamodelClassGeneratedFor( Book.class );
assertMetamodelClassGeneratedFor( BookAuthorRepository.class );
}
}