Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-11-29 19:03:42 +01:00 committed by Christian Beikov
parent 0fd83cf649
commit 9ef99082e1
10 changed files with 138 additions and 133 deletions

View File

@ -351,7 +351,7 @@ public class DomainResultCreationStateImpl
}
FetchBuilder explicitFetchBuilder = fetchBuilderResolverStack
.getCurrent()
.apply( fullPath );
.apply( fullPath );
final FetchBuilder fetchBuilder;
if ( explicitFetchBuilder != null ) {

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.various;
package org.hibernate.orm.test.annotations.various;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.various;
package org.hibernate.orm.test.annotations.various;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;

View File

@ -0,0 +1,37 @@
/*
* 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.annotations.various;
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.jupiter.api.Assertions.assertNull;
/**
* @author Emmanuel Bernard
*/
@DomainModel(
annotatedClasses = Antenna.class
)
@SessionFactory
public class GeneratedTest {
@Test
public void testGenerated(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Antenna antenna = new Antenna();
antenna.id = new Integer( 1 );
session.persist( antenna );
assertNull( antenna.latitude );
assertNull( antenna.longitude );
}
);
}
}

View File

@ -8,70 +8,80 @@ package org.hibernate.orm.test.annotations.various;
import java.util.Date;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.annotations.various.Conductor;
import org.hibernate.test.annotations.various.ProfessionalAgreement;
import org.hibernate.test.annotations.various.Truck;
import org.hibernate.test.annotations.various.Vehicule;
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;
/**
* @author Emmanuel Bernard
*/
public class IndexTest extends BaseCoreFunctionalTestCase {
@Test
public void testIndexManyToOne() throws Exception {
//TODO find a way to test indexes???
Session s = openSession();
s.getTransaction().begin();
Conductor emmanuel = new Conductor();
emmanuel.setName( "Emmanuel" );
s.persist( emmanuel );
Vehicule tank = new Vehicule();
tank.setCurrentConductor( emmanuel );
tank.setRegistrationNumber( "324VX43" );
s.persist( tank );
s.flush();
s.delete( tank );
s.delete( emmanuel );
s.getTransaction().rollback();
s.close();
}
@Test
public void testIndexAndJoined() throws Exception {
Session s = openSession();
s.getTransaction().begin();
Conductor cond = new Conductor();
cond.setName( "Bob" );
s.persist( cond );
ProfessionalAgreement agreement = new ProfessionalAgreement();
agreement.setExpirationDate( new Date() );
s.persist( agreement );
Truck truck = new Truck();
truck.setAgreement( agreement );
truck.setWeight( 20 );
truck.setRegistrationNumber( "2003424" );
truck.setYear( 2005 );
truck.setCurrentConductor( cond );
s.persist( truck );
s.flush();
s.delete( truck );
s.delete( agreement );
s.delete( cond );
s.getTransaction().rollback();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
@DomainModel(
annotatedClasses = {
Conductor.class,
Vehicule.class,
ProfessionalAgreement.class,
Truck.class
};
}
)
@SessionFactory
public class IndexTest {
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete from Conductor" ).executeUpdate();
session.createQuery( "delete from Vehicule" ).executeUpdate();
session.createQuery( "delete from ProfessionalAgreement" ).executeUpdate();
session.createQuery( "delete from Truck" ).executeUpdate();
}
);
}
@Test
public void testIndexManyToOne(SessionFactoryScope scope) {
//TODO find a way to test indexes???
scope.inTransaction(
session -> {
Conductor emmanuel = new Conductor();
emmanuel.setName( "Emmanuel" );
session.persist( emmanuel );
Vehicule tank = new Vehicule();
tank.setCurrentConductor( emmanuel );
tank.setRegistrationNumber( "324VX43" );
session.persist( tank );
session.flush();
session.delete( tank );
session.delete( emmanuel );
}
);
}
@Test
public void testIndexAndJoined(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Conductor cond = new Conductor();
cond.setName( "Bob" );
session.persist( cond );
ProfessionalAgreement agreement = new ProfessionalAgreement();
agreement.setExpirationDate( new Date() );
session.persist( agreement );
Truck truck = new Truck();
truck.setAgreement( agreement );
truck.setWeight( 20 );
truck.setRegistrationNumber( "2003424" );
truck.setYear( 2005 );
truck.setCurrentConductor( cond );
session.persist( truck );
session.flush();
session.delete( truck );
session.delete( agreement );
session.delete( cond );
}
);
}
}

View File

@ -6,50 +6,48 @@
*/
package org.hibernate.orm.test.annotations.various;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
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 org.hibernate.test.annotations.various.Conductor;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for the @OptimisticLock annotation.
*
* @author Emmanuel Bernard
*/
public class OptimisticLockAnnotationTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = Conductor.class
)
@SessionFactory
public class OptimisticLockAnnotationTest {
@Test
public void testOptimisticLockExcludeOnNameProperty() throws Exception {
Conductor c = new Conductor();
c.setName( "Bob" );
Session s = openSession();
s.getTransaction().begin();
s.persist( c );
s.flush();
public void testOptimisticLockExcludeOnNameProperty(SessionFactoryScope scope) {
s.clear();
c = ( Conductor ) s.get( Conductor.class, c.getId() );
Long version = c.getVersion();
c.setName( "Don" );
s.flush();
scope.inTransaction(
session -> {
Conductor c = new Conductor();
c.setName( "Bob" );
session.persist( c );
session.flush();
s.clear();
session.clear();
c = ( Conductor ) s.get( Conductor.class, c.getId() );
assertEquals( version, c.getVersion() );
c = session.get( Conductor.class, c.getId() );
Long version = c.getVersion();
c.setName( "Don" );
session.flush();
s.getTransaction().rollback();
s.close();
}
session.clear();
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Conductor.class
};
c = session.get( Conductor.class, c.getId() );
assertEquals( version, c.getVersion() );
}
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.various;
package org.hibernate.orm.test.annotations.various;
import java.util.Date;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.various;
package org.hibernate.orm.test.annotations.various;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.various;
package org.hibernate.orm.test.annotations.various;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;

View File

@ -1,40 +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.annotations.various;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertNull;
/**
* @author Emmanuel Bernard
*/
public class GeneratedTest extends BaseCoreFunctionalTestCase {
@Test
public void testGenerated() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Antenna antenna = new Antenna();
antenna.id = new Integer(1);
s.persist( antenna );
assertNull( antenna.latitude );
assertNull( antenna.longitude );
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Antenna.class
};
}
}