TransformationTemplate implements TransformationUtilityList { @Override public final String add(TransformationUtility utility) { if (utility.getParent() != null) { String exceptionMessage = String.format("Invalid attempt to add already registered transformation utility %s to transformation template %s", utility.getName(), name); throw new TransformationDefinitionException(exceptionMessage); } if (utility.getName() != null && utilityNames.contains(utility.getName())) { String exceptionMessage = String.format("Invalid attempt to add transformation utility %s to transformation template %s. Its name is already registered", utility.getName(), name); throw new TransformationDefinitionException(exceptionMessage); } if (!utility.isFileSet()) { String exceptionMessage; if (utility.getName() == null) { exceptionMessage = "Neither absolute, nor relative path, have been set for this transformation utility"; } else { exceptionMessage = String.format("Neither absolute, nor relative path, have been set for transformation utility %s", utility.getName()); } throw new TransformationDefinitionException(exceptionMessage); } int order; synchronized (this) { utilityList.add(utility); order = utilityList.size(); } utility.setParent(this, order); utilityNames.add(utility.getName()); return utility.getName(); } TransformationTemplate(); abstract Class<? extends Extension> getExtensionClass(); abstract String getDescription(); @Override final String add(TransformationUtility utility); @Override final String add(TransformationUtility utility, String utilityName); @Override final String addMultiple(TransformationOperation templateOperation, String... attributes); final String loop(TransformationUtility utility, int iterations); final String loop(TransformationUtility utility, String attribute); final String loop(TransformationUtility utility, UtilityCondition condition); @Deprecated @Override final void log(String logMessage); @Override final void info(String infoMessage); @Override final void debug(String debugMessage); @Override final void log(Level logLevel, String logMessage); @Deprecated @Override final void log(String logMessage, String... attributeNames); @Override final void info(String infoMessage, String... attributeNames); @Override final void debug(String debugMessage, String... attributeNames); @Override final void log(Level logLevel, String logMessage, String... attributeNames); @Override final List<TransformationUtility> getUtilities(); @Override List<TransformationUtility> getChildren(); @Override final String getName(); @Override final String toString(); String getApplicationType(); String getApplicationName(); void setBlank(boolean blank); boolean isBlank(); static final String BASELINE; }
@Test public void addTest() { TransformationTemplate transformationTemplate = getNewTestTransformationTemplate(); TransformationUtility transformationUtility = getNewTestTransformationUtility(); String tuName = transformationTemplate.add(transformationUtility); assertEquals(tuName, "NO_EXTENSION:AnonymousTransformationTemplate-1-AnonymousTransformationUtility"); assertEquals(transformationUtility.getName(), tuName); assertTrue(transformationTemplate.getUtilities().contains(transformationUtility)); assertEquals(transformationTemplate.getUtilities().size(), 1); }
@Test public void addUtilityThatAlreadyHasParentTest() { TransformationTemplate transformationTemplate = getNewTestTransformationTemplate(); TransformationUtility transformationUtility = getNewTestTransformationUtility(); assertEquals(transformationTemplate.add(transformationUtility), "NO_EXTENSION:AnonymousTransformationTemplate-1-AnonymousTransformationUtility"); try { transformationTemplate.add(transformationUtility); fail("TransformationDefinitionException was supposed to be thrown"); } catch (TransformationDefinitionException ex) { assertEquals("Invalid attempt to add already registered transformation utility NO_EXTENSION:AnonymousTransformationTemplate-1-AnonymousTransformationUtility to transformation template NO_EXTENSION:AnonymousTransformationTemplate", ex.getMessage()); } }