Skip to content

Commit

Permalink
[#2060] Add assertions to the test
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jan 21, 2025
1 parent e9be785 commit 2162b8b
Showing 1 changed file with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

import static org.assertj.core.api.Assertions.assertThat;

public class EmbeddedIdWithManyTest extends BaseReactiveTest {

Fruit cherry;
Fruit apple;
Fruit banana;

Flower sunflower;
Flower chrysanthemum;
Flower rose;

@Override
protected Collection<Class<?>> annotatedEntities() {
return List.of( Flower.class, Fruit.class );
Expand All @@ -34,21 +44,21 @@ protected Collection<Class<?>> annotatedEntities() {
@BeforeEach
public void populateDb(VertxTestContext context) {
Seed seed1 = new Seed( 1 );
Flower rose = new Flower( seed1, "Rose" );
rose = new Flower( seed1, "Rose" );

Fruit cherry = new Fruit( seed1, "Cherry" );
cherry = new Fruit( seed1, "Cherry" );
cherry.addFriend( rose );

Seed seed2 = new Seed( 2 );
Flower sunflower = new Flower( seed2, "Sunflower" );
sunflower = new Flower( seed2, "Sunflower" );

Fruit apple = new Fruit( seed2, "Apple" );
apple = new Fruit( seed2, "Apple" );
apple.addFriend( sunflower );

Seed seed3 = new Seed( 3 );
Flower chrysanthemum = new Flower( seed3, "Chrysanthemum" );
chrysanthemum = new Flower( seed3, "Chrysanthemum" );

Fruit banana = new Fruit( seed3, "Banana" );
banana = new Fruit( seed3, "Banana" );
banana.addFriend( chrysanthemum );

test(
Expand All @@ -60,11 +70,28 @@ public void populateDb(VertxTestContext context) {
}

@Test
public void test(VertxTestContext context) {
public void testFindWithEmbeddedId(VertxTestContext context) {
test(
context, getMutinySessionFactory().withTransaction( s -> s
.find( Flower.class, chrysanthemum.getSeed() )
.invoke( flower -> assertThat( flower.getName() ).isEqualTo( chrysanthemum.getName() ) )
)
);
}

@Test
public void testSelectQueryWithEmbeddedId(VertxTestContext context) {
test(
context, getMutinySessionFactory().withTransaction( s -> s
.createSelectionQuery( "from Flower", Flower.class )
.getResultList()
.invoke( list -> assertThat( list.stream().map( Flower::getName ) )
.containsExactlyInAnyOrder(
sunflower.getName(),
chrysanthemum.getName(),
rose.getName()
)
)
)
);
}
Expand Down

0 comments on commit 2162b8b

Please sign in to comment.