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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
*/ */
//$Id$ //$Id$
package org.hibernate.test.annotations.various; package org.hibernate.orm.test.annotations.various;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; 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
};
}
}