Skip to content

Commit

Permalink
CAY-2860 Translate (not)in expression with empty values
Browse files Browse the repository at this point in the history
 - add tests
  • Loading branch information
stariy95 committed Jun 19, 2024
1 parent 2526497 commit 5afdb92
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public void testInExp3() {
assertEquals(Expression.FALSE, exp.getType());
}

@Test
public void testInExpEmpty() {
Expression in = ExpressionFactory.inExp("abc", List.of());
assertEquals(ExpressionFactory.expFalse(), in);
}

@Test
public void testNotInExp1() {
Expression exp = ExpressionFactory.notInExp("abc", "a", "b");
Expand All @@ -212,6 +218,12 @@ public void testNotInExp3() {
assertEquals(Expression.TRUE, exp.getType());
}

@Test
public void testNotInExpEmpty() {
Expression in = ExpressionFactory.notInExp("abc", List.of());
assertEquals(ExpressionFactory.expTrue(), in);
}

@Test
public void testLikeExp() {
String v = "abc";
Expand Down
28 changes: 27 additions & 1 deletion cayenne/src/test/java/org/apache/cayenne/exp/ExpressionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.exp.parser.ASTIn;
import org.apache.cayenne.exp.parser.ASTList;
import org.apache.cayenne.exp.parser.SimpleNode;
import org.apache.cayenne.query.ObjectSelect;
import org.apache.cayenne.runtime.CayenneRuntime;
import org.apache.cayenne.testdo.testmap.Artist;
Expand All @@ -31,6 +34,7 @@
import org.apache.cayenne.unit.di.runtime.CayenneProjects;
import org.apache.cayenne.unit.di.runtime.RuntimeCase;
import org.apache.cayenne.unit.di.runtime.UseCayenneRuntime;
import org.junit.Ignore;
import org.junit.Test;

import java.util.ArrayList;
Expand Down Expand Up @@ -96,7 +100,7 @@ public void testMatch() {

@Test
public void testFirst() {
List<Painting> paintingList = new ArrayList<Painting>();
List<Painting> paintingList = new ArrayList<>();
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("x1");
paintingList.add(p1);
Expand Down Expand Up @@ -158,6 +162,28 @@ public void testInNull() {
assertEquals(1, artists.size());
}

@Test
public void testInEmpty() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("Picasso");
context.commitChanges();

List<Artist> artists = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.in(List.of())).select(context);
assertTrue(artists.isEmpty());
}

@Test
@Ignore("see https://issues.apache.org/jira/browse/CAY-2860")
public void testExplicitInEmpty() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("Picasso");
context.commitChanges();

ASTIn in = new ASTIn((SimpleNode) Artist.ARTIST_NAME.getExpression(), new ASTList(List.of()));
List<Artist> artists = ObjectSelect.query(Artist.class, in).select(context);
assertTrue(artists.isEmpty());
}

/**
* We are waiting invalid SQL here:
* data type of expression is not boolean in statement
Expand Down

0 comments on commit 5afdb92

Please sign in to comment.