HHH-12989 Make the test prove that everything is really working as expected
This commit is contained in:
parent
d922452307
commit
439ce293da
|
@ -4,10 +4,14 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.criteria.internal;
|
package org.hibernate.jpa.test.criteria.basic;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -18,17 +22,16 @@ import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jeremy Carnus
|
* @author Jeremy Carnus
|
||||||
|
* @author Guillaume Smet
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-12989")
|
@TestForIssue(jiraKey = "HHH-12989")
|
||||||
public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCase {
|
public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
@ -41,29 +44,34 @@ public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCas
|
||||||
|
|
||||||
CriteriaQuery<Event> criteria = cb.createQuery( Event.class );
|
CriteriaQuery<Event> criteria = cb.createQuery( Event.class );
|
||||||
|
|
||||||
Root<Event> event = criteria.from( Event.class );
|
Root<Event> eventRoot = criteria.from( Event.class );
|
||||||
Path<String> name = event.get( "name" );
|
Path<String> namePath = eventRoot.get( "name" );
|
||||||
|
Path<String> tagPath = eventRoot.get( "tag" );
|
||||||
|
|
||||||
Expression<String> replaceName = cb.function(
|
Expression<String> expression = cb.function(
|
||||||
"replace",
|
"lower",
|
||||||
String.class,
|
String.class,
|
||||||
name,
|
namePath );
|
||||||
cb.literal( "a" ),
|
|
||||||
cb.literal( "a" )
|
|
||||||
);
|
|
||||||
|
|
||||||
criteria.select( event );
|
criteria.select( eventRoot );
|
||||||
criteria.where( name.in( Arrays.asList( replaceName, "1" ) ) );
|
criteria.where( tagPath.in( Arrays.asList( expression, "my-tag" ) ) );
|
||||||
List<Event> resultList = session.createQuery( criteria ).getResultList();
|
List<Event> resultList = session.createQuery( criteria ).getResultList();
|
||||||
|
|
||||||
Assert.assertNotNull( resultList );
|
Assert.assertEquals( 2, resultList.size() );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
|
session.save( new Event( 1L, "EventName1", "EventName1".toLowerCase( Locale.ROOT ) ) );
|
||||||
|
session.save( new Event( 2L, "EventName2", "my-tag" ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[] { Event.class };
|
return new Class[]{ Event.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "Event")
|
@Entity(name = "Event")
|
||||||
|
@ -75,15 +83,24 @@ public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCas
|
||||||
@Column
|
@Column
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String tag;
|
||||||
|
|
||||||
protected Event() {
|
protected Event() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Event(Long id, String name, String tag) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public String getTag() {
|
||||||
this.name = name;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue