diff --git a/README.md b/README.md index e5223cf..3836757 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Build Status](https://travis-ci.org/RutledgePaulV/q-builders.svg)](https://travis-ci.org/RutledgePaulV/q-builders) [![Coverage Status](https://coveralls.io/repos/RutledgePaulV/q-builders/badge.svg?branch=master&service=github)](https://coveralls.io/github/RutledgePaulV/q-builders?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.rutledgepaulv/q-builders/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.rutledgepaulv/q-builders) +[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/RutledgePaulV/q-builders) ### Overview A generic abstraction for building queries for arbitrary domain models that minimizes diff --git a/pom.xml b/pom.xml index 540ca20..bbfc3a0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,28 +2,19 @@ 4.0.0 - com.github.rutledgepaulv + + com.github.rutledgepaulv + maven + 1.1 + + q-builders - 1.1 + 1.2 q-builders http://github.com/rutledgepaulv/q-builders A type-safe and database agnostic query building library. - - - Paul Rutledge - paul.v.rutledge@gmail.com - - - - - - MIT - http://opensource.org/licenses/MIT - - - http://github.com/rutledgepaulv/q-builders scm:git:git@github.com:rutledgepaulv/q-builders.git @@ -39,115 +30,6 @@ https://github.com/rutledgepaulv/q-builders/issues - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - 1.8 - UTF-8 - - - - - release - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - - - - - - - - external.atlassian.jgitflow - jgitflow-maven-plugin - 1.0-m5.1 - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - org.eluder.coveralls - coveralls-maven-plugin - 4.0.0 - - - org.jacoco - jacoco-maven-plugin - 0.7.5.201505241946 - - - prepare-agent - - prepare-agent - - - - - - - - @@ -174,13 +56,6 @@ true - - junit - junit - 4.12 - test - - cz.jirutka.rsql rsql-parser diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/builders/QBuilder.java b/src/main/java/com/github/rutledgepaulv/qbuilders/builders/QBuilder.java index c76d26f..9b74205 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/builders/QBuilder.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/builders/QBuilder.java @@ -33,8 +33,11 @@ public class QBuilder> implements Partial { private LogicalNode current; public QBuilder() { - root = new OrNode(null, new ArrayList<>()); - current = root; + root = current = new OrNode(); + } + + public final > EnumProperty enumeration(String field) { + return prop(field, EnumPropertyDelegate.class, EnumProperty.class); } public final BooleanProperty bool(String field) { @@ -69,11 +72,11 @@ public final InstantProperty instant(String field) { return prop(field, InstantPropertyDelegate.class, InstantProperty.class); } - public > ConditionProperty condition(String field) { + public final > ConditionProperty condition(String field) { return prop(field, ConditionPropertyDelegate.class, ConditionProperty.class); } - public final , Q extends Property> Q prop(String field, Class delegate, Class inter) { + protected final , Q extends Property> Q prop(String field, Class delegate, Class inter) { if(!inter.isAssignableFrom(delegate)) { throw new IllegalArgumentException("Must provide a delegate that implements the interface to be returned."); } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/conditions/Partial.java b/src/main/java/com/github/rutledgepaulv/qbuilders/conditions/Partial.java index 4b7eb28..04214b3 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/conditions/Partial.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/conditions/Partial.java @@ -14,6 +14,15 @@ */ public interface Partial> { + /** + * For usage when the field is known to contain values of an enum type. + * + * @param field The name of the field. + * + * @return The property interface so that a constraint can be set against the field. + */ + > EnumProperty enumeration(String field); + /** * For usage when the field is known to contain values of a boolean type. * diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/delegates/concrete/EnumPropertyDelegate.java b/src/main/java/com/github/rutledgepaulv/qbuilders/delegates/concrete/EnumPropertyDelegate.java new file mode 100644 index 0000000..b97c3ad --- /dev/null +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/delegates/concrete/EnumPropertyDelegate.java @@ -0,0 +1,14 @@ +package com.github.rutledgepaulv.qbuilders.delegates.concrete; + +import com.github.rutledgepaulv.qbuilders.builders.QBuilder; +import com.github.rutledgepaulv.qbuilders.delegates.virtual.ListablePropertyDelegate; +import com.github.rutledgepaulv.qbuilders.properties.concrete.EnumProperty; + +public final class EnumPropertyDelegate, S extends Enum> + extends ListablePropertyDelegate implements EnumProperty { + + public EnumPropertyDelegate(String field, T canonical) { + super(field, canonical); + } + +} diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AbstractNode.java b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AbstractNode.java index 08aa584..8223479 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AbstractNode.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AbstractNode.java @@ -2,38 +2,21 @@ import com.github.rutledgepaulv.qbuilders.visitors.NodeVisitor; -import java.util.ArrayList; -import java.util.List; - public abstract class AbstractNode implements Visitable { - private AbstractNode parent; - private List children = new ArrayList<>(); + private LogicalNode parent; - public AbstractNode(AbstractNode parent) { - this.parent = parent; - } + public AbstractNode() {} - public AbstractNode(AbstractNode parent, List children) { + public AbstractNode(LogicalNode parent) { this.parent = parent; - setChildren(children); - } - - public List getChildren() { - return children; } - public void setChildren(List children) { - this.children = children; - children.forEach(child -> child.setParent(this)); - } - - - public AbstractNode getParent() { + public LogicalNode getParent() { return parent; } - public void setParent(AbstractNode parent) { + public void setParent(LogicalNode parent) { this.parent = parent; } @@ -41,4 +24,5 @@ public void setParent(AbstractNode parent) { public T visit(NodeVisitor visitor) { return visitor.visitAny(this); } + } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AndNode.java b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AndNode.java index 6210454..b2cfdfc 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AndNode.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/AndNode.java @@ -4,7 +4,13 @@ public final class AndNode extends LogicalNode { - public AndNode(AbstractNode parent, List children) { + public AndNode() {} + + public AndNode(LogicalNode parent) { + super(parent); + } + + public AndNode(LogicalNode parent, List children) { super(parent, children); } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/ComparisonNode.java b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/ComparisonNode.java index 22c5236..c20e551 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/ComparisonNode.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/ComparisonNode.java @@ -10,7 +10,7 @@ public final class ComparisonNode extends AbstractNode { private ComparisonOperator operator; private Collection values; - public ComparisonNode(AbstractNode parent) { + public ComparisonNode(LogicalNode parent) { super(parent); } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/LogicalNode.java b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/LogicalNode.java index 4d9d981..634b5fd 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/LogicalNode.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/LogicalNode.java @@ -1,11 +1,31 @@ package com.github.rutledgepaulv.qbuilders.nodes; +import java.util.LinkedList; import java.util.List; public abstract class LogicalNode extends AbstractNode { - public LogicalNode(AbstractNode parent, List children) { - super(parent, children); + private List children = new LinkedList<>(); + + public LogicalNode() {} + + public LogicalNode(LogicalNode parent) { + super(parent); } + public LogicalNode(LogicalNode parent, List children) { + super(parent); + setChildren(children); + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + children.forEach(child -> child.setParent(this)); + } + + } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/OrNode.java b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/OrNode.java index 410f26e..9d64c7b 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/OrNode.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/nodes/OrNode.java @@ -4,8 +4,15 @@ public final class OrNode extends LogicalNode { - public OrNode(AbstractNode parent, List children) { + public OrNode() {} + + public OrNode(LogicalNode parent) { + super(parent); + } + + public OrNode(LogicalNode parent, List children) { super(parent, children); } + } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/properties/concrete/EnumProperty.java b/src/main/java/com/github/rutledgepaulv/qbuilders/properties/concrete/EnumProperty.java new file mode 100644 index 0000000..3a3b337 --- /dev/null +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/properties/concrete/EnumProperty.java @@ -0,0 +1,13 @@ +package com.github.rutledgepaulv.qbuilders.properties.concrete; + +import com.github.rutledgepaulv.qbuilders.builders.QBuilder; +import com.github.rutledgepaulv.qbuilders.properties.virtual.EquitableProperty; +import com.github.rutledgepaulv.qbuilders.properties.virtual.ListableProperty; + +/** + * A property view for fields with {@link Enum} values. + * + * @param The type of the final builder. + */ +public interface EnumProperty, S extends Enum> + extends ListableProperty, EquitableProperty {} diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/utilities/ObjectUtils.java b/src/main/java/com/github/rutledgepaulv/qbuilders/utilities/ObjectUtils.java index a3f34d6..16e2eb1 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/utilities/ObjectUtils.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/utilities/ObjectUtils.java @@ -7,8 +7,6 @@ @SuppressWarnings({"unchecked", "Convert2MethodRef"}) public final class ObjectUtils { - private ObjectUtils(){} - /** * Instantiate a class for the provided constructor arguments. diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/ElasticsearchVisitor.java b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/ElasticsearchVisitor.java index f226823..ceb8404 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/ElasticsearchVisitor.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/ElasticsearchVisitor.java @@ -77,13 +77,4 @@ protected QueryBuilder visit(ComparisonNode node) { throw new UnsupportedOperationException("This visitor does not support the operator " + operator + "."); } - - protected Object single(Collection values) { - if (!values.isEmpty()) { - return values.iterator().next(); - } else { - throw new IllegalArgumentException("You must provide a query value for the condition."); - } - } - } diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java index e7dd9f9..06d0a0b 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java @@ -77,16 +77,6 @@ protected Criteria visit(ComparisonNode node) { } - protected Object single(Collection values) { - if(!values.isEmpty()) { - return values.iterator().next(); - } else { - throw new IllegalArgumentException("You must provide a non-null query value for the condition."); - } - } - - - protected static class DefaultNormalizer implements Function { protected static DefaultNormalizer INSTANCE = new DefaultNormalizer(); diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/NodeVisitor.java b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/NodeVisitor.java index 8228dbe..e04a18c 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/NodeVisitor.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/NodeVisitor.java @@ -5,6 +5,8 @@ import com.github.rutledgepaulv.qbuilders.nodes.*; import com.github.rutledgepaulv.qbuilders.operators.ComparisonOperator; +import java.util.Collection; + @SuppressWarnings("ConstantConditions") public abstract class NodeVisitor { @@ -42,12 +44,23 @@ protected final T condition(ComparisonNode node) { } + protected Object single(Collection values) { + if(!values.isEmpty()) { + return values.iterator().next(); + } else { + throw new IllegalArgumentException("You must provide a non-null query value for the condition."); + } + } + public final T visitAny(AbstractNode node) { // skip straight to the children if it's a logical node with one member - if(node instanceof LogicalNode && node.getChildren().size() == 1) { - return visitAny(node.getChildren().get(0)); + if(node instanceof LogicalNode) { + LogicalNode logical = (LogicalNode) node; + if(logical.getChildren().size() == 1) { + return visitAny(logical.getChildren().get(0)); + } } if(node instanceof AndNode){ diff --git a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitor.java b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitor.java index 462e930..f090d0c 100644 --- a/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitor.java +++ b/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitor.java @@ -6,8 +6,10 @@ import com.github.rutledgepaulv.qbuilders.nodes.OrNode; import com.github.rutledgepaulv.qbuilders.operators.ComparisonOperator; +import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; + +import static java.util.stream.Collectors.joining; @SuppressWarnings("WeakerAccess") public class RSQLVisitor extends NodeVisitor { @@ -24,13 +26,13 @@ public RSQLVisitor(Function serializationStrategy) { @Override protected String visit(AndNode node) { - String body = node.getChildren().stream().map(this::visitAny).collect(Collectors.joining(";")); + String body = node.getChildren().stream().map(this::visitAny).collect(joining(";")); return nodeBelongsToParentExpression(node) ? "(" + body + ")" : body; } @Override protected String visit(OrNode node) { - String body = node.getChildren().stream().map(this::visitAny).collect(Collectors.joining(",")); + String body = node.getChildren().stream().map(this::visitAny).collect(joining(",")); return nodeBelongsToParentExpression(node) ? "(" + body + ")" : body; } @@ -69,12 +71,12 @@ protected boolean nodeBelongsToParentExpression(AbstractNode node) { } protected String single(ComparisonNode node, String op) { - return node.getField() + op + serialize(node.getValues().iterator().next()); + return node.getField() + op + serialize(single(node.getValues())); } protected String list(ComparisonNode node, String op) { return node.getField() + op + node.getValues().stream() - .map(this::serialize).collect(Collectors.joining(",", "(", ")")); + .map(this::serialize).collect(joining(",", "(", ")")); } protected String serialize(Object value) { @@ -91,26 +93,26 @@ protected static class DefaultSerializationStrategy implements Function { public MongoVisitorTest() { + Enum_EQ = "{ \"myEnum\" : \"VALUE1\"}"; + Enum_NE = "{ \"myEnum\" : { \"$ne\" : \"VALUE1\"}}"; + Enum_EX = "{ \"myEnum\" : { \"$exists\" : true}}"; + Enum_DNE = "{ \"myEnum\" : { \"$exists\" : false}}"; + Enum_IN = "{ \"myEnum\" : { \"$in\" : [ \"VALUE1\" , \"VALUE2\" , \"VALUE3\"]}}"; + Enum_NIN = "{ \"myEnum\" : { \"$nin\" : [ \"VALUE1\" , \"VALUE2\" , \"VALUE3\"]}}"; + String_EQ = "{ \"myString\" : \"abcdefg\"}"; String_NE = "{ \"myString\" : { \"$ne\" : \"abcdefg\"}}"; String_LT = "{ \"myString\" : { \"$lt\" : \"abcdefg\"}}"; @@ -160,7 +168,7 @@ protected MongoVisitor getVisitor() { @Override protected void compare(String expected, Criteria converted) { - assertEquals(expected, converted.getCriteriaObject().toString()); + assertEquals(expected, new CriteriaSerializer().apply(converted)); } } diff --git a/src/test/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitorTest.java b/src/test/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitorTest.java index 3709846..d8d6c1c 100644 --- a/src/test/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitorTest.java +++ b/src/test/java/com/github/rutledgepaulv/qbuilders/visitors/RSQLVisitorTest.java @@ -19,6 +19,14 @@ public class RSQLVisitorTest extends QBuilderTestBase { public RSQLVisitorTest() { + + Enum_EQ = "myEnum==\"VALUE1\""; + Enum_NE = "myEnum!=\"VALUE1\""; + Enum_EX = "myEnum=ex=\"true\""; + Enum_DNE = "myEnum=ex=\"false\""; + Enum_IN = "myEnum=in=(\"VALUE1\",\"VALUE2\",\"VALUE3\")"; + Enum_NIN = "myEnum=out=(\"VALUE1\",\"VALUE2\",\"VALUE3\")"; + String_EQ = "myString==\"abcdefg\""; String_NE = "myString!=\"abcdefg\""; String_LT = "myString=lt=\"abcdefg\""; diff --git a/src/test/java/com/github/rutledgepaulv/testsupport/CriteriaSerializer.java b/src/test/java/com/github/rutledgepaulv/testsupport/CriteriaSerializer.java new file mode 100644 index 0000000..991dae3 --- /dev/null +++ b/src/test/java/com/github/rutledgepaulv/testsupport/CriteriaSerializer.java @@ -0,0 +1,41 @@ +package com.github.rutledgepaulv.testsupport; + +import com.mongodb.DBObject; +import org.springframework.data.mongodb.core.query.Criteria; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Spring doesn't know how to serialize enums on a toString call + */ +public class CriteriaSerializer implements Function { + + @Override + public String apply(Criteria criteria) { + return applyInternal(criteria.getCriteriaObject()).toString(); + } + + private DBObject applyInternal(DBObject object) { + object.keySet().stream().forEach(key -> + object.put(key, object.get(key) instanceof Enum ? + object.get(key).toString() : object.get(key) instanceof DBObject ? + applyInternal((DBObject) object.get(key)) : object.get(key) instanceof Collection ? + applyList((Collection)object.get(key)) : object.get(key))); + + return object; + } + + + private List applyList(Collection items) { + return items.stream().map(item -> { + if (item instanceof Enum) { + return Objects.toString(item); + } else { + return item; + }}).collect(Collectors.toList()); + } +} diff --git a/src/test/java/com/github/rutledgepaulv/testsupport/DomainModel.java b/src/test/java/com/github/rutledgepaulv/testsupport/DomainModel.java index fe0f8f3..eb4ff09 100644 --- a/src/test/java/com/github/rutledgepaulv/testsupport/DomainModel.java +++ b/src/test/java/com/github/rutledgepaulv/testsupport/DomainModel.java @@ -7,6 +7,13 @@ public class DomainModel { + public enum MyEnum { + VALUE1, + VALUE2, + VALUE3 + } + + private MyEnum myEnum; private Byte myByte; private Float myFloat; private Double myDouble; @@ -91,6 +98,13 @@ public void setMyListOfStrings(List myListOfStrings) { this.myListOfStrings = myListOfStrings; } + public MyEnum getMyEnum() { + return myEnum; + } + + public void setMyEnum(MyEnum myEnum) { + this.myEnum = myEnum; + } public String getMyString2() { return myString2; @@ -110,6 +124,7 @@ public void setMySubList(List mySubList) { public DomainModel copy() { DomainModel domainModel = new DomainModel(); + domainModel.setMyEnum(getMyEnum()); domainModel.setMyByte(getMyByte()); domainModel.setMyCharacter(getMyCharacter()); domainModel.setMyDouble(getMyDouble()); @@ -143,12 +158,13 @@ public boolean equals(Object o) { Objects.equals(myString2, domainModel.myString2) && Objects.equals(myCharacter, domainModel.myCharacter) && Objects.equals(mySubList, domainModel.mySubList) && + Objects.equals(myEnum, domainModel.myEnum) && Objects.equals(myListOfStrings, domainModel.myListOfStrings); } @Override public int hashCode() { - return Objects.hash(myByte, myFloat, myDouble, myLong, myInteger, myShort, myString, myString2, myCharacter, + return Objects.hash(myByte, myFloat, myDouble, myEnum, myLong, myInteger, myShort, myString, myString2, myCharacter, mySubList, myListOfStrings); } } diff --git a/src/test/java/com/github/rutledgepaulv/testsupport/QBuilderTestBase.java b/src/test/java/com/github/rutledgepaulv/testsupport/QBuilderTestBase.java index 0cff3f7..5537c4a 100644 --- a/src/test/java/com/github/rutledgepaulv/testsupport/QBuilderTestBase.java +++ b/src/test/java/com/github/rutledgepaulv/testsupport/QBuilderTestBase.java @@ -7,6 +7,10 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; +import static com.github.rutledgepaulv.testsupport.DomainModel.MyEnum.VALUE1; +import static com.github.rutledgepaulv.testsupport.DomainModel.MyEnum.VALUE2; +import static com.github.rutledgepaulv.testsupport.DomainModel.MyEnum.VALUE3; + public abstract class QBuilderTestBase, S> { @@ -28,6 +32,15 @@ interface String { Condition NIN = QueryModel.QueryModelPredef.myString().nin("d", "e", "f"); } + interface Enum { + Condition EQ = QueryModel.QueryModelPredef.myEnum().eq(VALUE1); + Condition NE = QueryModel.QueryModelPredef.myEnum().ne(VALUE1); + Condition EX = QueryModel.QueryModelPredef.myEnum().exists(); + Condition DNE = QueryModel.QueryModelPredef.myEnum().doesNotExist(); + Condition IN = QueryModel.QueryModelPredef.myEnum().in(VALUE1, VALUE2, VALUE3); + Condition NIN = QueryModel.QueryModelPredef.myEnum().nin(VALUE1, VALUE2, VALUE3); + } + interface Boolean { Condition TRUE = QueryModel.QueryModelPredef.myBoolean().isTrue(); Condition FALSE = QueryModel.QueryModelPredef.myBoolean().isFalse(); @@ -175,6 +188,23 @@ protected interface VariedInputs { Condition NULL_INEQUALITY = QueryModel.QueryModelPredef.myString().ne(null); } + protected String Enum_EQ; + protected String Enum_NE; + protected String Enum_EX; + protected String Enum_DNE; + protected String Enum_IN; + protected String Enum_NIN; + + @Test + public void simple_Enum() { + compare(Enum_EQ, Simple.Enum.EQ); + compare(Enum_NE, Simple.Enum.NE); + compare(Enum_EX, Simple.Enum.EX); + compare(Enum_DNE, Simple.Enum.DNE); + compare(Enum_IN, Simple.Enum.IN); + compare(Enum_NIN, Simple.Enum.NIN); + } + protected String String_EQ; protected String String_NE; protected String String_LT; diff --git a/src/test/java/com/github/rutledgepaulv/testsupport/QueryModel.java b/src/test/java/com/github/rutledgepaulv/testsupport/QueryModel.java index 437bef4..c467fb4 100644 --- a/src/test/java/com/github/rutledgepaulv/testsupport/QueryModel.java +++ b/src/test/java/com/github/rutledgepaulv/testsupport/QueryModel.java @@ -61,6 +61,14 @@ public static InstantProperty myDateTime() { public static ConditionProperty mySubList() { return new QueryModel().mySubList(); } + + public static EnumProperty myEnum() { + return new QueryModel().myEnum(); + } + } + + public EnumProperty myEnum() { + return enumeration(getCurrentMethodName()); } private StringProperty myString2() {