Skip to content

Commit

Permalink
Re-enabled additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Jul 26, 2021
1 parent 3022371 commit a648e63
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.inheritance.discriminator;
package org.hibernate.orm.test.inheritance.discriminator;

import java.sql.Statement;
import java.util.Map;
Expand All @@ -17,27 +17,37 @@
import javax.persistence.InheritanceType;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
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.AfterEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

@TestForIssue(jiraKey = "HHH-12445")
public class SingleTableNullNotNullDiscriminatorTest extends BaseCoreFunctionalTestCase {

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
RootEntity.class,
Val1Entity.class,
Val2Entity.class,
NotNullEntity.class
};
@DomainModel(
annotatedClasses = {
SingleTableNullNotNullDiscriminatorTest.RootEntity.class,
SingleTableNullNotNullDiscriminatorTest.Val1Entity.class,
SingleTableNullNotNullDiscriminatorTest.Val2Entity.class,
SingleTableNullNotNullDiscriminatorTest.NotNullEntity.class
}
)
@SessionFactory
public class SingleTableNullNotNullDiscriminatorTest {

@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session ->
session.createQuery( "delete from root_ent" ).executeUpdate()
);
}

@Test
public void test() {
inTransaction( session -> {
public void test(SessionFactoryScope scope) {
scope.inTransaction( session -> {
Val1Entity val1 = new Val1Entity();
val1.setId( 1L );

Expand All @@ -61,7 +71,7 @@ public void test() {
} );
} );

inTransaction( session -> {
scope.inTransaction( session -> {
Map<Long, RootEntity> entities = session.createQuery(
"select e from root_ent e", RootEntity.class )
.getResultList()
Expand All @@ -83,6 +93,8 @@ public static class RootEntity {
@Id
private Long id;

private String name;

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.reattachment;
package org.hibernate.orm.test.reattachment;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.reattachment;
package org.hibernate.orm.test.reattachment;


import org.hibernate.testing.orm.junit.DomainModel;
Expand All @@ -19,7 +19,7 @@
* @author Steve Ebersole
*/
@DomainModel(
xmlMappings = " org/hibernate/test/reattachment/Mappings.hbm.xml"
xmlMappings = "org/hibernate/orm/test/reattachment/Mappings.hbm.xml"
)
@SessionFactory
public class CollectionReattachmentTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="org.hibernate.test.reattachment">
<hibernate-mapping package="org.hibernate.orm.test.reattachment">

<class name="Parent">
<id name="name" column="NAME" type="string" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.reattachment;
package org.hibernate.orm.test.reattachment;
import java.util.HashSet;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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.reattachment;

import org.hibernate.testing.TestForIssue;
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.AfterEach;
import org.junit.jupiter.api.Test;

/**
* Test of proxy reattachment semantics
*
* @author Steve Ebersole
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/reattachment/Mappings.hbm.xml"
)
@SessionFactory
public class ProxyReattachmentTest {

@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete from Parent" ).executeUpdate();
session.createQuery( "delete from Child" ).executeUpdate();
}
);
}

@Test
public void testUpdateAfterEvict(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Parent p = new Parent( "p" );
session.save( p );
}
);

Parent parent = scope.fromTransaction(
session -> {
Parent p = session.load( Parent.class, "p" );
// evict...
session.evict( p );
// now try to reattach...
session.update( p );
return p;
}
);

scope.inTransaction(
session ->
session.delete( parent )
);
}

@Test
public void testUpdateAfterClear(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Parent p = new Parent( "p" );
session.save( p );
}
);

Parent parent = scope.fromTransaction(
session -> {
Parent p = session.load( Parent.class, "p" );
// clear...
session.clear();
// now try to reattach...
session.update( p );
return p;
}
);

scope.inTransaction(
session ->
session.delete( parent )
);
}


@Test
@TestForIssue(jiraKey = "HHH-8374")
public void testRemoveAndReattachProxyEntity(SessionFactoryScope scope) {
Parent p = new Parent( "foo" );
scope.inTransaction(
session -> {
session.persist( p );
}
);

scope.inTransaction(
session -> {
Parent parent = session.load( Parent.class, p.getName() );
session.delete( parent );
// re-attach
session.persist( parent );
}
);
}
}
Loading

0 comments on commit a648e63

Please sign in to comment.