SetAssignExtension implements CustomTagExtension<SetAssignExtension.SetAssignTag> { public List<Map<String, String>> pipelinePossibleStates(SetAssignTag action, List<Map<String, String>> possibleStateList) { if (action == null) { throw new NullActionException("Called with a null action, and possibleStateList = " + possibleStateList.toString()); } String variable = action.getName(); String set = action.getSet(); String[] domain; if (set == null) { throw new NullSetException("Called with a null set, action name=" + action.getName() + " and possibleStateList = " + possibleStateList.toString()); } if (StringUtils.splitByWholeSeparator(set, action.getSeparator()).length == 0) { domain = new String[]{""}; } else { domain = StringUtils.splitByWholeSeparator(set, action.getSeparator()); } List<Map<String, String>> productTemp = new LinkedList<>(); for (Map<String, String> p : possibleStateList) { for (String value : domain) { HashMap<String, String> n = new HashMap<>(p); n.put(variable, value); productTemp.add(n); } } return productTemp; }  Class<SetAssignTag> getTagActionClass(); String getTagName(); String getTagNameSpace(); List<Map<String, String>> pipelinePossibleStates(SetAssignTag action,
                                                            List<Map<String, String>> possibleStateList);  }
@Test public void pipelineEmptyListTest() { List<Map<String, String>> emptyList = new LinkedList<>(); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet("A,B,C,D,E"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, emptyList); Assert.assertNotNull(processedList); Assert.assertEquals(0, processedList.size()); }
@Test public void pipelineExpandOnEmptySetTest() { List<Map<String, String>> listWithEmptyMap = new LinkedList<>(); listWithEmptyMap.add(new HashMap<String, String>()); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet(""); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, listWithEmptyMap); Assert.assertEquals(1, processedList.size()); Map<String, String> resultMap = processedList.get(0); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("", resultMap.get("var_out_test")); }
@Test public void pipelineCardinalityTest() { List<Map<String, String>> listOfMaps = new LinkedList<>(); listOfMaps.add(new HashMap<String, String>()); listOfMaps.add(new HashMap<String, String>()); listOfMaps.add(new HashMap<String, String>()); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet("A,B,C,D,E"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, listOfMaps); Assert.assertEquals(15, processedList.size()); }
@Test public void pipelineExpandOrderingTest() { List<Map<String, String>> listWithEmptyMap = new LinkedList<>(); listWithEmptyMap.add(new HashMap<String, String>()); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet("A,B,C"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, listWithEmptyMap); Assert.assertEquals(3, processedList.size()); Map<String, String> resultMap = processedList.get(0); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("A", resultMap.get("var_out_test")); resultMap = processedList.get(1); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("B", resultMap.get("var_out_test")); resultMap = processedList.get(2); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("C", resultMap.get("var_out_test")); }
@Test public void pipelineExpandWithNonEmptyMapTest() { List<Map<String, String>> listWithNonEmptyMap = new LinkedList<>(); HashMap<String, String> nonEmptyMap = new HashMap<>(); nonEmptyMap.put("var_out_test_1", "3"); listWithNonEmptyMap.add(nonEmptyMap); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test_2"); setAssignTag.setSet("A,B,C"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, listWithNonEmptyMap); Assert.assertEquals(3, processedList.size()); Map<String, String> resultMap = processedList.get(0); Assert.assertEquals(2, resultMap.keySet().size()); Assert.assertEquals("3", resultMap.get("var_out_test_1")); Assert.assertEquals("A", resultMap.get("var_out_test_2")); resultMap = processedList.get(1); Assert.assertEquals(2, resultMap.keySet().size()); Assert.assertEquals("3", resultMap.get("var_out_test_1")); Assert.assertEquals("B", resultMap.get("var_out_test_2")); resultMap = processedList.get(2); Assert.assertEquals(2, resultMap.keySet().size()); Assert.assertEquals("3", resultMap.get("var_out_test_1")); Assert.assertEquals("C", resultMap.get("var_out_test_2")); }
@Test public void pipelineOverwriteTest() { List<Map<String, String>> listWithNonEmptyMap = new LinkedList<>(); HashMap<String, String> nonEmptyMap = new HashMap<>(); nonEmptyMap.put("var_out_test", "3"); listWithNonEmptyMap.add(nonEmptyMap); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet("A,B,C"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, listWithNonEmptyMap); Assert.assertEquals(3, processedList.size()); Map<String, String> resultMap = processedList.get(0); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("A", resultMap.get("var_out_test")); resultMap = processedList.get(1); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("B", resultMap.get("var_out_test")); resultMap = processedList.get(2); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("C", resultMap.get("var_out_test")); }
@Test public void separatorTest() { List<Map<String, String>> list = new LinkedList<>(); list.add(new HashMap<String, String>()); SetAssignExtension setAssign = new SetAssignExtension(); SetAssignExtension.SetAssignTag setAssignTag = new SetAssignExtension.SetAssignTag(); setAssignTag.setName("var_out_test"); setAssignTag.setSet("(A,B)|C"); setAssignTag.setSeparator("|"); List<Map<String, String>> processedList = setAssign.pipelinePossibleStates(setAssignTag, list); Assert.assertEquals(2, processedList.size()); Map<String, String> resultMap = processedList.get(0); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("(A,B)", resultMap.get("var_out_test")); }