/** * Test to show that reporting an error about an uninitialized variable when generating templates * reports the correct line. */ @Test public void testParseTemplate() throws Exception { String[] lines = { /* 0 */ "template: template", /* 1 */ "a: {missingVar}", /* 2 */ "a: b", /* 3 */ "a: c", /* 4 */ "", /* 5 */ "template: template2", }; // Test must show "missingVar" missing on line 1. // Previous behaviour showed "missingVar" on line 5. TemplateFile templateFile = new TemplateFile(resourcePath); List<LocalizableMessage> warns = new ArrayList<>(); try { templateFile.parse(lines, warns); } catch (InitializationException e) { String msg = e.getMessage(); LocalizableMessage msg_locale = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get("missingVar", 1); assertEquals(msg, msg_locale.toString(), msg); } }
/** * Performs any initialization for this tag that may be needed while parsing a branch definition. * * @param templateFile The template file in which this tag is used. * @param branch The branch in which this tag is used. * @param arguments The set of arguments provided for this tag. * @param lineNumber The line number on which this tag appears in the template file. * @param warnings A list into which any appropriate warning messages may be placed. * @throws InitializationException If a problem occurs while initializing this tag. */ public void initializeForBranch( TemplateFile templateFile, Branch branch, String[] arguments, int lineNumber, List<Message> warnings) throws InitializationException { if ((arguments.length < 1) || (arguments.length > 2)) { Message message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get( getName(), lineNumber, 1, 2, arguments.length); throw new InitializationException(message); } String lowerName = toLowerCase(arguments[0]); AttributeType t = DirectoryServer.getAttributeType(lowerName, true); if (!branch.hasAttribute(t)) { Message message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); throw new InitializationException(message); } if (arguments.length == 2) { assertionValue = arguments[1]; } else { assertionValue = null; } }