import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public abstract class AbstractAnydataTest extends AbstractXmlTest {
+abstract class AbstractAnydataTest extends AbstractXmlTest {
static final QName FOO_QNAME = QName.create("test-anydata", "foo");
static final QName CONT_QNAME = QName.create(FOO_QNAME, "cont");
static final QName CONT_ANY_QNAME = QName.create(FOO_QNAME, "cont-any");
static EffectiveModelContext SCHEMA_CONTEXT;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static final void beforeAll() throws Exception {
SCHEMA_CONTEXT = YangParserTestUtils.parseYang("""
module test-anydata {
yang-version 1.1;
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static final void afterAll() {
SCHEMA_CONTEXT = null;
}
abstract class AbstractXmlTest {
private static final TransformerFactory TF = TransformerFactory.newInstance();
-
static final Document loadDocument(final String resourcePath) {
return requireNonNull(readXmlToDocument(Bug5446Test.class.getResourceAsStream(resourcePath)));
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-import org.w3c.dom.Document;
-public class AnyXmlWithParamsParsingTest {
+class AnyXmlWithParamsParsingTest {
private static final InputStream EDIT_CONFIG = XmlToNormalizedNodesTest.class.getResourceAsStream(
"/anyxml-support/params/edit.xml");
XMLNamespace.of("urn:ietf:params:xml:ns:netconf:base:1.0"), Revision.of("2011-06-01"));
@Test
- public void testAnyXmlWithParams() throws Exception {
- final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/params/");
+ void testAnyXmlWithParams() throws Exception {
+ final var context = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/params/");
- final Document doc = UntrustedXML.newDocumentBuilder().parse(EDIT_CONFIG);
+ final var doc = UntrustedXML.newDocumentBuilder().parse(EDIT_CONFIG);
final var resultHolder = new NormalizationResultHolder();
final var writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
- final XmlParserStream xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.of(context,
+ final var xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.of(context,
Absolute.of(QName.create(IETF_NETCONF, "edit-config"), YangConstants.operationInputQName(IETF_NETCONF)))
.toInference());
xmlParser.traverse(new DOMSource(doc.getDocumentElement()));
- final NormalizedNode parsed = resultHolder.getResult().data();
+ final var parsed = assertInstanceOf(ContainerNode.class, resultHolder.getResult().data());
- final DataContainerChild editCfg = ((ContainerNode) parsed).childByArg(getNodeId(parsed, "edit-content"));
- final DOMSource anyXmlParsedDom = ((DOMSourceAnyxmlNode) ((ChoiceNode) editCfg)
- .childByArg(getNodeId(parsed, "config"))).body();
+ final var editCfg = assertInstanceOf(ChoiceNode.class, parsed.childByArg(getNodeId(parsed, "edit-content")));
+ final var anyXmlParsedDom = assertInstanceOf(DOMSourceAnyxmlNode.class,
+ editCfg.childByArg(getNodeId(parsed, "config"))).body();
- assertNotNull(anyXmlParsedDom);
final String anyXmlParsedDomString = toStringDom(anyXmlParsedDom);
assertThat(anyXmlParsedDomString, containsString(
}
private static String toStringDom(final DOMSource source) {
+ final var sw = new StringWriter();
try {
- final StringWriter sw = new StringWriter();
- final TransformerFactory tf = TransformerFactory.newInstance();
- final Transformer transformer = tf.newTransformer();
+ final var tf = TransformerFactory.newInstance();
+ final var transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, new StreamResult(sw));
- return sw.toString();
- } catch (final TransformerException ex) {
- throw new RuntimeException("Error converting to String", ex);
+ } catch (TransformerException ex) {
+ throw new AssertionError("Error converting to String", ex);
}
+ return sw.toString();
}
}
\ No newline at end of file
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.stream.Stream;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import java.util.List;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
class AnydataNormalizeContentTest extends AbstractAnydataTest {
-
private static final QName BAR_QNAME = QName.create(FOO_QNAME, "bar"); // container level 2
private static final QName LIST_QNAME = QName.create(FOO_QNAME, "lst"); // list
private static final QName LEAF_LIST_QNAME = QName.create(FOO_QNAME, "my-leafs"); // leaf-list of type string
private static final String ANYDATA_XML = "<foo xmlns=\"test-anydata\"><cont-leaf>test</cont-leaf></foo>";
private static final String ANYDATA_EMPTY_XML = "<foo xmlns=\"test-anydata\" />";
- @BeforeAll
- static void beforeAll() throws Exception {
- beforeClass(); // junit 4
- }
-
- @AfterAll
- static void afterAll() {
- afterClass(); // junit 4
- }
-
@ParameterizedTest(name = "Anydata normalize to {0}")
- @MethodSource("normalizeArgs")
+ @MethodSource
void anydataNormalize(final String testDesc, final String xml, final Inference inference,
final NormalizedNode expectedData) throws Exception {
assertEquals(expectedData, normalizedAnydata.getData());
}
- private static Stream<Arguments> normalizeArgs() {
+ private static List<Arguments> anydataNormalize() {
// test case descriptor, xml, inference, expected normalized data
- return Stream.of(
- Arguments.of("container (root level)",
- ANYDATA_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME),
- Builders.containerBuilder().withNodeIdentifier(CONT_NODEID).withChild(LEAF_NODE).build()),
- Arguments.of("container (level 2)",
- ANYDATA_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, BAR_QNAME),
- Builders.containerBuilder().withNodeIdentifier(BAR_NODEID).withChild(LEAF_NODE).build()),
- Arguments.of("empty container",
- ANYDATA_EMPTY_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, BAR_QNAME),
- ImmutableNodes.containerNode(BAR_NODEID)),
- Arguments.of("single list element",
- ANYDATA_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME),
- Builders.unkeyedListBuilder().withNodeIdentifier(LIST_NODEID).withChild(
- Builders.unkeyedListEntryBuilder().withNodeIdentifier(LIST_NODEID)
- .withChild(LEAF_NODE).build()).build()),
- Arguments.of("single empty list element",
- ANYDATA_EMPTY_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME),
- Builders.unkeyedListBuilder().withNodeIdentifier(LIST_NODEID).withChild(
- Builders.unkeyedListEntryBuilder().withNodeIdentifier(LIST_NODEID).build()).build()),
- Arguments.of("single empty leaf-list element",
- ANYDATA_EMPTY_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME, LEAF_LIST_QNAME),
- Builders.leafSetBuilder().withNodeIdentifier(LEAF_LIST_NODEID).withChild(
- Builders.leafSetEntryBuilder()
- .withNodeIdentifier(new NodeWithValue<>(LEAF_LIST_QNAME, ""))
- .withValue("").build()).build()),
- Arguments.of("leaf of type empty",
- ANYDATA_EMPTY_XML,
- Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, LEAF_EMPTY_QNAME),
- ImmutableNodes.leafNode(LEAF_EMPTY_NODEID, Empty.value())));
+ return List.of(
+ Arguments.of("container (root level)",
+ ANYDATA_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME),
+ Builders.containerBuilder().withNodeIdentifier(CONT_NODEID).withChild(LEAF_NODE).build()),
+ Arguments.of("container (level 2)",
+ ANYDATA_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, BAR_QNAME),
+ Builders.containerBuilder().withNodeIdentifier(BAR_NODEID).withChild(LEAF_NODE).build()),
+ Arguments.of("empty container",
+ ANYDATA_EMPTY_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, BAR_QNAME),
+ ImmutableNodes.containerNode(BAR_NODEID)),
+ Arguments.of("single list element",
+ ANYDATA_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME),
+ Builders.unkeyedListBuilder()
+ .withNodeIdentifier(LIST_NODEID)
+ .withChild(Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(LIST_NODEID)
+ .withChild(LEAF_NODE)
+ .build())
+ .build()),
+ Arguments.of("single empty list element",
+ ANYDATA_EMPTY_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME),
+ Builders.unkeyedListBuilder()
+ .withNodeIdentifier(LIST_NODEID)
+ .withChild(Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(LIST_NODEID)
+ .build())
+ .build()),
+ Arguments.of("single empty leaf-list element",
+ ANYDATA_EMPTY_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, LIST_QNAME, LEAF_LIST_QNAME),
+ Builders.leafSetBuilder()
+ .withNodeIdentifier(LEAF_LIST_NODEID)
+ .withChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(LEAF_LIST_QNAME, ""))
+ .withValue("")
+ .build())
+ .build()),
+ Arguments.of("leaf of type empty",
+ ANYDATA_EMPTY_XML,
+ Inference.ofDataTreePath(SCHEMA_CONTEXT, CONT_QNAME, LEAF_EMPTY_QNAME),
+ ImmutableNodes.leafNode(LEAF_EMPTY_NODEID, Empty.value())));
}
}
import static org.hamcrest.MatcherAssert.assertThat;
import javax.xml.stream.XMLStreamReader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
-public class AnydataParseTest extends AbstractAnydataTest {
+class AnydataParseTest extends AbstractAnydataTest {
@Test
- public void testAnydata() throws Exception {
+ void testAnydata() throws Exception {
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(
toInputStream("<foo xmlns=\"test-anydata\"><bar/></foo>"));
import static org.junit.Assert.assertFalse;
import java.io.StringWriter;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedAnydata;
import org.opendaylight.yangtools.yang.model.spi.DefaultSchemaTreeInference;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
-@RunWith(Parameterized.class)
-public class AnydataSerializeTest extends AbstractAnydataTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
- private final XMLOutputFactory factory;
-
- public AnydataSerializeTest(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @Test
- public void testDOMAnydata() throws Exception {
+class AnydataSerializeTest extends AbstractAnydataTest {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testDOMAnydata(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var writer = new StringWriter();
final var xmlStreamWriter = factory.createXMLStreamWriter(writer);
assertEquals("<foo xmlns=\"test-anydata\"><bar xmlns=\"test-anydata\"></bar></foo>", serializedXml);
}
- @Test
- public void testXmlParseAnydata() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testXmlParseAnydata(final String factoryMode, final XMLOutputFactory factory) throws Exception {
// deserialization
final var reader = UntrustedXML.createXMLStreamReader(
AnydataSerializeTest.class.getResourceAsStream("/test-anydata.xml"));
XMLAssert.assertXMLEqual(diff, true);
}
- @Test
- public void testAnydataLoadFromXML() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testAnydataLoadFromXML(final String factoryMode, final XMLOutputFactory factory) throws Exception {
// Load XML file
final var doc = loadDocument("/test-anydata.xml");
final var domSource = new DOMSource(doc.getDocumentElement());
XMLAssert.assertXMLEqual(diff, true);
}
- @Test
- public void testAnydataSerialization() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testAnydataSerialization(final String factoryMode, final XMLOutputFactory factory) throws Exception {
//Get XML Data.
final var doc = loadDocument("/test-anydata.xml");
final var domSource = new DOMSource(doc.getDocumentElement());
XMLAssert.assertXMLEqual(diff, true);
}
- @Test
- public void testSiblingSerialize() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testSiblingSerialize(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var writer = new StringWriter();
final var xmlStreamWriter = factory.createXMLStreamWriter(writer);
+ "<cont-leaf>abc</cont-leaf></cont>", serializedXml);
}
- @Test
- public void testNormalizedSerialize() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ public void testNormalizedSerialize(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var writer = new StringWriter();
final var xmlStreamWriter = factory.createXMLStreamWriter(writer);
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class Bug5396Test {
+class Bug5396Test {
private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"), Revision.of("2016-03-22"));
private final EffectiveModelContext schemaContext = YangParserTestUtils.parseYang("""
}""");
@Test
- public void test() throws Exception {
+ void test() throws Exception {
testInputXML("/bug5396/xml/foo.xml", "dp1o34");
testInputXML("/bug5396/xml/foo2.xml", "dp0s3f9");
testInputXML("/bug5396/xml/foo3.xml", "dp09P1p2s3");
testInputXML("/bug5396/xml/foo4.xml", "dp0p3p1");
testInputXML("/bug5396/xml/foo5.xml", "dp0s3");
- try {
- testInputXML("/bug5396/xml/invalid-foo.xml", null);
- fail("Test should fail due to invalid input string");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Invalid value \"dp09P1p2s1234\" for union type."));
- }
+ final var ex = assertThrows(IllegalArgumentException.class,
+ () -> testInputXML("/bug5396/xml/invalid-foo.xml", null));
+ assertThat(ex.getMessage(), startsWith("Invalid value \"dp09P1p2s1234\" for union type."));
}
private void testInputXML(final String xmlPath, final String expectedValue) throws Exception {
Inference.ofDataTreePath(schemaContext, QName.create(FOO, "root")));
xmlParser.parse(reader);
- final var data = result.getResult().data();
- assertTrue(data instanceof ContainerNode);
- final ContainerNode rootContainer = (ContainerNode) data;
-
- DataContainerChild myLeaf = rootContainer.childByArg(new NodeIdentifier(QName.create(FOO, "my-leaf")));
- assertTrue(myLeaf instanceof LeafNode);
+ final var rootContainer = assertInstanceOf(ContainerNode.class, result.getResult().data());
+ final var myLeaf = assertInstanceOf(LeafNode.class,
+ rootContainer.childByArg(new NodeIdentifier(QName.create(FOO, "my-leaf"))));
assertEquals(expectedValue, myLeaf.body());
}
}
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Base64;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMResult;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xmlunit.builder.DiffBuilder;
-public class Bug5446Test extends AbstractXmlTest {
+class Bug5446Test extends AbstractXmlTest {
private static final QNameModule FOO_MODULE = QNameModule.create(XMLNamespace.of("foo"), Revision.of("2015-11-05"));
private static final QName ROOT_QNAME = QName.create(FOO_MODULE, "root");
private static final QName IP_ADDRESS_QNAME = QName.create(FOO_MODULE, "ip-address");
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final EffectiveModelContext schemaContext = YangParserTestUtils.parseYang("""
module foo {
yang-version 1;
.ignoreComments()
.checkForIdentical()
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(diff.hasDifferences(), diff.toString());
}
private static ContainerNode createDocNode() {
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.InputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class Bug8083Test {
+class Bug8083Test {
private static final QNameModule FOOBAR = QNameModule.create(XMLNamespace.of("foobar-ns"));
private static final QNameModule BAZ = QNameModule.create(XMLNamespace.of("baz-ns"));
private static final QNameModule ZAB = QNameModule.create(XMLNamespace.of("zab-ns"));
@Test
- public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
+ void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
final var schemaContext = YangParserTestUtils.parseYang("""
module baz {
namespace baz-ns;
}
@Test
- public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
+ void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
final var schemaContext = YangParserTestUtils.parseYang("""
module zab {
namespace zab-ns;
}
@Test
- public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
+ void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
final var schemaContext = YangParserTestUtils.parseYang("""
module foobar {
namespace foobar-ns;
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class Bug8675Test {
+class Bug8675Test {
private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"), Revision.of("2017-06-13"));
private static EffectiveModelContext schemaContext;
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ static void setup() {
schemaContext = YangParserTestUtils.parseYang("""
module foo {
namespace foo;
}""");
}
- @AfterClass
- public static void cleanup() {
+ @AfterAll
+ static void cleanup() {
schemaContext = null;
}
@Test
- public void testParsingEmptyElements() throws Exception {
+ void testParsingEmptyElements() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(
"/bug8675/foo.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void testParsingEmptyRootElement() throws Exception {
+ void testParsingEmptyRootElement() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-2.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final var result = new NormalizationResultHolder();
}
@Test
- public void testListAsRootElement() throws Exception {
+ void testListAsRootElement() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-3.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final var result = new NormalizationResultHolder();
}
@Test
- public void testAnyXmlAsRootElement() throws Exception {
+ void testAnyXmlAsRootElement() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-4.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final var result = new NormalizationResultHolder();
}
@Test
- public void testLeafAsRootElement() throws Exception {
+ void testLeafAsRootElement() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-5.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final var result = new NormalizationResultHolder();
}
@Test
- public void testLeafListAsRootElement() throws Exception {
+ void testLeafListAsRootElement() throws Exception {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-6.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final var result = new NormalizationResultHolder();
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.params.provider.MethodSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xmlunit.builder.DiffBuilder;
-@RunWith(Parameterized.class)
-public class Bug8745Test extends AbstractXmlTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
+class Bug8745Test extends AbstractXmlTest {
private static EffectiveModelContext SCHEMA_CONTEXT;
- private final XMLOutputFactory factory;
-
- public Bug8745Test(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
SCHEMA_CONTEXT = YangParserTestUtils.parseYang("""
module foo {
namespace foo;
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
SCHEMA_CONTEXT = null;
}
- @Test
- public void testParsingAttributes() throws Exception {
+ @MethodSource("data")
+ @ArgumentsSource(TestFactories.class)
+ void testParsingAttributes(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var doc = loadDocument("/bug8745/foo.xml");
final var domSource = new DOMSource(doc.getDocumentElement());
final var domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
.ignoreWhitespace()
.checkForIdentical()
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(diff.hasDifferences(), diff.toString());
}
}
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.io.InputStream;
import java.io.StringWriter;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-@RunWith(Parameterized.class)
-public class Bug8803Test {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
+class Bug8803Test {
private static EffectiveModelContext SCHEMA_CONTEXT;
- private final XMLOutputFactory factory;
-
- public Bug8803Test(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
SCHEMA_CONTEXT = YangParserTestUtils.parseYang("""
module bar {
namespace bar-ns;
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
SCHEMA_CONTEXT = null;
}
- @Test
- public void test() throws Exception {
- final InputStream resourceAsStream = Bug8803Test.class.getResourceAsStream("/bug8803/foo.xml");
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void test(final String factoryMode, final XMLOutputFactory factory) throws Exception {
+ final var resourceAsStream = Bug8803Test.class.getResourceAsStream("/bug8803/foo.xml");
// deserialization
- final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
+ final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
- final NormalizationResultHolder result = new NormalizationResultHolder();
- final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+ final var result = new NormalizationResultHolder();
+ final var streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter,
Inference.ofDataTreePath(SCHEMA_CONTEXT, QName.create("foo-ns", "top-cont")));
xmlParser.parse(reader);
- final NormalizedNode transformedInput = result.getResult().data();
+ final var transformedInput = result.getResult().data();
assertNotNull(transformedInput);
// serialization
- final StringWriter writer = new StringWriter();
- final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(writer);
+ final var writer = new StringWriter();
+ final var xmlStreamWriter = factory.createXMLStreamWriter(writer);
- final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(
- xmlStreamWriter, SCHEMA_CONTEXT);
+ final var xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter,
+ SCHEMA_CONTEXT);
- final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
- xmlNormalizedNodeStreamWriter);
+ final var normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(xmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(transformedInput);
normalizedNodeWriter.flush();
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class Bug890Test {
+class Bug890Test {
private static final QNameModule FOO_MODULE = QNameModule.create(XMLNamespace.of("foo"), Revision.of("2018-07-10"));
private static final QName OUTGOING_LABELS_QNAME = QName.create(FOO_MODULE, "outgoing-labels");
private static final QName INDEX_QNAME = QName.create(FOO_MODULE, "index");
@Test
- public void testinputXml() throws Exception {
+ void testinputXml() throws Exception {
final var schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug890");
final var reader = UntrustedXML.createXMLStreamReader(new ByteArrayInputStream("""
<root xmlns="foo">
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-@RunWith(Parameterized.class)
-public class DOMSourceXMLStreamReaderTest extends AbstractXmlTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
+class DOMSourceXMLStreamReaderTest extends AbstractXmlTest {
private static EffectiveModelContext SCHEMA_CONTEXT;
- private final XMLOutputFactory factory;
-
- public DOMSourceXMLStreamReaderTest(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
SCHEMA_CONTEXT = YangParserTestUtils.parseYang("""
module bar {
namespace bar-ns;
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
SCHEMA_CONTEXT = null;
}
- @Test
- public void test() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void test(final String factoryMode, final XMLOutputFactory factory) throws Exception {
// deserialization
final var doc = loadDocument("/dom-reader-test/foo.xml");
final var inputXml = new DOMSource(doc.getDocumentElement());
allGenerated.add(encoded);
}
- assertEquals(allGenerated.size(), MAX_COUNTER);
+ assertEquals(MAX_COUNTER, allGenerated.size());
assertEquals("dPT", allGenerated.get(MAX_COUNTER - 1));
assertEquals("a", allGenerated.get(0));
assertEquals(allGenerated.size(), new HashSet<>(allGenerated).size());
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Collection;
import java.util.List;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.dom.DOMResult;
import org.custommonkey.xmlunit.ElementNameAndTextQualifier;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-@RunWith(Parameterized.class)
public class NormalizedNodeXmlTranslationTest extends AbstractXmlTest {
- private final EffectiveModelContext schema;
-
- @Parameterized.Parameters()
- public static Collection<Object[]> data() {
- return List.of(new Object[][] {
- { "/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok.xml", augmentChoiceHell() },
- { "/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok2.xml", null },
- { "/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok3.xml", augmentChoiceHell2() },
- { "/schema/test.yang", "/schema/simple.xml", null },
- { "/schema/test.yang", "/schema/simple2.xml", null },
- // TODO check attributes
- { "/schema/test.yang", "/schema/simple_xml_with_attributes.xml", withAttributes() }
- });
- }
-
private static final QNameModule MODULE = QNameModule.create(
XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:controller:test"), Revision.of("2014-03-13"));
return new NodeIdentifier(QName.create(MODULE, localName));
}
- private final ContainerNode expectedNode;
- private final String xmlPath;
-
- public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath,
- final ContainerNode expectedNode) {
- schema = YangParserTestUtils.parseYangResource(yangPath);
- this.xmlPath = xmlPath;
- this.expectedNode = expectedNode;
+ @ParameterizedTest
+ @MethodSource("data")
+ void testTranslationRepairing(final String yangPath, final String xmlPath, final ContainerNode expectedNode)
+ throws Exception {
+ testTranslation(TestFactories.REPAIRING_OUTPUT_FACTORY, yangPath, xmlPath, expectedNode);
}
- @Test
- public void testTranslationRepairing() throws Exception {
- testTranslation(TestFactories.REPAIRING_OUTPUT_FACTORY);
+ @ParameterizedTest
+ @MethodSource("data")
+ void testTranslation(final String yangPath, final String xmlPath, final ContainerNode expectedNode)
+ throws Exception {
+ testTranslation(TestFactories.DEFAULT_OUTPUT_FACTORY, yangPath, xmlPath, expectedNode);
}
- @Test
- public void testTranslation() throws Exception {
- testTranslation(TestFactories.DEFAULT_OUTPUT_FACTORY);
- }
-
- private void testTranslation(final XMLOutputFactory factory) throws Exception {
+ private static void testTranslation(final XMLOutputFactory factory, final String yangPath, final String xmlPath,
+ final ContainerNode expectedNode) throws Exception {
+ final var schema = YangParserTestUtils.parseYangResource(yangPath);
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(xmlPath);
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
// XMLAssert.assertXMLEqual(diff, true);
}
+
+ static List<Arguments> data() {
+ return List.of(
+ Arguments.of("/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok.xml", augmentChoiceHell()),
+ Arguments.of("/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok2.xml", null),
+ Arguments.of("/schema/augment_choice_hell.yang", "/schema/augment_choice_hell_ok3.xml",
+ augmentChoiceHell2()),
+ Arguments.of("/schema/test.yang", "/schema/simple.xml", null),
+ Arguments.of("/schema/test.yang", "/schema/simple2.xml", null),
+ // TODO check attributes
+ Arguments.of("/schema/test.yang", "/schema/simple_xml_with_attributes.xml", withAttributes()));
+ }
}
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import java.io.IOException;
-import java.util.Collection;
import java.util.Map;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMResult;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-import org.xml.sax.SAXException;
-@RunWith(Parameterized.class)
public class NormalizedNodesToXmlTest extends AbstractXmlTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
private QNameModule bazModule;
private QName outerContainer;
private static EffectiveModelContext SCHEMA_CONTEXT;
- private final XMLOutputFactory factory;
-
- public NormalizedNodesToXmlTest(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
SCHEMA_CONTEXT = YangParserTestUtils.parseYangResource("/baz.yang");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
SCHEMA_CONTEXT = null;
}
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
bazModule = QNameModule.create(XMLNamespace.of("baz-namespace"));
outerContainer = QName.create(bazModule, "outer-container");
myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3");
}
- @Test
- public void testNormalizedNodeToXmlSerialization() throws XMLStreamException, IOException, SAXException {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testNormalizedNodeToXmlSerialization(final String factoryMode, final XMLOutputFactory factory)
+ throws Exception {
final var doc = loadDocument("/baz.xml");
final var domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final var xmlStreamWriter = factory.createXMLStreamWriter(domResult);
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xmlunit.builder.DiffBuilder;
-@RunWith(Parameterized.class)
-public class SchemaOrderedNormalizedNodeWriterTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
+class SchemaOrderedNormalizedNodeWriterTest {
private static final String FOO_NAMESPACE = "foo";
private static final String RULE_NODE = "rule";
private static final String NAME_NODE = "name";
private static final String POLICY_NODE = "policy";
private static final String ORDER_NAMESPACE = "order";
- private final XMLOutputFactory factory;
-
- public SchemaOrderedNormalizedNodeWriterTest(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @Test
- public void testWrite() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testWrite(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var stringWriter = new StringWriter();
final var xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
.ignoreWhitespace()
.checkForIdentical()
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(diff.hasDifferences(), diff.toString());
}
- @Test
- public void testWriteOrder() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testWriteOrder(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final StringWriter stringWriter = new StringWriter();
final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
EffectiveModelContext schemaContext = YangParserTestUtils.parseYang("""
var writer = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter, schemaContext);
try (var nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext)) {
-
- final var cont = Builders.containerBuilder()
+ nnw.write(Builders.containerBuilder()
+ .withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "root"))
+ .withChild(Builders.containerBuilder()
.withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "cont"))
.withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "content"), "content1"))
- .build();
-
- final var root = Builders.containerBuilder()
- .withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "root"))
- .withChild(cont)
- .withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "id"), "id1"))
- .build();
-
- nnw.write(root);
+ .build())
+ .withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "id"), "id1"))
+ .build());
}
assertEquals("""
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import java.util.Collection;
import java.util.Map;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.dom.DOMResult;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-@RunWith(Parameterized.class)
public class SchemalessXMLStreamNormalizedNodeStreamWriterTest extends AbstractXmlTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
- private final XMLOutputFactory factory;
-
private QNameModule foobarModule;
private QName outerContainer;
private QName mySecondKeyLeaf;
private QName myLeafInList3;
- public SchemalessXMLStreamNormalizedNodeStreamWriterTest(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
foobarModule = QNameModule.create(XMLNamespace.of("foobar-namespace"), Revision.of("2016-09-19"));
outerContainer = QName.create(foobarModule, "outer-container");
myLeafInList3 = QName.create(foobarModule, "my-leaf-in-list-3");
}
- @Test
- public void testWrite() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testWrite(final String factoryMode, final XMLOutputFactory factory) throws Exception {
final var doc = loadDocument("/foobar.xml");
final var domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final var xmlStreamWriter = factory.createXMLStreamWriter(domResult);
XMLAssert.assertXMLEqual(diff, true);
}
- private NormalizedNode buildOuterContainerNode() {
+ private ContainerNode buildOuterContainerNode() {
return Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(outerContainer))
.withChild(Builders.containerBuilder()
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import javax.xml.stream.XMLStreamException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class StrictParsingModeTest {
+class StrictParsingModeTest {
private static EffectiveModelContext schemaContext;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
schemaContext = YangParserTestUtils.parseYang("""
module foo {
namespace foo;
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
schemaContext = null;
}
- @Test
// unknown child nodes in the top-level-container node will be skipped when the strictParsing is set to false
- public void testLenientParsing() throws Exception {
+ @Test
+ void testLenientParsing() throws Exception {
final var resourceAsStream = StrictParsingModeTest.class.getResourceAsStream(
"/strict-parsing-mode-test/foo.xml");
assertNotNull(transformedInput);
}
- @Test
// should fail because strictParsing is switched on and the top-level-container node contains child nodes
// which are not defined in the provided YANG model
- public void testStrictParsing() throws Exception {
+ @Test
+ void testStrictParsing() throws Exception {
final var resourceAsStream = StrictParsingModeTest.class.getResourceAsStream(
"/strict-parsing-mode-test/foo.xml");
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import java.util.Collection;
-import java.util.List;
+import java.util.stream.Stream;
import javax.xml.stream.XMLOutputFactory;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
-final class TestFactories {
+final class TestFactories implements ArgumentsProvider {
/**
* Non-repairing XMLOutputFactory.
*/
REPAIRING_OUTPUT_FACTORY = f;
}
- private TestFactories() {
- // Hidden on purpose
- }
-
- static Collection<Object[]> junitParameters() {
- return List.of(new Object[][] {
- { "default", DEFAULT_OUTPUT_FACTORY },
- { "repairing", REPAIRING_OUTPUT_FACTORY },
- });
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext context) throws Exception {
+ return Stream.of(
+ Arguments.of("default", DEFAULT_OUTPUT_FACTORY),
+ Arguments.of("repairing", REPAIRING_OUTPUT_FACTORY));
}
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.regex.Pattern;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class XmlStreamUtilsTest {
+class XmlStreamUtilsTest {
@FunctionalInterface
interface XMLStreamWriterConsumer {
void accept(XMLStreamWriter writer) throws XMLStreamException;
private static Module leafRefModule;
private static PreferredPrefixes pref;
- @BeforeClass
- public static void initialize() {
+ @BeforeAll
+ static void initialize() {
modelContext = YangParserTestUtils.parseYangResource("/leafref-test.yang");
assertNotNull(modelContext);
assertEquals(1, modelContext.getModules().size());
pref = new PreferredPrefixes.Shared(modelContext);
}
- @AfterClass
- public static void cleanup() {
+ @AfterAll
+ static void cleanup() {
leafRefModule = null;
modelContext = null;
}
@Test
- public void testWriteIdentityRef() throws Exception {
+ void testWriteIdentityRef() throws Exception {
final QNameModule parent = QNameModule.create(XMLNamespace.of("parent:uri"), Revision.of("2000-01-01"));
String xmlAsString = createXml(writer -> {
final Pattern prefixedIdentityPattern = Pattern.compile(".*\"different:namespace\">(.*):identity.*");
final Matcher matcher = prefixedIdentityPattern.matcher(xmlAsString);
- assertTrue("Xml: " + xmlAsString + " should match: " + prefixedIdentityPattern, matcher.matches());
+ assertTrue(matcher.matches(), "Xml: " + xmlAsString + " should match: " + prefixedIdentityPattern);
}
private static String createXml(final XMLStreamWriterConsumer consumer) throws XMLStreamException, IOException {
* One leafref reference to other leafref via relative references.
*/
@Test
- public void testLeafRefRelativeChaining() {
+ void testLeafRefRelativeChaining() {
getTargetNodeForLeafRef(StringTypeDefinition.class, "cont3", "leafname3");
}
@Test
- public void testLeafRefRelative() {
+ void testLeafRefRelative() {
getTargetNodeForLeafRef(StringTypeDefinition.class, "pointToStringLeaf");
}
@Test
- public void testLeafRefAbsoluteWithSameTarget() {
+ void testLeafRefAbsoluteWithSameTarget() {
getTargetNodeForLeafRef(InstanceIdentifierTypeDefinition.class, "absname");
}
* Tests relative path with double point inside path (e. g. "../../lf:interface/../lf:cont2/lf:stringleaf")
*/
// ignored because this isn't implemented
- @Ignore
+ @Disabled
@Test
- public void testLeafRefWithDoublePointInPath() {
+ void testLeafRefWithDoublePointInPath() {
getTargetNodeForLeafRef(StringTypeDefinition.class, "lf-with-double-point-inside");
}
@Test
- public void testLeafRefRelativeAndAbsoluteWithSameTarget() {
+ void testLeafRefRelativeAndAbsoluteWithSameTarget() {
assertSame(getTargetNodeForLeafRef(InstanceIdentifierTypeDefinition.class, "absname"),
getTargetNodeForLeafRef(InstanceIdentifierTypeDefinition.class, "relname"));
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xml.sax.SAXException;
-public class XmlToNormalizedNodesTest {
+class XmlToNormalizedNodesTest {
private static final QNameModule FOO_MODULE = QNameModule.create(XMLNamespace.of("foo-namespace"));
private static final QName PARENT_CONTAINER = QName.create(FOO_MODULE, "parent-container");
private static Inference outerContainerSchema;
private static Inference parentContainerSchema;
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ static void setup() {
schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
parentContainerSchema = Inference.ofDataTreePath(schemaContext, PARENT_CONTAINER);
outerContainerSchema = Inference.ofDataTreePath(schemaContext, OUTER_CONTAINER);
}
- @AfterClass
- public static void cleanup() {
+ @AfterAll
+ static void cleanup() {
schemaContext = null;
parentContainerSchema = null;
outerContainerSchema = null;
}
@Test
- public void testComplexXmlParsing() throws IOException, SAXException, URISyntaxException, XMLStreamException,
+ void testComplexXmlParsing() throws IOException, SAXException, URISyntaxException, XMLStreamException,
ParserConfigurationException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/baz.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void testSimpleXmlParsing() throws IOException, URISyntaxException, XMLStreamException,
+ void testSimpleXmlParsing() throws IOException, URISyntaxException, XMLStreamException,
ParserConfigurationException, SAXException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/foo.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnDuplicateLeaf() throws XMLStreamException, IOException,
+ void shouldFailOnDuplicateLeaf() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-foo.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnDuplicateAnyXml() throws XMLStreamException, IOException,
+ void shouldFailOnDuplicateAnyXml() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-foo-2.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnDuplicateContainer() throws XMLStreamException, IOException,
+ void shouldFailOnDuplicateContainer() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-foo-3.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnUnterminatedLeafElement() throws XMLStreamException, IOException,
+ void shouldFailOnUnterminatedLeafElement() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-baz.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnUnterminatedLeafElement2() throws XMLStreamException, IOException,
+ void shouldFailOnUnterminatedLeafElement2() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-baz-2.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnUnterminatedContainerElement() throws XMLStreamException, IOException,
+ void shouldFailOnUnterminatedContainerElement() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-baz-4.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
}
@Test
- public void shouldFailOnUnknownChildNode() throws XMLStreamException, IOException,
+ void shouldFailOnUnknownChildNode() throws XMLStreamException, IOException,
ParserConfigurationException, SAXException, URISyntaxException {
final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/invalid-baz-3.xml");
final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.StringReader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1107Test {
+class YT1107Test {
private static final QName PARENT = QName.create("yt1107", "parent");
private static final QName ADMIN = QName.create(PARENT, "admin");
private static final QName NAME = QName.create(PARENT, "name");
private static final QName USER = QName.create(PARENT, "user");
@Test
- public void testInterleavingLists() throws Exception {
+ void testInterleavingLists() throws Exception {
final var schemaContext = YangParserTestUtils.parseYang("""
module yt1107 {
namespace "yt1107";
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.StringWriter;
-import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xmlunit.builder.DiffBuilder;
-@RunWith(Parameterized.class)
-public class YT1108Test {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return TestFactories.junitParameters();
- }
-
+class YT1108Test {
private static final QName IDENT_ONE = QName.create("foo-namespace", "ident-one");
private static final QName IDENTITYREF_LEAF = QName.create("foo-namespace", "identityref-leaf");
private static final QName LEAF_CONTAINER = QName.create("foo-namespace", "leaf-container");
private static EffectiveModelContext MODEL_CONTEXT;
- private final XMLOutputFactory factory;
-
- public YT1108Test(final String factoryMode, final XMLOutputFactory factory) {
- this.factory = factory;
- }
-
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
MODEL_CONTEXT = YangParserTestUtils.parseYang("""
module foo {
namespace "foo-namespace";
}""");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
MODEL_CONTEXT = null;
}
- @Test
- public void testLeafOfIdentityRefTypeNNToXmlSerialization() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testLeafOfIdentityRefTypeNNToXmlSerialization(final String factoryMode, final XMLOutputFactory factory)
+ throws Exception {
final var diff = DiffBuilder
- .compare(serializeToXml(Builders.containerBuilder()
+ .compare(serializeToXml(factory, Builders.containerBuilder()
.withNodeIdentifier(NodeIdentifier.create(LEAF_CONTAINER))
.withChild(Builders.leafBuilder()
.withNodeIdentifier(NodeIdentifier.create(IDENTITYREF_LEAF))
.ignoreWhitespace()
.checkForIdentical()
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(diff.hasDifferences(), diff.toString());
}
- @Test
- public void testLeafOfUnionWithIdentityRefNNToXmlSerialization() throws Exception {
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestFactories.class)
+ void testLeafOfUnionWithIdentityRefNNToXmlSerialization(final String factoryMode, final XMLOutputFactory factory)
+ throws Exception {
final var diff = DiffBuilder
- .compare(serializeToXml(Builders.containerBuilder()
+ .compare(serializeToXml(factory, Builders.containerBuilder()
.withNodeIdentifier(NodeIdentifier.create(LEAF_CONTAINER))
.withChild(Builders.leafBuilder()
.withNodeIdentifier(NodeIdentifier.create(UNION_IDENTITYREF_LEAF))
.ignoreWhitespace()
.checkForIdentical()
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(diff.hasDifferences(), diff.toString());
}
- private String serializeToXml(final ContainerNode normalizedNode) throws Exception {
+ private static String serializeToXml(final XMLOutputFactory factory, final ContainerNode normalizedNode)
+ throws Exception {
final var sw = new StringWriter();
try (var nnsw = XMLStreamNormalizedNodeStreamWriter.create(factory.createXMLStreamWriter(sw), MODEL_CONTEXT)) {
NormalizedNodeWriter.forStreamWriter(nnsw).write(normalizedNode);
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;