|
| 1 | +/* Hibernate, Relational Persistence for Idiomatic Java |
| 2 | + * |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * Copyright: Red Hat Inc. and Hibernate Authors |
| 5 | + */ |
| 6 | +package org.hibernate.reactive.dynamic; |
| 7 | + |
| 8 | +import io.vertx.ext.unit.TestContext; |
| 9 | +import org.hibernate.reactive.BaseReactiveTest; |
| 10 | +import org.hibernate.tuple.DynamicMapInstantiator; |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import java.util.Collection; |
| 14 | +import java.util.HashMap; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | + |
| 19 | +public class DynamicEntityTest extends BaseReactiveTest { |
| 20 | + |
| 21 | + @Override |
| 22 | + protected Collection<String> mappings() { |
| 23 | + return List.of("org/hibernate/reactive/dynamic/Book.hbm.xml"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void test(TestContext context) { |
| 28 | + Map<String, String> book = new HashMap<>(); |
| 29 | + book.put("ISBN", "9781932394153"); |
| 30 | + book.put("title", "Hibernate in Action"); |
| 31 | + book.put("author", "Christian Bauer and Gavin King"); |
| 32 | + book.put( DynamicMapInstantiator.KEY, "Book" ); |
| 33 | + |
| 34 | + test( |
| 35 | + context, |
| 36 | + getMutinySessionFactory() |
| 37 | + .withTransaction( session -> session.persist( book ) ) |
| 38 | + .chain( v -> getMutinySessionFactory() |
| 39 | + .withSession( session -> session.createQuery("from Book", Map.class).getSingleResult() ) |
| 40 | + .invoke( map -> context.assertEquals( "Christian Bauer and Gavin King", map.get("author") ) ) ) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments