RangeExtension implements CustomTagExtension<RangeExtension.RangeTag> { public List<Map<String, String>> pipelinePossibleStates(RangeTag action, List<Map<String, String>> possibleStateList) { String variable = action.getName(); BigDecimal from = new BigDecimal(action.getFrom()); BigDecimal to = new BigDecimal(action.getTo()); BigDecimal step; if (action.getStep() != null) { step = new BigDecimal(action.getStep()); } else { step = BigDecimal.ONE; } List<BigDecimal> rangeValues = new ArrayList<>(); if (step.signum() == 1) { for (BigDecimal current = from; current.compareTo(to) <= 0; current = current.add(step)) { rangeValues.add(current); } } else if (step.signum() == -1) { for (BigDecimal current = from; current.compareTo(to) >= 0; current = current.add(step)) { rangeValues.add(current); } } else { rangeValues.add(from); } List<Map<String, String>> productTemp = new LinkedList<>(); for (Map<String, String> p : possibleStateList) { for (BigDecimal value : rangeValues) { HashMap<String, String> n = new HashMap<>(p); n.put(variable, value.toString()); productTemp.add(n); } } return productTemp; }  Class<RangeTag> getTagActionClass(); String getTagName(); String getTagNameSpace(); List<Map<String, String>> pipelinePossibleStates(RangeTag action,
                                                            List<Map<String, String>> possibleStateList);  }
@Test public void defaultStepTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); pipeInputList.add(new HashMap<String, String>()); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("10"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(10, resultList.size()); }
@Test public void emptyListTest() { List<Map<String, String>> emptyList = new LinkedList<>(); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("5"); rangeTag.setStep("0.7"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, emptyList); Assert.assertNotNull(resultList); Assert.assertEquals(0, resultList.size()); }
@Test public void noContaminationTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); HashMap<String, String> nonEmptyPossibleState = new HashMap<>(); nonEmptyPossibleState.put("var_out_test", "foobar"); pipeInputList.add(nonEmptyPossibleState); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test_2"); rangeTag.setFrom("1"); rangeTag.setTo("5"); rangeTag.setStep("0.7"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(6, resultList.size()); for (int i = 0; i < 6; i++) { Assert.assertEquals("foobar", resultList.get(i).get("var_out_test")); } }
@Test public void positiveStepTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); pipeInputList.add(new HashMap<String, String>()); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("5"); rangeTag.setStep("0.7"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(6, resultList.size()); Map<String, String> resultMap = resultList.get(0); Assert.assertEquals("1", resultMap.get("var_out_test")); resultMap = resultList.get(1); Assert.assertEquals("1.7", resultMap.get("var_out_test")); resultMap = resultList.get(2); Assert.assertEquals("2.4", resultMap.get("var_out_test")); resultMap = resultList.get(3); Assert.assertEquals("3.1", resultMap.get("var_out_test")); resultMap = resultList.get(4); Assert.assertEquals("3.8", resultMap.get("var_out_test")); resultMap = resultList.get(5); Assert.assertEquals("4.5", resultMap.get("var_out_test")); }
@Test public void bigNumbersTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); pipeInputList.add(new HashMap<String, String>()); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("20000"); rangeTag.setStep("10"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(2000, resultList.size()); Map<String, String> resultMap = resultList.get(0); Assert.assertEquals("1", resultMap.get("var_out_test")); resultMap = resultList.get(1); Assert.assertEquals("11", resultMap.get("var_out_test")); resultMap = resultList.get(100); Assert.assertEquals("1001", resultMap.get("var_out_test")); resultMap = resultList.get(1000); Assert.assertEquals("10001", resultMap.get("var_out_test")); }
@Test public void negativeStepTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); pipeInputList.add(new HashMap<String, String>()); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("-3"); rangeTag.setStep("-0.7"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(6, resultList.size()); Map<String, String> resultMap = resultList.get(0); Assert.assertEquals("1", resultMap.get("var_out_test")); resultMap = resultList.get(1); Assert.assertEquals("0.3", resultMap.get("var_out_test")); resultMap = resultList.get(2); Assert.assertEquals("-0.4", resultMap.get("var_out_test")); resultMap = resultList.get(3); Assert.assertEquals("-1.1", resultMap.get("var_out_test")); resultMap = resultList.get(4); Assert.assertEquals("-1.8", resultMap.get("var_out_test")); resultMap = resultList.get(5); Assert.assertEquals("-2.5", resultMap.get("var_out_test")); }
@Test public void zeroStepTest() { List<Map<String, String>> pipeInputList = new LinkedList<>(); pipeInputList.add(new HashMap<String, String>()); RangeExtension rangeExtension = new RangeExtension(); RangeExtension.RangeTag rangeTag = new RangeExtension.RangeTag(); rangeTag.setName("var_out_test"); rangeTag.setFrom("1"); rangeTag.setTo("-3"); rangeTag.setStep("0"); List<Map<String, String>> resultList = rangeExtension.pipelinePossibleStates(rangeTag, pipeInputList); Assert.assertEquals(1, resultList.size()); Map<String, String> resultMap = resultList.get(0); Assert.assertEquals("1", resultMap.get("var_out_test")); }