HHH-10968 - Test cases.

This commit is contained in:
Chris Cranford 2016-07-25 21:56:07 -05:00
parent 45460a7085
commit a345adbdc5
5 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml.metamodel;
import java.util.Map;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
/**
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-10968")
public abstract class AbstractMetamodelPopulateTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[] { "org/hibernate/jpa/test/xml/Person.hbm.xml" };
}
@Override
@SuppressWarnings("unchecked")
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( AvailableSettings.JPA_METAMODEL_POPULATION, getPopulationMode() );
}
protected abstract String getPopulationMode();
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml.metamodel;
import javax.persistence.EntityManager;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.junit.Assert.assertNull;
/**
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-10968")
public class DisabledPopulationTest extends AbstractMetamodelPopulateTest {
@Override
protected String getPopulationMode() {
return "DISABLED";
}
@Test
public void testJpaMetaModelPopulationDisabled() {
EntityManager entityManager = getOrCreateEntityManager();
try {
// When 'DISABLED' is set, no metamodel data is populated.
// This means that the metamodel data will be null.
assertNull( entityManager.getMetamodel() );
}
finally {
entityManager.close();
}
}
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml.metamodel;
import javax.persistence.EntityManager;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-10968")
public class EnabledPopulationTest extends AbstractMetamodelPopulateTest {
@Override
protected String getPopulationMode() {
return "ENABLED";
}
@Test
public void testJpaMetaModelPopulationEnabled() {
EntityManager entityManager = getOrCreateEntityManager();
try {
// When 'ENABLED' is set, the metamodel data is populated, including map-mode entities.
// This means that the mapped entity will be included in the managed types.
assertEquals( 1, entityManager.getMetamodel().getManagedTypes().size() );
}
finally {
entityManager.close();
}
}
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml.metamodel;
import javax.persistence.EntityManager;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-10968")
public class IgnoreUnsupportedPopulationTest extends AbstractMetamodelPopulateTest {
@Override
protected String getPopulationMode() {
return "ignoreUnsupported";
}
@Test
public void testJpaMetaModelPopulationSettingUnsupported() {
EntityManager entityManager = getOrCreateEntityManager();
try {
// When 'ignoreUnsupported' is set, all map-mode entities are ignored.
// This means that the managed types collection is empty.
assertTrue( entityManager.getMetamodel().getManagedTypes().isEmpty() );
}
finally {
entityManager.close();
}
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!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="Person">
<id name="id" type="integer">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="NAME" length="20" not-null="true"/>
</property>
</class>
</hibernate-mapping>