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.
|
||||
* 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.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -18,17 +22,16 @@ import javax.persistence.criteria.Path;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
/**
|
||||
* @author Jeremy Carnus
|
||||
* @author Guillaume Smet
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12989")
|
||||
public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCase {
|
||||
|
@ -41,29 +44,34 @@ public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCas
|
|||
|
||||
CriteriaQuery<Event> criteria = cb.createQuery( Event.class );
|
||||
|
||||
Root<Event> event = criteria.from( Event.class );
|
||||
Path<String> name = event.get( "name" );
|
||||
Root<Event> eventRoot = criteria.from( Event.class );
|
||||
Path<String> namePath = eventRoot.get( "name" );
|
||||
Path<String> tagPath = eventRoot.get( "tag" );
|
||||
|
||||
Expression<String> replaceName = cb.function(
|
||||
"replace",
|
||||
Expression<String> expression = cb.function(
|
||||
"lower",
|
||||
String.class,
|
||||
name,
|
||||
cb.literal( "a" ),
|
||||
cb.literal( "a" )
|
||||
);
|
||||
namePath );
|
||||
|
||||
criteria.select( event );
|
||||
criteria.where( name.in( Arrays.asList( replaceName, "1" ) ) );
|
||||
criteria.select( eventRoot );
|
||||
criteria.where( tagPath.in( Arrays.asList( expression, "my-tag" ) ) );
|
||||
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
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Event.class };
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{ Event.class };
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
|
@ -75,15 +83,24 @@ public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCas
|
|||
@Column
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
private String tag;
|
||||
|
||||
protected Event() {
|
||||
}
|
||||
|
||||
public Event(Long id, String name, String tag) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue