summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
7f41bd0)
There are two places where we fail to propagate location:
- one is a pure omission
- one is a case of bad format
Fix both sites, improving our error reporting.
Change-Id: I65b52c69a6d6d7bb0fd8a9bc3956a2dab51d81c5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
33c07eff30a65dd0889cc08dc88ddad72039321d)
if (!added && !elementList) {
throw new XMLStreamException(String.format(
"Duplicate element \"%s\" in namespace \"%s\" with parent \"%s\" in XML input",
if (!added && !elementList) {
throw new XMLStreamException(String.format(
"Duplicate element \"%s\" in namespace \"%s\" with parent \"%s\" in XML input",
- xmlElementName, elementNS, parent.getSchema()), in.getLocation());
+ xmlElementName, elementNS, parentSchema), in.getLocation());
}
// We have a match, proceed with it
}
// We have a match, proceed with it
} else if (parentSchema instanceof ListSchemaNode) {
optMount = MountPointSchemaNode.streamAll((ListSchemaNode) parentSchema).findFirst();
} else {
} else if (parentSchema instanceof ListSchemaNode) {
optMount = MountPointSchemaNode.streamAll((ListSchemaNode) parentSchema).findFirst();
} else {
- throw new XMLStreamException("Unhandled mount-aware schema " + parentSchema);
+ throw new XMLStreamException("Unhandled mount-aware schema " + parentSchema,
+ in.getLocation());
}
if (optMount.isPresent()) {
}
if (optMount.isPresent()) {
if (strictParsing) {
throw new XMLStreamException(String.format(
"Schema for node with name %s and namespace %s does not exist at %s", xmlElementName,
if (strictParsing) {
throw new XMLStreamException(String.format(
"Schema for node with name %s and namespace %s does not exist at %s", xmlElementName,
- elementNS, parentSchema.getPath(), in.getLocation()));
+ elementNS, parentSchema.getPath()), in.getLocation());
}
LOG.debug("Skipping unknown node ns=\"{}\" localName=\"{}\" at path {}", elementNS, xmlElementName,
}
LOG.debug("Skipping unknown node ns=\"{}\" localName=\"{}\" at path {}", elementNS, xmlElementName,
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import java.io.InputStream;
import javax.xml.stream.XMLStreamException;
import java.io.InputStream;
import javax.xml.stream.XMLStreamException;
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelContainer, true);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelContainer, true);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of an unknown child node.");
- } catch (XMLStreamException ex) {
- assertEquals("Schema for node with name unknown-container-a and namespace foo does not exist at "
- + "AbsoluteSchemaPath{path=[(foo)top-level-container]}", ex.getMessage());
- }
+
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("Schema for node with name unknown-container-a and namespace foo "
+ + "does not exist at AbsoluteSchemaPath{path=[(foo)top-level-container]}"));
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of duplicate leaf.");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString("Duplicate element \"decimal64-leaf\" in namespace"
- + " \"foo-namespace\" with parent \"container leaf-container\" in XML input"));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("Duplicate element \"decimal64-leaf\" in namespace"
+ + " \"foo-namespace\" with parent \"container leaf-container\" in XML input"));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of duplicate anyxml");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString("Duplicate element \"my-anyxml\" in namespace"
- + " \"foo-namespace\" with parent \"container anyxml-container\" in XML input"));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("Duplicate element \"my-anyxml\" in namespace"
+ + " \"foo-namespace\" with parent \"container anyxml-container\" in XML input"));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of duplicate container");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString("Duplicate element \"leaf-container\" in namespace"
- + " \"foo-namespace\" with parent \"container parent-container\" in XML input"));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("Duplicate element \"leaf-container\" in namespace"
+ + " \"foo-namespace\" with parent \"container parent-container\" in XML input"));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of unterminated leaf element.");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString(" START_ELEMENT "));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString(" START_ELEMENT "));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of unterminated leaf element.");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString("</my-leaf-1>"));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("</my-leaf-1>"));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of unterminated container element.");
- } catch (XMLStreamException ex) {
- assertThat(ex.getMessage(), containsString("</my-container-1>"));
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+ assertThat(ex.getMessage(), containsString("</my-container-1>"));
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
- try {
- xmlParser.parse(reader);
- fail("XMLStreamException should have been thrown because of an unknown child node.");
- } catch (XMLStreamException ex) {
- assertEquals("Schema for node with name my-container-1 and namespace baz-namespace does not exist at "
- + "AbsoluteSchemaPath{path=[(baz-namespace)outer-container, (baz-namespace)my-container-1]}",
- ex.getMessage());
- }
+ final XMLStreamException ex = assertThrows(XMLStreamException.class, () -> xmlParser.parse(reader));
+
+ assertThat(ex.getMessage(), containsString("Schema for node with name my-container-1 and namespace "
+ + "baz-namespace does not exist at "
+ + "AbsoluteSchemaPath{path=[(baz-namespace)outer-container, (baz-namespace)my-container-1]}"));
}
private static NormalizedNode<?, ?> buildOuterContainerNode() {
}
private static NormalizedNode<?, ?> buildOuterContainerNode() {