Skip to content

Commit

Permalink
add a test for "dynamic" i.e. Map entities
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Nov 1, 2022
1 parent f8af474 commit 78dab9a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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") ) ) )
);
}

}
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>

0 comments on commit 78dab9a

Please sign in to comment.