-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test for "dynamic" i.e. Map entities
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
hibernate-reactive-core/src/test/java/org/hibernate/reactive/dynamic/DynamicEntityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> mappings() { | ||
return List.of("org/hibernate/reactive/dynamic/Book.hbm.xml"); | ||
} | ||
|
||
@Test | ||
public void test(TestContext context) { | ||
Map<String, String> 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") ) ) ) | ||
); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
hibernate-reactive-core/src/test/resources/org/hibernate/reactive/dynamic/Book.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE hibernate-mapping PUBLIC | ||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" | ||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> | ||
|
||
<hibernate-mapping> | ||
<class entity-name="Book" table="dbooks"> | ||
<id name="ISBN" column="isbn" length="32" type="string"/> | ||
<property name="title" not-null="true" length="50" type="string"/> | ||
<property name="author" not-null="true" length="50" type="string"/> | ||
</class> | ||
</hibernate-mapping> |