Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-11-29 16:40:20 +01:00 committed by Christian Beikov
parent 16460cf3ab
commit 91cc3d8d51
13 changed files with 229 additions and 217 deletions

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.type.dynamicparameterized;
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
import java.util.Date;

View File

@ -0,0 +1,78 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
import java.util.Date;
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.assertEquals;
/**
* @author Daniel Gredler
*/
@DomainModel(
annotatedClasses = { AbstractEntity.class, Entity1.class, Entity2.class }
)
@SessionFactory
public class DynamicParameterizedTypeTest {
@Test
public void testParameterValues(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Entity1 entity1 = new Entity1();
entity1.id = new Date( 0 );
Entity2 entity2 = new Entity2();
entity2.id = new Date( 0 );
session.persist( entity1 );
session.persist( entity2 );
session.flush();
session.clear();
entity1 = session.byId( Entity1.class ).load( entity1.id );
entity2 = session.byId( Entity2.class ).load( entity2.id );
assertEquals( "ENTITY1.PROP1", entity1.entity1_Prop1 );
assertEquals( "ENTITY1.PROP2", entity1.entity1_Prop2 );
assertEquals( "ENTITY1.PROP3.FOO", entity1.entity1_Prop3 );
assertEquals( "ENTITY1.PROP4.BAR", entity1.entity1_Prop4 );
assertEquals( "ENTITY1.PROP5", entity1.entity1_Prop5 );
assertEquals( "ENTITY1.PROP6", entity1.entity1_Prop6 );
assertEquals( "ENTITY2.PROP1", entity2.entity2_Prop1 );
assertEquals( "ENTITY2.PROP2", entity2.entity2_Prop2 );
assertEquals( "ENTITY2.PROP3", entity2.entity2_Prop3 );
assertEquals( "ENTITY2.PROP4", entity2.entity2_Prop4 );
assertEquals( "ENTITY2.PROP5.BLAH", entity2.entity2_Prop5 );
assertEquals( "ENTITY2.PROP6.YEAH", entity2.entity2_Prop6 );
}
);
}
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.type.dynamicparameterized;
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
import org.hibernate.annotations.CustomType;
import org.hibernate.annotations.Parameter;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.type.dynamicparameterized;
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
import org.hibernate.annotations.CustomType;
import org.hibernate.annotations.Parameter;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.type.dynamicparameterized;
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
import java.io.Serializable;
import java.sql.PreparedStatement;

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.annotations.uniqueconstraint;
package org.hibernate.orm.test.annotations.uniqueconstraint;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;

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.annotations.uniqueconstraint;
package org.hibernate.orm.test.annotations.uniqueconstraint;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;

View File

