Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions hibernate-core/src/test/java/NoPackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/
import org.hibernate.query.Query;

import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
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;

Expand All @@ -15,18 +17,20 @@
* We had problems with ByteBuddy in the past.
*/
@JiraKey(value = "HHH-13112")
public class NoPackageTest extends BaseCoreFunctionalTestCase {
@DomainModel(annotatedClasses = {AnnotationMappedNoPackageEntity.class})
@SessionFactory
public class NoPackageTest {

@Test
public void testNoException() {
inTransaction( session -> {
public void testNoException(SessionFactoryScope scope) {
scope.inTransaction( session -> {
AnnotationMappedNoPackageEntity box = new AnnotationMappedNoPackageEntity();
box.setId( 42 );
box.setName( "This feels dirty" );
session.persist( box );
} );

inTransaction( session -> {
scope.inTransaction( session -> {
Query<AnnotationMappedNoPackageEntity> query = session.createQuery(
"select e from " + AnnotationMappedNoPackageEntity.class.getSimpleName() + " e",
AnnotationMappedNoPackageEntity.class
Expand All @@ -35,11 +39,4 @@ public void testNoException() {
assertEquals( (Integer) 42, box.getId() );
} );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class[] {
AnnotationMappedNoPackageEntity.class
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/
package org.hibernate.bytecode.internal.bytebuddy;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ByteBuddyBasicProxyFactoryTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.hibernate.bytecode.enhance.spi.Enhancer;

import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Tests that bytecode can be enhanced when the original class cannot be loaded from
Expand All @@ -31,9 +31,9 @@ public void test() {
// Now use a fake class name so it won't be found in the ClassLoader
// provided by DefaultEnhancementContext
byte[] enhanced = enhancer.enhance( SimpleEntity.class.getName() + "Fake", buffer );
Assert.assertNotNull( "This is null when there have been swallowed exceptions during enhancement. Check Logs!", enhanced );
Assertions.assertNotNull( enhanced, "This is null when there have been swallowed exceptions during enhancement. Check Logs!" );
// Make sure enhanced bytecode is different from original bytecode.
Assert.assertFalse( Arrays.equals( buffer, enhanced ) );
Assertions.assertFalse( Arrays.equals( buffer, enhanced ) );
}

private byte[] readResource(Class<?> clazz) {
Expand All @@ -52,7 +52,7 @@ private byte[] readResource(Class<?> clazz) {
os.close();
}
catch (IOException ex) {
Assert.fail( "Should not have an IOException here" );
Assertions.fail( "Should not have an IOException here" );
}
return os.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.hibernate.bytecode.enhance.spi.Enhancer;

import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* WildFly will use class names in "internal JVM format" when invoking the enhancer,
Expand All @@ -34,10 +34,10 @@ public void test() {
buffer = readResource( resourceName );
}
catch (IOException e) {
Assert.fail( "Should not have an IOException here" );
Assertions.fail( "Should not have an IOException here" );
}
byte[] enhanced = enhancer.enhance( internalName, buffer );
Assert.assertNotNull( "This is null when there have been swallowed exceptions during enhancement. Check Logs!", enhanced );
Assertions.assertNotNull( enhanced, "This is null when there have been swallowed exceptions during enhancement. Check Logs!" );
}

private byte[] readResource(String resourceName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/
package org.hibernate.bytecode.internal.bytebuddy;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.lang.reflect.InvocationTargetException;

import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class GenerateProxiesTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author Steve Ebersole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.hibernate.bytecode.enhance.spi.EnhancementException;
import org.hibernate.bytecode.enhance.spi.Enhancer;
import org.hibernate.bytecode.spi.ByteCodeHelper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper;

import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Verifies that proxies being generated by ByteBuddyProxyHelper
* do not break the contract with PrimeAmongSecondarySupertypes.
Expand Down Expand Up @@ -58,36 +62,36 @@ private static Stream<Arguments> interfaces() {
public void testNamingConventions(Method m) {
final Class<?> returnType = m.getReturnType();
final String expectedMethodName = "as" + returnType.getSimpleName();
Assert.assertEquals( expectedMethodName, m.getName() );
Assert.assertNotNull( m.isDefault() );
assertEquals( expectedMethodName, m.getName() );
assertNotNull( m.isDefault() );
}

@ParameterizedTest
@MethodSource("superTypeMethods")
public void testAllsubInterfacesExtendTheSingleparent(Method m) {
final Class<?> returnType = m.getReturnType();
Assert.assertTrue( PrimeAmongSecondarySupertypes.class.isAssignableFrom( returnType ) );
assertTrue( PrimeAmongSecondarySupertypes.class.isAssignableFrom( returnType ) );
}

@ParameterizedTest
@MethodSource("superTypeMethods")
public void testSubInterfaceOverrides(Method m) throws NoSuchMethodException {
final Class<?> returnType = m.getReturnType();
final Method subMethod = returnType.getMethod( m.getName(), m.getParameterTypes() );
Assert.assertNotNull( subMethod );
Assert.assertNotNull( subMethod.isDefault() );
assertNotNull( subMethod );
assertNotNull( subMethod.isDefault() );
}

@Test
public void testHibernateProxyGeneration() {
ProxyFactory enhancer = createProxyFactory( SampleClass.class, HibernateProxy.class );
final Object proxy = enhancer.getProxy( Integer.valueOf( 1 ), null );
Assert.assertTrue( HibernateProxy.class.isAssignableFrom( proxy.getClass() ) );
Assert.assertTrue( proxy instanceof HibernateProxy );
assertTrue( HibernateProxy.class.isAssignableFrom( proxy.getClass() ) );
assertTrue( proxy instanceof HibernateProxy );
PrimeAmongSecondarySupertypes casted = (PrimeAmongSecondarySupertypes) proxy;
final HibernateProxy extracted = casted.asHibernateProxy();
Assert.assertNotNull( extracted );
Assert.assertSame( proxy, extracted );
assertNotNull( extracted );
Assertions.assertSame( proxy, extracted );
testForLIE( (SampleClass) proxy );
}

Expand All @@ -96,8 +100,8 @@ public void testHibernateProxyGeneration() {
*/
private void testForLIE(SampleClass sampleProxy) {
SampleClass other = new SampleClass();
Assert.assertEquals( 7, other.additionMethod( 3,4 ) );
Assert.assertThrows( LazyInitializationException.class, () -> sampleProxy.additionMethod( 3, 4 ) );
assertEquals( 7, other.additionMethod( 3,4 ) );
Assertions.assertThrows( LazyInitializationException.class, () -> sampleProxy.additionMethod( 3, 4 ) );
}

private ProxyFactory createProxyFactory(Class<?> persistentClass, Class<?>... interfaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
*/
package org.hibernate.dialect;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Map;

import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;

import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;

@RequiresDialect(H2Dialect.class)
@JiraKey(value = "HHH-17791")
public class H2DialectDatabaseVersionTest extends BaseUnitTestCase {
public class H2DialectDatabaseVersionTest {

@Test
public void snapshotVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

import java.util.Map;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;


import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RequiresDialect(MySQLDialect.class)
@JiraKey(value = "HHH-18518")
public class MySQLDialectDatabaseVersionTest extends BaseUnitTestCase {
public class MySQLDialectDatabaseVersionTest {

@Test
public void versionWithSuffix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;

import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Verifies that setting {@code AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY} to {@code none}
* is going to skip loading the sequence information from the database.
*/
@RequiresDialect( H2Dialect.class )
@JiraKey( value = "HHH-14667")
public class SkipLoadingSequenceInformationTest extends BaseCoreFunctionalTestCase {

@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, SequenceMismatchStrategy.NONE );
configuration.setProperty( Environment.DIALECT, VetoingDialect.class );
}
@DomainModel(annotatedClasses = {SkipLoadingSequenceInformationTest.SequencingEntity.class})
@SessionFactory
@ServiceRegistry(
settings = { @Setting( name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "NONE") },
settingProviders = { @SettingProvider( settingName = Environment.DIALECT, provider = SkipLoadingSequenceInformationTest.VetoingDialectClassProvider.class) }
)
public class SkipLoadingSequenceInformationTest {

@Entity(name="seqentity")
static class SequencingEntity {
Expand All @@ -51,11 +53,6 @@ static class SequencingEntity {
String name;
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{SequencingEntity.class};
}

@Test
public void test() {
// If it's able to boot, we're good.
Expand All @@ -68,4 +65,11 @@ public SequenceInformationExtractor getSequenceInformationExtractor() {
}
}

public static class VetoingDialectClassProvider implements SettingProvider.Provider<Class<?>> {
@Override
public Class<?> getSetting() {
return VetoingDialect.class;
}
}

}
Loading