Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2020-06-24 16:37:23 +01:00
parent d85bf402e3
commit dca850f5ad
6 changed files with 69 additions and 56 deletions

View File

@ -4,7 +4,7 @@
* 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.test.collection.lazynocascade;
package org.hibernate.orm.test.collection.lazynocascade;
/**
* @author Vasily Kochnev

View File

@ -4,7 +4,7 @@
* 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.test.collection.lazynocascade;
package org.hibernate.orm.test.collection.lazynocascade;
/**
* @author Vasily Kochnev

View File

@ -0,0 +1,65 @@
/*
* 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.orm.test.collection.lazynocascade;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Vasily Kochnev
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/collection/lazynocascade/Parent.hbm.xml"
)
@SessionFactory
public class LazyAssociationNoCascadeTest {
@Test
public void testNoCascadeCache(SessionFactoryScope scope) {
Parent parent = new Parent();
BaseChild firstChild = new BaseChild();
parent.getChildren().add( firstChild );
Parent mergedParent = scope.fromSession(
session -> {
session.beginTransaction();
try {
session.save( parent );
session.getTransaction().commit();
session.clear();
Child secondChild = new Child();
secondChild.setName( "SecondChildName" );
parent.getChildren().add( secondChild );
firstChild.setDependency( secondChild );
session.beginTransaction();
Parent merged = (Parent) session.merge( parent );
session.getTransaction().commit();
return merged;
}
catch (Exception exception) {
if ( session.getTransaction().isActive() ) {
session.getTransaction().rollback();
}
throw exception;
}
}
);
assertNotNull( mergedParent );
assertEquals( mergedParent.getChildren().size(), 2 );
}
}

View File

@ -8,7 +8,7 @@
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.collection.lazynocascade">
<hibernate-mapping package="org.hibernate.orm.test.collection.lazynocascade">
<class name="Parent">
<id name="id" column="parent_id">
<generator class="increment"/>

View File

@ -4,7 +4,7 @@
* 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.test.collection.lazynocascade;
package org.hibernate.orm.test.collection.lazynocascade;
import java.util.LinkedHashSet;
import java.util.Set;

View File

@ -1,52 +0,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>.
*/
package org.hibernate.test.collection.lazynocascade;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.hibernate.Session;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Vasily Kochnev
*/
public class LazyAssociationNoCascadeTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[] {"collection/lazynocascade/Parent.hbm.xml"};
}
@Test
public void testNoCascadeCache() {
Parent parent = new Parent();
BaseChild firstChild = new BaseChild();
parent.getChildren().add( firstChild );
Session s = openSession();
s.beginTransaction();
s.save(parent);
s.getTransaction().commit();
s.clear();
Child secondChild = new Child();
secondChild.setName( "SecondChildName" );
parent.getChildren().add( secondChild );
firstChild.setDependency( secondChild );
s.beginTransaction();
Parent mergedParent = (Parent) s.merge( parent );
s.getTransaction().commit();
s.close();
assertNotNull( mergedParent );
assertEquals( mergedParent.getChildren().size(), 2 );
}
}