@ -4,10 +4,31 @@
* 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.uniqueconstraint;
package org.hibernate.orm.test.annotations.uniqueconstraint;
import java.util.List;
import java.util.stream.Collectors;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MariaDBDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@ -16,36 +37,18 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-11236")
@RequiresDialect(MySQL5Dialect.class)
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase {
@RequiresDialect(value = MySQLDialect.class, version = 500)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
@BaseUnitTest
public class MySQLDropConstraintThrowsExceptionTest {
@Before
@BeforeEach
public void setUp() {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -68,7 +71,7 @@ public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase {
}
}
@After
@AfterEach
public void tearDown() {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -94,7 +97,10 @@ public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase {
@Test
public void testEnumTypeInterpretation() {
final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( false, false );
final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(
false,
false
);
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -115,9 +121,17 @@ public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase {
.filter(
sql -> sql.toLowerCase().contains( "alter " )
).map( String::trim ).collect( Collectors.toList() );
assertTrue( alterStatements.get( 0 ).matches( "alter table CUSTOMER\\s+drop index .*?" ) );
assertTrue( alterStatements.get( 1 )
.matches( "alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)" ) );
if ( metadata.getDatabase().getDialect() instanceof MariaDBDialect ) {
assertTrue( alterStatements.get( 0 ).matches( "alter table if exists CUSTOMER\\s+drop index .*?" ) );
assertTrue( alterStatements.get( 1 )
.matches( "alter table if exists CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)" ) );
}
else {
assertTrue( alterStatements.get( 0 ).matches( "alter table CUSTOMER\\s+drop index .*?" ) );
assertTrue( alterStatements.get( 1 )
.matches( "alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)" ) );
}
}
finally {
if ( sessionFactory != null ) {

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.annotations.uniqueconstraint;
package org.hibernate.orm.test.annotations.uniqueconstraint;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;

View File

@ -0,0 +1,100 @@
/*
* 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.uniqueconstraint;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.Rule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import jakarta.persistence.PersistenceException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12688")
@RequiresDialect(H2Dialect.class)
@Jpa(
annotatedClasses = {
Room.class,
Building.class,
House.class
},
integrationSettings = @Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "5")
)
public class UniqueConstraintBatchingTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
Logger.getMessageLogger( CoreMessageLogger.class, SqlExceptionHelper.class.getName() ) );
private Triggerable triggerable;
@BeforeEach
public void setUp() {
triggerable = logInspection.watchForLogMessages( "Unique index" );
triggerable.reset();
}
@Test
public void testBatching(EntityManagerFactoryScope scope) throws Exception {
Room livingRoom = new Room();
scope.inTransaction(
entityManager -> {
livingRoom.setId( 1l );
livingRoom.setName( "livingRoom" );
entityManager.persist( livingRoom );
} );
scope.inTransaction(
entityManager -> {
House house = new House();
house.setId( 1l );
house.setCost( 100 );
house.setHeight( 1000l );
house.setRoom( livingRoom );
entityManager.persist( house );
} );
try {
scope.inTransaction(
entityManager -> {
House house2 = new House();
house2.setId( 2l );
house2.setCost( 100 );
house2.setHeight( 1001l );
house2.setRoom( livingRoom );
entityManager.persist( house2 );
} );
fail( "Should throw exception" );
}
catch (PersistenceException e) {
assertEquals( 1, triggerable.triggerMessages().size() );
assertTrue( triggerable.triggerMessage().startsWith( "Unique index or primary key violation" ) );
}
}
}

View File

@ -12,9 +12,6 @@ import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.annotations.uniqueconstraint.Building;
import org.hibernate.test.annotations.uniqueconstraint.House;
import org.hibernate.test.annotations.uniqueconstraint.Room;
import org.junit.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;

View File

@ -1,81 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.type.dynamicparameterized;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Daniel Gredler
*/
public class DynamicParameterizedTypeTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { AbstractEntity.class, Entity1.class, Entity2.class };
}
@Test
public void testParameterValues() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Entity1 entity1 = new Entity1();
entity1.id = new Date( 0 );
Entity2 entity2 = new Entity2();
entity2.id = new Date( 0 );
s.persist( entity1 );
s.persist( entity2 );
s.flush();
s.clear();
entity1 = (Entity1) s.byId( Entity1.class ).load( entity1.id );
entity2 = (Entity2) s.byId( Entity2.class ).load( entity2.id );
Assert.assertEquals( "ENTITY1.PROP1", entity1.entity1_Prop1 );
Assert.assertEquals( "ENTITY1.PROP2", entity1.entity1_Prop2 );
Assert.assertEquals( "ENTITY1.PROP3.FOO", entity1.entity1_Prop3 );
Assert.assertEquals( "ENTITY1.PROP4.BAR", entity1.entity1_Prop4 );
Assert.assertEquals( "ENTITY1.PROP5", entity1.entity1_Prop5 );
Assert.assertEquals( "ENTITY1.PROP6", entity1.entity1_Prop6 );
Assert.assertEquals( "ENTITY2.PROP1", entity2.entity2_Prop1 );
Assert.assertEquals( "ENTITY2.PROP2", entity2.entity2_Prop2 );
Assert.assertEquals( "ENTITY2.PROP3", entity2.entity2_Prop3 );
Assert.assertEquals( "ENTITY2.PROP4", entity2.entity2_Prop4 );
Assert.assertEquals( "ENTITY2.PROP5.BLAH", entity2.entity2_Prop5 );
Assert.assertEquals( "ENTITY2.PROP6.YEAH", entity2.entity2_Prop6 );
tx.rollback();
s.close();
}
}

View File

@ -1,96 +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.uniqueconstraint;
import java.util.Map;
import jakarta.persistence.PersistenceException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.junit.Rule;
import org.junit.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12688")
@RequiresDialect(H2Dialect.class)
public class UniqueConstraintBatchingTest extends BaseEntityManagerFunctionalTestCase {
protected Class[] getAnnotatedClasses() {
return new Class[] {
Room.class,
Building.class,
House.class
};
}
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
Logger.getMessageLogger( CoreMessageLogger.class, SqlExceptionHelper.class.getName() ) );
private Triggerable triggerable;
@Override
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.STATEMENT_BATCH_SIZE, 5 );
triggerable = logInspection.watchForLogMessages( "Unique index" );
triggerable.reset();
}
@Test
public void testBatching() throws Exception {
Room livingRoom = new Room();
doInJPA( this::entityManagerFactory, entityManager -> {
livingRoom.setId( 1l );
livingRoom.setName( "livingRoom" );
entityManager.persist( livingRoom );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
House house = new House();
house.setId( 1l );
house.setCost( 100 );
house.setHeight( 1000l );
house.setRoom( livingRoom );
entityManager.persist( house );
} );
try {
doInJPA( this::entityManagerFactory, entityManager -> {
House house2 = new House();
house2.setId( 2l );
house2.setCost( 100 );
house2.setHeight( 1001l );
house2.setRoom( livingRoom );
entityManager.persist( house2 );
} );
fail( "Should throw exception" );
}
catch (PersistenceException e) {
assertEquals( 1, triggerable.triggerMessages().size() );
assertTrue( triggerable.triggerMessage().startsWith( "Unique index or primary key violation" ) );
}
}
}