private Array getNewArray(String setType, BigInteger count, Object ...objects) { Array result = new Array(); result.setType(setType); result.setN(count); StringBuilder valueBldr = new StringBuilder(); for (Object o : objects) { if (setType.equalsIgnoreCase("string")) valueBldr.append("\'"); valueBldr.append(o.toString()); if (setType.equalsIgnoreCase("string")) valueBldr.append("\'"); valueBldr.append(" "); } result.setContent(valueBldr.toString()); return result; }
array.setType("string"); array.setN(BigInteger.valueOf(predicateAsString.split(",").length)); simpleSetPredicate.setArray(array);
@Test public void testSimpleStringSet() { Array array = new Array(); array.setType("string"); StringBuilder bldr = new StringBuilder(); for (int x = 0; x < 4; x++) { bldr.append("\"").append("testValue ").append(x).append("\" "); } array.setContent(bldr.toString()); array.setN(new BigInteger("4")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( \"testValue 0\" , \"testValue 1\" , \"testValue 2\" , \"testValue 3\" ) )"; doPredicateRetrieve(expected); }
@Test public void testSimpleRealSet() { Array array = new Array(); array.setType("real"); array.setContent("3.14 29.5 17 71"); array.setN(new BigInteger("4")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( 3.14, 29.5, 17.0, 71.0 ) )"; doPredicateRetrieve(expected); }
@Test(expected=IllegalStateException.class) public void testInvalidItemCount() { Array array = new Array(); array.setType("int"); array.setContent("1 33 45"); array.setN(new BigInteger("2")); predicate.setArray(array); // Note: Since we expect an exception it doesn't matter // what is passed as the expected value doPredicateRetrieve(null); }
@Test public void testSimpleIntSet() { Array array = new Array(); array.setType("int"); array.setContent("1 33 45"); array.setN(new BigInteger("3")); predicate.setArray(array); String expected = "( mTF1 == false ) && ( vTF1 in ( 1, 33, 45 ) )"; doPredicateRetrieve(expected); }
@Test public void testNegativeMembership() { Array array = new Array(); array.setType("real"); array.setContent("3.14 29.5 17 71"); array.setN(new BigInteger("4")); predicate.setArray(array); predicate.setBooleanOperator("isNotIn"); String expected = "( mTF1 == false ) && ( vTF1 not in ( 3.14, 29.5, 17.0, 71.0 ) )"; doPredicateRetrieve(expected); }