Skip to content

[3.0] Test HQL new operator with many-to-one #2282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: clean up HQLQueryTest class
* Code formattation
* Replace Jupiter assertions with AssertJ ones
  • Loading branch information
DavideD committed May 30, 2025
commit 68fe873bce92d4cf29cb4778cbcd5dca1b51c88b
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/
package org.hibernate.reactive;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -21,19 +18,19 @@
import io.vertx.junit5.Timeout;
import io.vertx.junit5.VertxTestContext;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

import static jakarta.persistence.CascadeType.PERSIST;
import static jakarta.persistence.FetchType.LAZY;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Timeout(value = 10, timeUnit = MINUTES)

public class HQLQueryTest extends BaseReactiveTest {

Flour spelt = new Flour( 1, "Spelt", "An ancient grain, is a hexaploid species of wheat.", "Wheat flour" );
Expand Down Expand Up @@ -82,7 +79,7 @@ public void testAutoFlushOnResultList(VertxTestContext context) {
public void testSelectScalarString(VertxTestContext context) {
test( context, getSessionFactory().withSession( s -> {
Stage.SelectionQuery<String> qr = s.createSelectionQuery( "SELECT 'Prova' FROM Flour WHERE id = " + rye.getId(), String.class );
assertNotNull( qr );
assertThat( qr ).isNotNull();
return qr.getSingleResult();
} ).thenAccept( found -> assertEquals( "Prova", found ) ) );
}
Expand All @@ -91,30 +88,33 @@ public void testSelectScalarString(VertxTestContext context) {
public void testSelectScalarCount(VertxTestContext context) {
test( context, getSessionFactory().withSession( s -> {
Stage.SelectionQuery<Long> qr = s.createSelectionQuery( "SELECT count(*) FROM Flour", Long.class );
assertNotNull( qr );
assertThat( qr ).isNotNull();
return qr.getSingleResult();
} ).thenAccept( found -> assertEquals( 3L, found ) ) );
}

@Test
public void testSelectWithMultipleScalarValues(VertxTestContext context) {
test( context, getSessionFactory().withSession( s -> {
Stage.SelectionQuery<?> qr = s.createSelectionQuery( "SELECT 'Prova', f.id FROM Flour f WHERE f.id = " + rye.getId(), Object[].class );
assertNotNull( qr );
return qr.getSingleResult();
} ).thenAccept( found -> {
assertTrue( found instanceof Object[] );
assertEquals( "Prova", ( (Object[]) found )[0] );
assertEquals( rye.getId(), ( (Object[]) found )[1] );
} )
Stage.SelectionQuery<?> qr = s.createSelectionQuery(
"SELECT 'Prova', f.id FROM Flour f WHERE f.id = " + rye.getId(),
Object[].class
);
assertThat( qr ).isNotNull();
return qr.getSingleResult();
} ).thenAccept( found -> {
assertThat( found ).isInstanceOf( Object[].class );
assertEquals( "Prova", ( (Object[]) found )[0] );
assertEquals( rye.getId(), ( (Object[]) found )[1] );
} )
);
}

@Test
public void testSingleResultQueryOnId(VertxTestContext context) {
test( context, getSessionFactory().withSession( s -> {
Stage.SelectionQuery<?> qr = s.createSelectionQuery( "FROM Flour WHERE id = 1", Flour.class );
assertNotNull( qr );
assertThat( qr ).isNotNull();
return qr.getSingleResult();
} ).thenAccept( flour -> assertEquals( spelt, flour ) )
);
Expand All @@ -124,7 +124,7 @@ public void testSingleResultQueryOnId(VertxTestContext context) {
public void testSingleResultQueryOnName(VertxTestContext context) {
test( context, getSessionFactory().withSession( s -> {
Stage.SelectionQuery<?> qr = s.createSelectionQuery( "FROM Flour WHERE name = 'Almond'", Flour.class );
assertNotNull( qr );
assertThat( qr ).isNotNull();
return qr.getSingleResult();
} ).thenAccept( flour -> assertEquals( almond, flour ) )
);
Expand All @@ -135,7 +135,7 @@ public void testFromQuery(VertxTestContext context) {
test( context, getSessionFactory()
.withSession( s -> {
Stage.SelectionQuery<Flour> qr = s.createSelectionQuery( "FROM Flour ORDER BY name", Flour.class );
assertNotNull( qr );
assertThat( qr ).isNotNull();
return qr.getResultList();
} )
.thenAccept( results -> assertThat( results ).containsExactly( almond, rye, spelt ) )
Expand Down
Loading