InLineTransformerExtension implements CustomTagExtension<InLineTransformerExtension.TransformTag> { public List<Map<String, String>> pipelinePossibleStates(TransformTag action, List<Map<String, String>> possibleStateList) { DataTransformer tr = transformers.get(action.getName()); DataPipe pipe = new DataPipe(0, null); for (Map<String, String> possibleState : possibleStateList) { pipe.getDataMap().putAll(possibleState); tr.transform(pipe); possibleState.putAll(pipe.getDataMap()); } return possibleStateList; } InLineTransformerExtension(final Map<String, DataTransformer> transformers); Class<TransformTag> getTagActionClass(); String getTagName(); String getTagNameSpace(); List<Map<String, String>> pipelinePossibleStates(TransformTag action,
                                                            List<Map<String, String>> possibleStateList);  }
@Test public void addingAndCallingTransformersByNameTest() { CallCheckTransformer dummyTransformerOne = new CallCheckTransformer(); CallCheckTransformer dummyTransformerTwo = new CallCheckTransformer(); CallCheckTransformer dummyTransformerThree = new CallCheckTransformer(); HashMap<String, DataTransformer> transformerNames = new HashMap<>(); transformerNames.put("one", dummyTransformerOne); transformerNames.put("two", dummyTransformerTwo); transformerNames.put("three", dummyTransformerThree); InLineTransformerExtension transformerExtension = new InLineTransformerExtension(transformerNames); List<Map<String, String>> pipelineInput = new LinkedList<>(); pipelineInput.add(new HashMap<String, String>()); InLineTransformerExtension.TransformTag transformTag = new InLineTransformerExtension.TransformTag(); transformTag.setName("two"); transformerExtension.pipelinePossibleStates(transformTag, pipelineInput); Assert.assertFalse(dummyTransformerOne.isWasCalled()); Assert.assertTrue(dummyTransformerTwo.isWasCalled()); Assert.assertFalse(dummyTransformerThree.isWasCalled()); }
@Test public void emptyListTest() { CallCheckTransformer dummyTransformer = new CallCheckTransformer(); HashMap<String, DataTransformer> transformerNames = new HashMap<>(); transformerNames.put("dummy", dummyTransformer); InLineTransformerExtension transformerExtension = new InLineTransformerExtension(transformerNames); List<Map<String, String>> emptyList = new LinkedList<>(); InLineTransformerExtension.TransformTag transformTag = new InLineTransformerExtension.TransformTag(); transformTag.setName("dummy"); List<Map<String, String>> resultList = transformerExtension.pipelinePossibleStates(transformTag, emptyList); Assert.assertNotNull(resultList); Assert.assertEquals(0, resultList.size()); Assert.assertFalse(dummyTransformer.isWasCalled()); }
@Test public void nonEmptyListTest() { DataTransformer appendTransformer = new DataTransformer() { public void transform(DataPipe cr) { cr.getDataMap().put("Test", "Lorum"); } }; HashMap<String, DataTransformer> transformerNames = new HashMap<>(); transformerNames.put("append", appendTransformer); InLineTransformerExtension transformerExtension = new InLineTransformerExtension(transformerNames); List<Map<String, String>> nonEmptyList = new LinkedList<>(); nonEmptyList.add(new HashMap<String, String>()); nonEmptyList.add(new HashMap<String, String>()); InLineTransformerExtension.TransformTag transformTag = new InLineTransformerExtension.TransformTag(); transformTag.setName("append"); List<Map<String, String>> resultList = transformerExtension.pipelinePossibleStates(transformTag, nonEmptyList); Assert.assertNotNull(resultList); Assert.assertEquals(2, resultList.size()); Map<String, String> resultMap = resultList.get(0); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("Lorum", resultMap.get("Test")); resultMap = resultList.get(1); Assert.assertEquals(1, resultMap.keySet().size()); Assert.assertEquals("Lorum", resultMap.get("Test")); }