Skip to content

[#678] Test for UUID as field type #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void longIdentifierWithStageAPI(TestContext context) {
@Test
public void shortIdentifierWithStageAPI(TestContext context) {
ShortEntity entityA = new ShortEntity( "Short A" );
ShortEntity entityB = new ShortEntity( "Long B" );
ShortEntity entityB = new ShortEntity( "Short B" );

Stage.Session session = openSession();
test( context, session
Expand All @@ -98,7 +98,6 @@ public void shortIdentifierWithStageAPI(TestContext context) {
* Mutiny API tests
*/


@Test
public void integerIdentifierWithMutinyAPI(TestContext context) {
IntegerEntity entityA = new IntegerEntity( "Integer A" );
Expand Down Expand Up @@ -138,7 +137,7 @@ public void longIdentifierWithMutinyAPI(TestContext context) {
@Test
public void shortIdentifierWithMutinyAPI(TestContext context) {
ShortEntity entityA = new ShortEntity( "Short A" );
ShortEntity entityB = new ShortEntity( "Long B" );
ShortEntity entityB = new ShortEntity( "Short B" );

Mutiny.Session session = openMutinySession();
test( context, session
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.reactive;

import java.util.Objects;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.mutiny.Mutiny;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static java.util.Arrays.asList;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
import static org.hibernate.reactive.testing.DatabaseSelectionRule.runOnlyFor;
import static org.hibernate.reactive.testing.DatabaseSelectionRule.skipTestsFor;

public abstract class UUIDAsBinaryType extends BaseReactiveTest {

public static class ForMySQLandMariaDBTest extends UUIDAsBinaryType {
// There's an issue querying for Binary types if the size of the column is different from
// the size of the parameter: see https://github.com/hibernate/hibernate-reactive/issues/678
@Rule
public DatabaseSelectionRule rule = runOnlyFor( MYSQL, MARIA );

@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
configuration.addAnnotatedClass( ExactSizeUUIDEntity.class );
return configuration;
}

@Test
public void exactSize(TestContext context) {
ExactSizeUUIDEntity entityA = new ExactSizeUUIDEntity( "Exact Size A" );
ExactSizeUUIDEntity entityB = new ExactSizeUUIDEntity( "Exact Size B" );

Mutiny.Session session = openMutinySession();
test( context, session
.persistAll( entityA, entityB )
.call( session::flush )
.invoke( () -> context.assertNotEquals( entityA.id, entityB.id ) )
.chain( () -> openMutinySession().find( ExactSizeUUIDEntity.class, entityA.id, entityB.id ) )
.invoke( list -> {
context.assertEquals( list.size(), 2 );
context.assertTrue( list.containsAll( asList( entityA, entityB ) ) );
} )
);
}

@Entity
private static class ExactSizeUUIDEntity {

@Id
@GeneratedValue
@Column(columnDefinition = "binary(16)")
UUID id;

@Column(unique = true)
String name;

public ExactSizeUUIDEntity() {
}

public ExactSizeUUIDEntity(String name) {
this.name = name;
}

@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
ExactSizeUUIDEntity that = (ExactSizeUUIDEntity) o;
return Objects.equals( name, that.name );
}

@Override
public int hashCode() {
return Objects.hash( name );
}

@Override
public String toString() {
return id + ":" + name;
}
}

}

public static class ForOtherDbsTest extends UUIDAsBinaryType {

@Rule
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA );

@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
configuration.addAnnotatedClass( UUIDEntity.class );
return configuration;
}

@Test
public void uuidIdentifierWithMutinyAPI(TestContext context) {
UUIDEntity entityA = new UUIDEntity( "UUID A" );
UUIDEntity entityB = new UUIDEntity( "UUID B" );

Mutiny.Session session = openMutinySession();
test( context, session
.persistAll( entityA, entityB )
.call( session::flush )
.invoke( () -> context.assertNotEquals( entityA.id, entityB.id ) )
.chain( () -> openMutinySession().find( UUIDEntity.class, entityA.id, entityB.id ) )
.invoke( list -> {
context.assertEquals( list.size(), 2 );
context.assertTrue( list.containsAll( asList( entityA, entityB ) ) );
} )
);
}

@Entity
private static class UUIDEntity {

@Id
@GeneratedValue
UUID id;

@Column(unique = true)
String name;

public UUIDEntity() {
}

public UUIDEntity(String name) {
this.name = name;
}

@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
UUIDEntity that = (UUIDEntity) o;
return Objects.equals( name, that.name );
}

@Override
public int hashCode() {
return Objects.hash( name );
}

@Override
public String toString() {
return id + ":" + name;
}
}
}
}