--- /dev/null
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.impl.schema.tree;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public abstract class AbstractTestModelTest {
+ static SchemaContext SCHEMA_CONTEXT;
+
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
+ }
+}
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class Bug2690Test {
+public class Bug2690Test extends AbstractTestModelTest {
private static final YangInstanceIdentifier NAME_PATH = YangInstanceIdentifier.of(TestModel.NON_PRESENCE_QNAME)
.node(TestModel.NAME_QNAME);
@Before
public void prepare() {
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- YangParserTestUtils.parseYangResource("/odl-datastore-test.yang"));
+ SCHEMA_CONTEXT);
}
@Test
* DataTreeModification, but should appear as UNMODIFIED in the
* resulting DataTreeCandidate.
*/
-public class Bug3674Test {
+public class Bug3674Test extends AbstractTestModelTest {
private DataTree tree;
@Before
public void setUp() {
- tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- TestModel.createTestContext());
+ tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
// Create the top-level container
final DataTreeModification mod = tree.takeSnapshot().newModification();
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private static final QName LIST_ID = QName.create(NS, REV, "list-id");
private static final QName MANDATORY_LEAF = QName.create(NS, REV, "mandatory-leaf");
private static final QName COMMON_LEAF = QName.create(NS, REV, "common-leaf");
- private SchemaContext schemaContext;
+ private static SchemaContext SCHEMA_CONTEXT;
- @Before
- public void init() {
- this.schemaContext = TestModel.createTestContext("/bug5968/foo.yang");
- assertNotNull("Schema context must not be null.", this.schemaContext);
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext("/bug5968/foo.yang");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
}
private static DataTree initDataTree(final SchemaContext schemaContext, final boolean withMapNode)
@Test
public void mergeInvalidContainerTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final MapNode myList = createMap(true);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@Test
public void mergeInvalidMapTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
mergeMap(modificationTree, true);
@Test
public void mergeInvalidMapEntryTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+ final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
mergeMapEntry(modificationTree, "1", null, "common-value");
@Test
public void mergeValidContainerTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final MapNode myList = createMap(false);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@Test
public void mergeValidMapTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
mergeMap(modificationTree, false);
@Test
public void mergeValidMapEntryTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+ final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
mergeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
@Test
public void validMultiStepsMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@Test
public void invalidMultiStepsMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@Test
public void validMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@Test
public void invalidMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@Test
public void validMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@Test
public void invalidMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
*/
@Test
public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private static final QName LIST_ID = QName.create(NS, REV, "list-id");
private static final QName MANDATORY_LEAF = QName.create(NS, REV, "mandatory-leaf");
private static final QName COMMON_LEAF = QName.create(NS, REV, "common-leaf");
- private SchemaContext schemaContext;
- @Before
- public void init() {
- this.schemaContext = TestModel.createTestContext("/bug5968/foo.yang");
- assertNotNull("Schema context must not be null.", this.schemaContext);
+ private static SchemaContext SCHEMA_CONTEXT;
+
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext("/bug5968/foo.yang");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
}
private static DataTree initDataTree(final SchemaContext schemaContext, final boolean withMapNode)
@Test
public void writeInvalidContainerTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final MapNode myList = createMap(true);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@Test
public void writeInvalidMapTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMap(modificationTree, true);
@Test
public void writeInvalidMapEntryTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+ final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMapEntry(modificationTree, "1", null, "common-value");
@Test
public void writeValidContainerTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final MapNode myList = createMap(false);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@Test
public void writeValidMapTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+ final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMap(modificationTree, false);
@Test
public void writeValidMapEntryTest() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+ final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
import com.google.common.collect.ImmutableSet;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class CaseAugmentTest {
-
- private SchemaContext schemaContext;
private static final QName CHOICE1_QNAME = QName.create(TestModel.TEST_QNAME, "choice1");
private static final QName C1L1_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf1");
private static final QName C1L2_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf2");
private static final AugmentationIdentifier AUGMENT_ID = new AugmentationIdentifier(
ImmutableSet.of(C1L2_QNAME, C1L3_QNAME));
- @Before
- public void prepare() {
- schemaContext = TestModel.createTestContext("/case-augment-test.yang");
- assertNotNull("Schema context must not be null.", schemaContext);
+ private static SchemaContext SCHEMA_CONTEXT;
+
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext("/case-augment-test.yang");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
}
- private DataTree initDataTree() {
- DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ private static DataTree initDataTree() {
+ DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
+ SCHEMA_CONTEXT);
return inMemoryDataTree;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class CaseExclusionTest {
+ private static SchemaContext SCHEMA_CONTEXT;
- private SchemaContext schemaContext;
+ private DataTree inMemoryDataTree;
- @Before
- public void prepare() {
- schemaContext = TestModel.createTestContext("/case-exclusion-test.yang");
- assertNotNull("Schema context must not be null.", schemaContext);
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext("/case-exclusion-test.yang");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
}
- private DataTree initDataTree() {
- return new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ @Before
+ public void before() {
+ inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
+ SCHEMA_CONTEXT);
}
@Test
public void testCorrectCaseWrite() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree();
final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final ContainerNode container = Builders
@Test(expected = IllegalArgumentException.class)
public void testCaseExclusion() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree();
final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final ContainerNode container = Builders
@Test(expected = IllegalArgumentException.class)
public void testCaseExclusionOnChoiceWrite() throws DataValidationFailedException {
- final DataTree inMemoryDataTree = initDataTree();
// Container write
final ContainerNode container = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
* 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.impl.schema.tree;
import static org.junit.Assert.assertFalse;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ConcurrentTreeModificationTest {
+public class ConcurrentTreeModificationTest extends AbstractTestModelTest {
private static final Logger LOG = LoggerFactory.getLogger(ConcurrentTreeModificationTest.class);
private static final Short ONE_ID = 1;
.withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).build())
.build();
- private SchemaContext schemaContext;
private DataTree inMemoryDataTree;
+
@Before
public void prepare() {
- schemaContext = TestModel.createTestContext();
- assertNotNull("Schema context must not be null.", schemaContext);
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- schemaContext);
+ SCHEMA_CONTEXT);
}
private static ContainerNode createFooTestContainerNode() {
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import static org.junit.Assert.assertNotNull;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
import com.google.common.base.VerifyException;
-import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
// TODO: expand these tests to catch some more obscure cases
-public class ConfigStatementValidationTest {
+public class ConfigStatementValidationTest extends AbstractTestModelTest {
private static final Short ONE_ID = 1;
private static final Short TWO_ID = 2;
.build())
.build();
- private SchemaContext schemaContext;
-
private static ContainerNode createFooTestContainerNode() {
return ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
.withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(BAR_NODE).build()).build();
}
- @Before
- public void prepare() {
- schemaContext = TestModel.createTestContext();
- assertNotNull("Schema context must not be null.", schemaContext);
- }
-
@Test(expected = SchemaValidationFailedException.class)
public void testOnPathFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(
new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node(
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode());
modificationTree.ready();
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataLeafFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode());
modificationTree.ready();
@Test(expected = SchemaValidationFailedException.class)
public void testOnPathCaseLeafFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
TestModel.TEST_QNAME, "choice1"));
final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier(
@Test(expected = VerifyException.class)
public void testOnDataCaseLeafFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
- DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
TestModel.TEST_QNAME, "choice1"));
final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
* 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.impl.schema.tree;
import static org.junit.Assert.assertEquals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class DataTreeCandidatesTest {
+public class DataTreeCandidatesTest extends AbstractTestModelTest {
private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidatesTest.class);
- private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
-
private DataTree dataTree;
@Before
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-public class DataTreeTransactionTest {
+public class DataTreeTransactionTest extends AbstractTestModelTest {
private DataTree tree;
@Before
public void setUp() {
- tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- TestModel.createTestContext());
+ tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
}
@Test
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-public class ErrorReportingTest {
+public class ErrorReportingTest extends AbstractTestModelTest {
private DataTree tree;
@Before
public void setup() {
- tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- TestModel.createTestContext());
+ tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
}
@Test
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
public class MandatoryLeafTest {
- private SchemaContext schemaContext;
+ private static SchemaContext SCHEMA_CONTEXT;
- @Before
- public void prepare() {
- schemaContext = TestModel.createTestContext("/mandatory-leaf-test.yang");
- assertNotNull("Schema context must not be null.", schemaContext);
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = TestModel.createTestContext("/mandatory-leaf-test.yang");
}
- private DataTree initDataTree(final boolean enableValidation) {
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
+ }
+
+ private static DataTree initDataTree(final boolean enableValidation) {
return new InMemoryDataTreeFactory().create(
new DataTreeConfiguration.Builder(TreeType.CONFIGURATION).setMandatoryNodesValidation(enableValidation)
- .build(), schemaContext);
+ .build(), SCHEMA_CONTEXT);
}
@Test
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/*
* Schema structure of document is
* }
* }
*/
-public class ModificationMetadataTreeTest {
+public class ModificationMetadataTreeTest extends AbstractTestModelTest {
private static final Short ONE_ID = 1;
private static final Short TWO_ID = 2;
.build())
.build();
- private SchemaContext schemaContext;
private RootModificationApplyOperation rootOper;
@Before
public void prepare() {
- schemaContext = TestModel.createTestContext();
- assertNotNull("Schema context must not be null.", schemaContext);
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+ rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
public NormalizedNode<?, ?> createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
- .withNodeIdentifier(new NodeIdentifier(schemaContext.getQName()))
+ .withNodeIdentifier(new NodeIdentifier(SCHEMA_CONTEXT.getQName()))
.withChild(createTestContainer()).build();
}
@Test
public void basicReadWrites() {
final DataTreeModification modificationTree = new InMemoryDataTreeModification(
- new InMemoryDataTreeSnapshot(schemaContext,
+ new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper), rootOper);
final Optional<NormalizedNode<?, ?>> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
assertTrue(originalBarNode.isPresent());
* Creates empty Snapshot with associated schema context.
*/
final DataTree t = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
- schemaContext);
+ SCHEMA_CONTEXT);
/**
*
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class StoreTreeNodesTest {
+public class StoreTreeNodesTest extends AbstractTestModelTest {
private static final Logger LOG = LoggerFactory.getLogger(StoreTreeNodesTest.class);
private static final Short ONE_ID = 1;
.build())
.build();
- private SchemaContext schemaContext;
private RootModificationApplyOperation rootOper;
@Before
public void prepare() {
- schemaContext = TestModel.createTestContext();
- assertNotNull("Schema context must not be null.", schemaContext);
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+ rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
public NormalizedNode<?, ?> createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()))
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(SCHEMA_CONTEXT.getQName()))
.withChild(createTestContainer()).build();
}
@Test
public void findNodeTestNodeFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final Optional<TreeNode> node = StoreTreeNodes.findNode(rootNode, OUTER_LIST_1_PATH);
@Test
public void findNodeTestNodeNotFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
@Test
public void findNodeCheckedTestNodeFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
TreeNode foundNode = null;
@Test
public void findNodeCheckedTestNodeNotFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
@Test
public void findClosestOrFirstMatchTestNodeExists() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final Optional<TreeNode> expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH);
@Test
public void findClosestOrFirstMatchTestNodeDoesNotExist() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final YangInstanceIdentifier outerListInnerListPath = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH)
@Test
public void getChildTestChildFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final Optional<TreeNode> node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode),
@Test
public void getChildTestChildNotFound() {
- final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+ final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final Optional<TreeNode> node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode),