import static org.junit.Assert.assertTrue;
import java.util.Collection;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-public class AugmentTest {
+public class AugmentTest extends AbstractYangTest {
private static final QNameModule FOO = QNameModule.create(
XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-10-13"));
private static final QNameModule BAR = QNameModule.create(
private static final QName Q1 = QName.create(BAR, "ifEntry");
private static final QName Q2 = QName.create(BAZ, "augment-holder");
- @Test
- public void testAugmentParsing() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
+ private static EffectiveModelContext AUGMENT_IN_AUGMENT;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ AUGMENT_IN_AUGMENT = assertEffectiveModelDir("/augment-test/augment-in-augment");
+ }
+ @Test
+ public void testAugmentParsing() {
// foo.yang
- final Module module1 = context.findModules("foo").iterator().next();
+ final Module module1 = AUGMENT_IN_AUGMENT.findModules("foo").iterator().next();
Collection<? extends AugmentationSchemaNode> augmentations = module1.getAugmentations();
assertEquals(1, augmentations.size());
final AugmentationSchemaNode augment = augmentations.iterator().next();
final Collection<? extends DataSchemaNode> augmentChildren = augment.getChildNodes();
assertEquals(4, augmentChildren.size());
for (final DataSchemaNode dsn : augmentChildren) {
- TestUtils.checkIsAugmenting(dsn, false);
+ checkIsAugmenting(dsn, false);
}
final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName(QName.create(
assertFalse(odl.isAugmenting());
// baz.yang
- final Module module3 = context.findModules("baz").iterator().next();
+ final Module module3 = AUGMENT_IN_AUGMENT.findModules("baz").iterator().next();
augmentations = module3.getAugmentations();
assertEquals(3, augmentations.size());
AugmentationSchemaNode augment1 = null;
}
@Test
- public void testAugmentResolving() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
- final Module module2 = context.findModules("bar").iterator().next();
+ public void testAugmentResolving() {
+ final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
// augment "/br:interfaces/br:ifEntry" {
final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
"augment-holder"));
- TestUtils.checkIsAugmenting(augmentHolder, true);
+ checkIsAugmenting(augmentHolder, true);
assertEquals(Q2, augmentHolder.getQName());
// foo.yang
}
@Test
- public void testAugmentedChoice() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
- final Module module2 = context.findModules("bar").iterator().next();
+ public void testAugmentedChoice() {
+ final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
module2.getQNameModule(), "ifEntry"));
final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
BAZ, "augment-holder"));
- TestUtils.checkIsAugmenting(augmentedHolder, true);
+ checkIsAugmenting(augmentedHolder, true);
// foo.yang
// augment "/br:interfaces/br:ifEntry/bz:augment-holder"
@Test
public void testAugmentRpc() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI());
+ final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
final Revision revision = Revision.of("2013-10-11");
@Test
public void testAugmentInUsesResolving() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses")
- .toURI());
+ final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
assertEquals(1, context.getModules().size());
final Module test = context.getModules().iterator().next();
final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id"));
assertTrue(id.isAugmenting());
}
+
+ /**
+ * Test if node has augmenting flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
+ * child nodes/case nodes too.
+ *
+ * @param node node to check
+ * @param expected expected value
+ */
+ private static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+ assertEquals(expected, node.isAugmenting());
+ if (node instanceof DataNodeContainer) {
+ for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+ checkIsAugmenting(child, expected);
+ }
+ } else if (node instanceof ChoiceSchemaNode) {
+ for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+ checkIsAugmenting(caseNode, expected);
+ }
+ }
+ }
}