DomConfigPayloadBuilder { public static ConfigDefinitionKey parseConfigName(Element configE) { if (!configE.getNodeName().equals("config")) { throw new ConfigurationRuntimeException("The root element must be 'config', but was '" + configE.getNodeName() + "'."); } if (!configE.hasAttribute("name")) { throw new ConfigurationRuntimeException ("The 'config' element must have a 'name' attribute that matches the name of the config definition."); } String elementString = configE.getAttribute("name"); if (!elementString.contains(".")) { throw new ConfigurationRuntimeException("The config name '" + elementString + "' contains illegal characters. Only names with the pattern " + namespacePattern.pattern() + "." + namePattern.pattern() + " are legal."); } Tuple2<String, String> t = ConfigUtils.getNameAndNamespaceFromString(elementString); String xmlName = t.first; String xmlNamespace = t.second; if (!validName(xmlName)) { throw new ConfigurationRuntimeException("The config name '" + xmlName + "' contains illegal characters. Only names with the pattern " + namePattern.toString() + " are legal."); } if (!validNamespace(xmlNamespace)) { throw new ConfigurationRuntimeException("The config namespace '" + xmlNamespace + "' contains illegal characters. Only namespaces with the pattern " + namespacePattern.toString() + " are legal."); } return new ConfigDefinitionKey(xmlName, xmlNamespace); } DomConfigPayloadBuilder(ConfigDefinition configDefinition); ConfigPayloadBuilder build(Element configE); static ConfigDefinitionKey parseConfigName(Element configE);  }
@Test public void testNameParsing() { Element configRoot = getDocument(new StringReader("<config name=\"test.function-test\" version=\"1\">" + "<int_val>1</int_val> +" + "</config>")); ConfigDefinitionKey key = DomConfigPayloadBuilder.parseConfigName(configRoot); assertThat(key.getName(), is("function-test")); assertThat(key.getNamespace(), is("test")); }
@Test(expected = ConfigurationRuntimeException.class) public void testNameParsingInvalidName() { Element configRoot = getDocument(new StringReader("<config name=\" function-test\" version=\"1\">" + "<int_val>1</int_val> +" + "</config>")); DomConfigPayloadBuilder.parseConfigName(configRoot); }
@Test(expected = ConfigurationRuntimeException.class) public void testNameParsingInvalidNamespace() { Element configRoot = getDocument(new StringReader("<config name=\"_foo.function-test\" version=\"1\">" + "<int_val>1</int_val> +" + "</config>")); DomConfigPayloadBuilder.parseConfigName(configRoot); }