Skip to content

Commit f1db967

Browse files
committed
add a test for "dynamic" i.e. Map entities
1 parent ba19489 commit f1db967

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE hibernate-mapping PUBLIC
2+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3+
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
4+
5+
<hibernate-mapping>
6+
<class entity-name="Book" table="dbooks">
7+
<id name="ISBN" column="isbn" length="32" type="string"/>
8+
<property name="title" not-null="true" length="50" type="string"/>
9+
<property name="author" not-null="true" length="50" type="string"/>
10+
</class>
11+
</hibernate-mapping>

0 commit comments

Comments
 (0)