From 78dab9a83794b8037f0735e9e4de39f6b9b31256 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 1 Nov 2022 23:05:30 +0100 Subject: [PATCH] add a test for "dynamic" i.e. Map entities --- .../reactive/dynamic/DynamicEntityTest.java | 44 +++++++++++++++++++ .../hibernate/reactive/dynamic/Book.hbm.xml | 11 +++++ 2 files changed, 55 insertions(+) create mode 100644 hibernate-reactive-core/src/test/java/org/hibernate/reactive/dynamic/DynamicEntityTest.java create mode 100644 hibernate-reactive-core/src/test/resources/org/hibernate/reactive/dynamic/Book.hbm.xml diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/dynamic/DynamicEntityTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/dynamic/DynamicEntityTest.java new file mode 100644 index 000000000..bcdd24334 --- /dev/null +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/dynamic/DynamicEntityTest.java @@ -0,0 +1,44 @@ +/* Hibernate, Relational Persistence for Idiomatic Java + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright: Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.reactive.dynamic; + +import io.vertx.ext.unit.TestContext; +import org.hibernate.reactive.BaseReactiveTest; +import org.hibernate.tuple.DynamicMapInstantiator; +import org.junit.Test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class DynamicEntityTest extends BaseReactiveTest { + + @Override + protected Collection mappings() { + return List.of("org/hibernate/reactive/dynamic/Book.hbm.xml"); + } + + @Test + public void test(TestContext context) { + Map book = new HashMap<>(); + book.put("ISBN", "9781932394153"); + book.put("title", "Hibernate in Action"); + book.put("author", "Christian Bauer and Gavin King"); + book.put( DynamicMapInstantiator.KEY, "Book" ); + + test( + context, + getMutinySessionFactory() + .withTransaction( session -> session.persist( book ) ) + .chain( v -> getMutinySessionFactory() + .withSession( session -> session.createQuery("from Book", Map.class).getSingleResult() ) + .invoke( map -> context.assertEquals( "Christian Bauer and Gavin King", map.get("author") ) ) ) + ); + } + +} diff --git a/hibernate-reactive-core/src/test/resources/org/hibernate/reactive/dynamic/Book.hbm.xml b/hibernate-reactive-core/src/test/resources/org/hibernate/reactive/dynamic/Book.hbm.xml new file mode 100644 index 000000000..eb5205355 --- /dev/null +++ b/hibernate-reactive-core/src/test/resources/org/hibernate/reactive/dynamic/Book.hbm.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file