Java Code Examples for org.opendaylight.yangtools.yang.common.QName#create()
The following examples show how to use
org.opendaylight.yangtools.yang.common.QName#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeafRefContextTreeBuilderTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void leafRefContextUtilsTest() { final QName q1 = QName.create(tst, "odl-contributor"); final QName q2 = QName.create(tst, "contributor"); final QName q3 = QName.create(tst, "odl-project-name"); final LeafRefContext odlContrProjNameCtx = rootLeafRefContext.getReferencingChildByName(q1) .getReferencingChildByName(q2).getReferencingChildByName(q3); final DataSchemaNode odlContrProjNameNode = tstMod.findDataChildByName(q1, q2, q3).get(); final LeafRefContext foundOdlContrProjNameCtx = LeafRefContextUtils.getLeafRefReferencingContext( odlContrProjNameNode, rootLeafRefContext); assertNotNull(foundOdlContrProjNameCtx); assertTrue(foundOdlContrProjNameCtx.isReferencing()); assertNotNull(foundOdlContrProjNameCtx.getLeafRefTargetPath()); assertEquals(odlContrProjNameCtx, foundOdlContrProjNameCtx); }
Example 2
Source File: LeafRefContextTreeBuilderTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void leafRefContextUtilsTest3() { final QName q16 = QName.create(tst, "con1"); final DataSchemaNode con1 = tstMod.findDataChildByName(q16).get(); final List<LeafRefContext> allLeafRefChilds = LeafRefContextUtils.findAllLeafRefChilds(con1, rootLeafRefContext); assertNotNull(allLeafRefChilds); assertFalse(allLeafRefChilds.isEmpty()); assertEquals(4, allLeafRefChilds.size()); final QName q17 = QName.create(tst, "odl-contributor"); final DataSchemaNode odlContributorNode = tstMod.findDataChildByName(q17).get(); List<LeafRefContext> allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef( odlContributorNode, rootLeafRefContext); assertNotNull(allChildsReferencedByLeafRef); assertFalse(allChildsReferencedByLeafRef.isEmpty()); assertEquals(1, allChildsReferencedByLeafRef.size()); allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(con1, rootLeafRefContext); assertNotNull(allChildsReferencedByLeafRef); assertTrue(allChildsReferencedByLeafRef.isEmpty()); }
Example 3
Source File: UnrecognizedStatementSupport.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Override public Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf( final StatementDefinition yangStmtDef) { final QName baseQName = getStatementName(); final QName statementName = QName.create(baseQName, yangStmtDef.getStatementName().getLocalName()); final ModelDefinedStatementDefinition def; final Optional<ArgumentDefinition> optArgDef = yangStmtDef.getArgumentDefinition(); if (optArgDef.isPresent()) { final ArgumentDefinition argDef = optArgDef.get(); def = new ModelDefinedStatementDefinition(statementName, argDef.getArgumentName(), argDef.isYinElement()); } else { def = new ModelDefinedStatementDefinition(statementName); } return Optional.of(new ModelDefinedStatementSupport(def)); }
Example 4
Source File: ConfigStatementValidationTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test(expected = SchemaValidationFailedException.class) public void testOnPathCaseLeafFail() throws DataValidationFailedException { final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create( 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( QName.create(TestModel.TEST_QNAME, "case2-cont")); final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId); final ContainerNode case2Cont = Builders.containerBuilder().withNodeIdentifier(case2ContId) .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")).build(); final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); modificationTree.write(ii, case2Cont); modificationTree.ready(); }
Example 5
Source File: MandatoryLeafTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testCorrectMandatoryLeafChoiceWrite() throws DataValidationFailedException { final DataTree inMemoryDataTree = initDataTree(true); // Container write final ContainerNode container = Builders.containerBuilder() .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build(); final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification(); modificationTree1.write(TestModel.TEST_PATH, container); modificationTree1.ready(); inMemoryDataTree.validate(modificationTree1); final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); inMemoryDataTree.commit(prepare1); // Choice write final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1")); final ChoiceNode choice = Builders .choiceBuilder() .withNodeIdentifier(choice1Id) .withChild( Builders.containerBuilder() .withNodeIdentifier( new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))) .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")) .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")) .build()).build(); final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification(); modificationTree2.write(TestModel.TEST_PATH.node(choice1Id), choice); modificationTree2.ready(); inMemoryDataTree.validate(modificationTree2); final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); inMemoryDataTree.commit(prepare2); }
Example 6
Source File: LeafRefContextTreeBuilderTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void buildLeafRefContextTreeTest4() { final QName q9 = QName.create(tst, "odl-project"); final QName q10 = QName.create(tst, "project"); final QName q11 = QName.create(tst, "name"); final LeafRefContext leafRefCtx4 = rootLeafRefContext.getReferencedChildByName(q9) .getReferencedChildByName(q10).getReferencedChildByName(q11); assertNotNull(leafRefCtx4); assertTrue(leafRefCtx4.isReferenced()); assertEquals(6, leafRefCtx4.getAllReferencedByLeafRefCtxs().size()); }
Example 7
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testGetDataChildByName() { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, new HashSet<>(), moduleConfig); final QName qname = QName.create("config-namespace", "2016-08-11", "cont"); final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class); doReturn(Optional.of(mockedContainer)).when(moduleConfig).findDataChildByName(any(QName.class)); final DataSchemaNode dataSchemaNode = filteringSchemaContextProxy.getDataChildByName(qname); assertTrue(dataSchemaNode instanceof ContainerSchemaNode); }
Example 8
Source File: Bug4610Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4610"); Revision revision = Revision.of("2015-12-12"); QNameModule foo = QNameModule.create(URI.create("foo"), revision); QNameModule bar = QNameModule.create(URI.create("bar"), revision); QName g1 = QName.create(bar, "g1"); QName g2 = QName.create(bar, "g2"); QName c1Bar = QName.create(bar, "c1"); QName c1Foo = QName.create(foo, "c1"); QName g3 = QName.create(foo, "g3"); QName root = QName.create(foo, "root"); ContainerEffectiveStatement effectiveContainerStatementG1 = findContainer(context, g1, c1Bar); ContainerEffectiveStatement effectiveContainerStatementG2 = findContainer(context, g2, c1Bar); ContainerEffectiveStatement effectiveContainerStatementG3 = findContainer(context, g3, c1Foo); ContainerEffectiveStatement effectiveContainerStatementRoot = findContainer(context, root, c1Foo); // check arguments QName originalStatementArgument = effectiveContainerStatementG1.argument(); assertTrue(originalStatementArgument.equals(effectiveContainerStatementG2.argument())); assertFalse(originalStatementArgument.equals(effectiveContainerStatementG3.argument())); assertFalse(originalStatementArgument.equals(effectiveContainerStatementRoot.argument())); ContainerStatement originalContainerStatement = effectiveContainerStatementG1.getDeclared(); ContainerStatement inGrouping2ContainerStatement = effectiveContainerStatementG2.getDeclared(); ContainerStatement inGrouping3ContainerStatement = effectiveContainerStatementG3.getDeclared(); ContainerStatement inRootContainerStatement = effectiveContainerStatementRoot.getDeclared(); // check declared instances assertTrue(originalContainerStatement == inGrouping2ContainerStatement); assertTrue(originalContainerStatement == inGrouping3ContainerStatement); assertTrue(originalContainerStatement == inRootContainerStatement); }
Example 9
Source File: NormalizedNodeWriterTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Before public void setUp() { bazModule = QNameModule.create(URI.create("baz-namespace"), Revision.of("1970-01-01")); myKeyedList = QName.create(bazModule, "my-keyed-list"); myKeyLeaf = QName.create(bazModule, "my-key-leaf"); myLeafList = QName.create(bazModule, "my-leaf-list"); }
Example 10
Source File: MandatoryLeafTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testDisabledValidation() throws DataValidationFailedException { final DataTree inMemoryDataTree = initDataTree(false); final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1")); final ContainerNode container = Builders .containerBuilder() .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) .withChild( Builders.choiceBuilder() .withNodeIdentifier(choice1Id) .withChild( Builders.containerBuilder() .withNodeIdentifier( new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))) .withChild( leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")).build()).build()).build(); final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); modificationTree.write(TestModel.TEST_PATH, container); modificationTree.ready(); inMemoryDataTree.validate(modificationTree); final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); inMemoryDataTree.commit(prepare); }
Example 11
Source File: AntlrXPathParser.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private YangExpr parseFunctionCall(final FunctionCallContext expr) { // We are mapping functions to RFC7950 YIN namespace, to keep us consistent with type/statement definitions final FunctionNameContext name = getChild(expr, FunctionNameContext.class, 0); final QName parsed; switch (name.getChildCount()) { case 1: parsed = QName.create(YangConstants.RFC6020_YIN_MODULE, name.getChild(0).getText()); break; case 3: parsed = createQName(name.getChild(0).getText(), name.getChild(2).getText()); break; default: throw illegalShape(name); } final List<YangExpr> args = expr.expr().stream().map(this::parseExpr).collect(ImmutableList.toImmutableList()); final YangFunction func = YANG_FUNCTIONS.get(parsed); if (func != null) { if (minimumYangVersion.compareTo(func.getYangVersion()) < 0) { minimumYangVersion = func.getYangVersion(); } final YangExpr funcExpr = functionSupport.functionToExpr(func, args); if (funcExpr instanceof YangLiteralExpr) { haveLiteral = true; } return funcExpr; } checkArgument(!YangConstants.RFC6020_YIN_MODULE.equals(parsed.getModule()), "Unknown default function %s", parsed); return YangFunctionCallExpr.of(parsed, args); }
Example 12
Source File: LeafRefContextTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() { final QName q1 = QName.create(root, "ref1"); final QName q2 = QName.create(root, "leaf1"); final QName q3 = QName.create(root, "cont1"); final QName q4 = QName.create(root, "cont2"); final QName q5 = QName.create(root, "list1"); final QName q6 = QName.create(root, "name"); final DataSchemaNode leafRefNode = rootMod.findDataChildByName(q1).get(); final DataSchemaNode targetNode = rootMod.findDataChildByName(q2).get(); final DataSchemaNode cont1Node = rootMod.findDataChildByName(q3).get(); final DataSchemaNode cont2Node = rootMod.findDataChildByName(q4).get(); final DataSchemaNode name1Node = rootMod.findDataChildByName(q3, q5, q6).get(); assertTrue(LeafRefContextUtils.isLeafRef(leafRefNode, rootLeafRefContext)); assertFalse(LeafRefContextUtils.isLeafRef(targetNode, rootLeafRefContext)); assertTrue(LeafRefContextUtils.hasLeafRefChild(cont1Node, rootLeafRefContext)); assertFalse(LeafRefContextUtils.hasLeafRefChild(leafRefNode, rootLeafRefContext)); assertTrue(LeafRefContextUtils.isReferencedByLeafRef(targetNode, rootLeafRefContext)); assertFalse(LeafRefContextUtils.isReferencedByLeafRef(leafRefNode, rootLeafRefContext)); assertTrue(LeafRefContextUtils.hasChildReferencedByLeafRef(cont2Node, rootLeafRefContext)); assertFalse(LeafRefContextUtils.hasChildReferencedByLeafRef(leafRefNode, rootLeafRefContext)); Map<QName, LeafRefContext> leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(name1Node, rootLeafRefContext); assertEquals(4, leafRefs.size()); leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(leafRefNode, rootLeafRefContext); assertTrue(leafRefs.isEmpty()); }
Example 13
Source File: PathArgumentListTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void testPathArgument() { final QNameModule qNameModule = QNameModule.create(URI.create("urn:opendaylight.test2"), Revision.of("2015-08-08")); final QName qNameRoot = QName.create(qNameModule, "root"); final QName qNameList = QName.create(qNameModule, "list"); final QName qNameLeaf = QName.create(qNameModule, "leaf-a"); final Map<QName, Object> entryLeaf = new HashMap<>(); entryLeaf.put(qNameList, "leaf"); final NodeIdentifierWithPredicates nodeIdentifierWithPredicates = NodeIdentifierWithPredicates.of(qNameList, entryLeaf); final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.of(qNameRoot).node(qNameList) .node(nodeIdentifierWithPredicates).node(qNameLeaf); final PathArgument pathArgumentToRoot = yangInstanceIdentifier.getAncestor(1).getPathArguments().iterator() .next(); final StackedPathArguments stackedPathArguments = (StackedPathArguments)yangInstanceIdentifier .getPathArguments(); assertTrue(yangInstanceIdentifier.pathArgumentsEqual(yangInstanceIdentifier)); assertEquals(pathArgumentToRoot, stackedPathArguments.get(0)); assertEquals(4, stackedPathArguments.size()); assertTrue(stackedPathArguments.contains(pathArgumentToRoot)); assertEquals(0, stackedPathArguments.indexOf(pathArgumentToRoot)); assertEquals(0, stackedPathArguments.lastIndexOf(pathArgumentToRoot)); final StackedReversePathArguments stackedReversePathArguments = (StackedReversePathArguments)yangInstanceIdentifier.getReversePathArguments(); final QName rootQname = pathArgumentToRoot.getNodeType(); final QName leafQname = stackedReversePathArguments.get(0).getNodeType(); assertEquals(qNameRoot, rootQname); assertEquals(qNameLeaf, leafQname); assertEquals(4, stackedReversePathArguments.size()); assertTrue(stackedReversePathArguments.contains(pathArgumentToRoot)); assertEquals(3, stackedReversePathArguments.indexOf(pathArgumentToRoot)); assertEquals(3, stackedReversePathArguments.lastIndexOf(pathArgumentToRoot)); final StackedYangInstanceIdentifier stackedYangInstanceIdentifier = (StackedYangInstanceIdentifier) yangInstanceIdentifier; final StackedYangInstanceIdentifier stackedYangInstanceIdentifierClone = stackedYangInstanceIdentifier.clone(); final YangInstanceIdentifier yangInstanceIdentifier1 = stackedYangInstanceIdentifier.getAncestor(4); assertEquals(stackedYangInstanceIdentifier, stackedYangInstanceIdentifierClone); assertEquals(stackedReversePathArguments, yangInstanceIdentifier1.getReversePathArguments()); try { stackedYangInstanceIdentifier.getAncestor(12); fail(); } catch (IllegalArgumentException e) { // Expected } }
Example 14
Source File: MandatoryLeafTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testMandatoryLeafViolationChoiceWrite() throws DataValidationFailedException { final DataTree inMemoryDataTree = initDataTree(true); // Container write final ContainerNode container = Builders.containerBuilder() .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build(); final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification(); modificationTree1.write(TestModel.TEST_PATH, container); modificationTree1.ready(); inMemoryDataTree.validate(modificationTree1); final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); inMemoryDataTree.commit(prepare1); // Choice write final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1")); final ChoiceNode choice = Builders .choiceBuilder() .withNodeIdentifier(choice1Id) .withChild( Builders.containerBuilder() .withNodeIdentifier( new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))) .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")) .build()).build(); try { final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification(); modificationTree2.write(TestModel.TEST_PATH.node(choice1Id), choice); modificationTree2.ready(); inMemoryDataTree.validate(modificationTree2); final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); inMemoryDataTree.commit(prepare2); } catch (final IllegalArgumentException e) { assertEquals("Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?" + "revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:" + "yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1", e.getMessage()); throw e; } }
Example 15
Source File: DataTreeCandidateValidatorTest2.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@BeforeClass public static void init() throws DataValidationFailedException { context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); for (final Module module : context.getModules()) { if (module.getName().equals("leafref-validation2")) { mainModule = module; } } rootModuleQname = mainModule.getQNameModule(); rootLeafRefContext = LeafRefContext.create(context); chips = QName.create(rootModuleQname, "chips"); chip = QName.create(rootModuleQname, "chip"); devType = QName.create(rootModuleQname, "dev_type"); chipDesc = QName.create(rootModuleQname, "chip_desc"); devices = QName.create(rootModuleQname, "devices"); device = QName.create(rootModuleQname, "device"); typeText = QName.create(rootModuleQname, "type_text"); devDesc = QName.create(rootModuleQname, "dev_desc"); sn = QName.create(rootModuleQname, "sn"); defaultIp = QName.create(rootModuleQname, "default_ip"); deviceTypeStr = QName.create(rootModuleQname, "device_types"); deviceType = QName.create(rootModuleQname, "device_type"); type = QName.create(rootModuleQname, "type"); desc = QName.create(rootModuleQname, "desc"); inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips) .get(); final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); initialDataTreeModification.write(path1, chipsContainer); final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule .findDataChildByName(deviceTypeStr).get(); final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); initialDataTreeModification.write(path2, deviceTypesContainer); initialDataTreeModification.ready(); final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification); inMemoryDataTree.commit(writeChipsCandidate); LOG.debug("{}", inMemoryDataTree); }
Example 16
Source File: Bug5396Test.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void test() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5396"); assertNotNull(context); QName root = QName.create("foo", "root"); QName myLeaf2 = QName.create("foo", "my-leaf2"); SchemaPath schemaPath = SchemaPath.create(true, root, myLeaf2); SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, schemaPath); assertTrue(findDataSchemaNode instanceof LeafSchemaNode); LeafSchemaNode leaf2 = (LeafSchemaNode) findDataSchemaNode; TypeDefinition<?> type = leaf2.getType(); assertTrue(type instanceof UnionTypeDefinition); UnionTypeDefinition union = (UnionTypeDefinition) type; List<TypeDefinition<?>> types = union.getTypes(); assertEquals(4, types.size()); TypeDefinition<?> type0 = types.get(0); TypeDefinition<?> type1 = types.get(1); TypeDefinition<?> type2 = types.get(2); TypeDefinition<?> type3 = types.get(3); assertFalse(type0.equals(type1)); assertFalse(type0.equals(type2)); assertFalse(type0.equals(type3)); assertTrue(type0 instanceof StringTypeDefinition); assertTrue(type1 instanceof StringTypeDefinition); assertTrue(type2 instanceof StringTypeDefinition); assertTrue(type3 instanceof StringTypeDefinition); StringTypeDefinition stringType0 = (StringTypeDefinition) type0; StringTypeDefinition stringType1 = (StringTypeDefinition) type1; StringTypeDefinition stringType2 = (StringTypeDefinition) type2; StringTypeDefinition stringType3 = (StringTypeDefinition) type3; final List<PatternConstraint> patternConstraints0 = stringType0.getPatternConstraints(); final List<PatternConstraint> patternConstraints1 = stringType1.getPatternConstraints(); final List<PatternConstraint> patternConstraints2 = stringType2.getPatternConstraints(); final List<PatternConstraint> patternConstraints3 = stringType3.getPatternConstraints(); assertEquals(1, patternConstraints0.size()); assertEquals(1, patternConstraints1.size()); assertEquals(1, patternConstraints2.size()); assertEquals(1, patternConstraints3.size()); final PatternConstraint patternConstraint0 = patternConstraints0.get(0); final PatternConstraint patternConstraint1 = patternConstraints1.get(0); final PatternConstraint patternConstraint2 = patternConstraints2.get(0); final PatternConstraint patternConstraint3 = patternConstraints3.get(0); assertEquals("^(?:dp[0-9]+o[0-9]+(d[0-9]+)?)$", patternConstraint0.getJavaPatternString()); assertEquals("^(?:dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?)$", patternConstraint1.getJavaPatternString()); assertEquals("^(?:dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?)$", patternConstraint2.getJavaPatternString()); assertEquals("^(?:dp[0-9]+p[0-9]+p[0-9]+)$", patternConstraint3.getJavaPatternString()); }
Example 17
Source File: AbstractModuleStringInstanceIdentifierCodec.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override protected final QName createQName(final String prefix, final String localName) { final Module module = moduleForPrefix(prefix); checkArgument(module != null, "Failed to lookup prefix %s", prefix); return QName.create(module.getQNameModule(), localName); }
Example 18
Source File: NormalizedNodeXmlTranslationTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
private static NodeIdentifier getNodeIdentifier(final String localName) { return new NodeIdentifier(QName.create(URI.create(NAMESPACE), REVISION, localName)); }
Example 19
Source File: AugmentTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void testAugmentedChoice() throws Exception { final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment") .toURI()); final Module module2 = TestUtils.findModule(context, "bar").get(); 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); // foo.yang // augment "/br:interfaces/br:ifEntry/bz:augment-holder" final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(FOO, "odl")); assertNotNull(odl); final Collection<? extends CaseSchemaNode> cases = odl.getCases(); assertEquals(4, cases.size()); CaseSchemaNode id = null; CaseSchemaNode node1 = null; CaseSchemaNode node2 = null; CaseSchemaNode node3 = null; for (final CaseSchemaNode ccn : cases) { if ("id".equals(ccn.getQName().getLocalName())) { id = ccn; } else if ("node1".equals(ccn.getQName().getLocalName())) { node1 = ccn; } else if ("node2".equals(ccn.getQName().getLocalName())) { node2 = ccn; } else if ("node3".equals(ccn.getQName().getLocalName())) { node3 = ccn; } } assertNotNull(id); assertNotNull(node1); assertNotNull(node2); assertNotNull(node3); final List<QName> qnames = new ArrayList<>(); qnames.add(Q0); qnames.add(Q1); qnames.add(Q2); qnames.add(QName.create(FOO, "odl")); // case id QName qname = QName.create(FOO, "id"); assertEquals(qname, id.getQName()); qnames.add(qname); assertEquals(SchemaPath.create(qnames, true), id.getPath()); final Collection<? extends DataSchemaNode> idChildren = id.getChildNodes(); assertEquals(1, idChildren.size()); // case node1 qname = QName.create(FOO, "node1"); assertEquals(qname, node1.getQName()); qnames.set(4, qname); assertEquals(SchemaPath.create(qnames, true), node1.getPath()); final Collection<? extends DataSchemaNode> node1Children = node1.getChildNodes(); assertTrue(node1Children.isEmpty()); // case node2 qname = QName.create(FOO, "node2"); assertEquals(qname, node2.getQName()); qnames.set(4, qname); assertEquals(SchemaPath.create(qnames, true), node2.getPath()); final Collection<? extends DataSchemaNode> node2Children = node2.getChildNodes(); assertTrue(node2Children.isEmpty()); // case node3 qname = QName.create(FOO, "node3"); assertEquals(qname, node3.getQName()); qnames.set(4, qname); assertEquals(SchemaPath.create(qnames, true), node3.getPath()); final Collection<? extends DataSchemaNode> node3Children = node3.getChildNodes(); assertEquals(1, node3Children.size()); // test cases qnames.clear(); qnames.add(Q0); qnames.add(Q1); qnames.add(Q2); qnames.add(QName.create(FOO, "odl")); // case id child qnames.add(QName.create(FOO, "id")); qnames.add(QName.create(FOO, "id")); final LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next(); assertNotNull(caseIdChild); assertEquals(SchemaPath.create(qnames, true), caseIdChild.getPath()); // case node3 child qnames.set(4, QName.create(FOO, "node3")); qnames.set(5, QName.create(FOO, "node3")); final ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next(); assertNotNull(caseNode3Child); assertEquals(SchemaPath.create(qnames, true), caseNode3Child.getPath()); }
Example 20
Source File: YangParserSimpleTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void testParseContainer() { final ContainerSchemaNode nodes = (ContainerSchemaNode) testModule .getDataChildByName(QName.create(testModule.getQNameModule(), "nodes")); // test SchemaNode args assertEquals(SN_NODES, nodes.getQName()); assertEquals(SN_NODES_PATH, nodes.getPath()); assertEquals(Optional.of("nodes collection"), nodes.getDescription()); assertEquals(Optional.of("nodes ref"), nodes.getReference()); assertEquals(Status.CURRENT, nodes.getStatus()); assertEquals(0, nodes.getUnknownSchemaNodes().size()); // test DataSchemaNode args assertFalse(nodes.isAugmenting()); assertFalse(nodes.isConfiguration()); // constraints assertEquals("class != 'wheel'", nodes.getWhenCondition().get().getOriginalString()); final Collection<? extends MustDefinition> mustConstraints = nodes.getMustConstraints(); assertEquals(2, mustConstraints.size()); final String must1 = "ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)"; final String errMsg1 = "An atm MTU must be 64 .. 17966"; final String must2 = "ifId != 0"; boolean found1 = false; boolean found2 = false; for (final MustDefinition must : mustConstraints) { if (must1.equals(must.toString())) { found1 = true; assertEquals(Optional.of(errMsg1), must.getErrorMessage()); } else if (must2.equals(must.toString())) { found2 = true; assertFalse(must.getErrorMessage().isPresent()); assertFalse(must.getErrorAppTag().isPresent()); assertFalse(must.getDescription().isPresent()); assertFalse(must.getReference().isPresent()); } } assertTrue(found1); assertTrue(found2); assertTrue(nodes.isPresenceContainer()); // typedef final Collection<? extends TypeDefinition<?>> typedefs = nodes.getTypeDefinitions(); assertEquals(1, typedefs.size()); final TypeDefinition<?> nodesType = typedefs.iterator().next(); final QName typedefQName = QName.create(SN, "nodes-type"); assertEquals(typedefQName, nodesType.getQName()); assertEquals(SN_NODES_PATH.createChild(QName.create(SN, "nodes-type")), nodesType.getPath()); assertFalse(nodesType.getDescription().isPresent()); assertFalse(nodesType.getReference().isPresent()); assertEquals(Status.CURRENT, nodesType.getStatus()); assertEquals(0, nodesType.getUnknownSchemaNodes().size()); // child nodes // total size = 8: defined 6, inserted by uses 2 assertEquals(8, nodes.getChildNodes().size()); final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create( testModule.getQNameModule(), "added")); assertEquals(createPath("nodes", "added"), added.getPath()); assertEquals(createPath("mytype"), added.getType().getPath()); final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create( testModule.getQNameModule(), "links")); assertFalse(links.isUserOrdered()); final Collection<? extends GroupingDefinition> groupings = nodes.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition nodeGroup = groupings.iterator().next(); final QName groupQName = QName.create(SN, "node-group"); assertEquals(groupQName, nodeGroup.getQName()); final SchemaPath nodeGroupPath = SN_NODES_PATH.createChild(groupQName); assertEquals(nodeGroupPath, nodeGroup.getPath()); final Collection<? extends UsesNode> uses = nodes.getUses(); assertEquals(1, uses.size()); final UsesNode use = uses.iterator().next(); assertEquals(nodeGroup, use.getSourceGrouping()); }