org.opendaylight.yangtools.yang.model.api.SchemaPath Java Examples

The following examples show how to use org.opendaylight.yangtools.yang.model.api.SchemaPath. 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: SchemaOrderedNormalizedNodeWriterTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testWriteOrder() throws XMLStreamException, IOException, SAXException {
    final StringWriter stringWriter = new StringWriter();
    final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
    SchemaContext schemaContext = getSchemaContext("/bug1848/order.yang");
    NormalizedNodeStreamWriter writer = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter, schemaContext);

    try (NormalizedNodeWriter nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext, SchemaPath.ROOT)) {

        DataContainerChild<?, ?> cont = Builders.containerBuilder()
                .withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "cont"))
                .withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "content"), "content1"))
                .build();

        NormalizedNode<?, ?> root = Builders.containerBuilder()
                .withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "root"))
                .withChild(cont)
                .withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "id"), "id1"))
                .build();

        nnw.write(root);
    }

    XMLAssert.assertXMLIdentical(new Diff(EXPECTED_2, stringWriter.toString()), true);
}
 
Example #2
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void nodeTest() throws Exception {
    SchemaContext context = StmtTestUtils.parseYangSources(
        "/semantic-statement-parser/multiple-revisions/node-test");
    assertNotNull(context);

    QName root = QName.create("foo", "2016-04-06", "foo-root");
    QName container20160404 = QName.create("foo", "2016-04-06", "con20160404");
    SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
        container20160404));
    assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);

    QName container20160405 = QName.create("foo", "2016-04-06", "con20160405");
    findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
        container20160405));
    assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);

    QName container20160406 = QName.create("foo", "2016-04-06", "con20160406");
    findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
        container20160406));
    assertNull(findDataSchemaNode);
}
 
Example #3
Source File: SchemaContextFactoryDeviationsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testDeviationsSupportedInSomeModules() throws Exception {
    final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations =
            ImmutableSetMultimap.<QNameModule, QNameModule>builder()
            .put(FOO_MODULE, BAR_MODULE)
            .put(FOO_MODULE, BAZ_MODULE)
            .put(BAR_MODULE, BAZ_MODULE)
            .build();

    final ListenableFuture<EffectiveModelContext> lf = createSchemaContext(modulesWithSupportedDeviations, FOO, BAR,
        BAZ, FOOBAR);
    assertTrue(lf.isDone());
    final SchemaContext schemaContext = lf.get();
    assertNotNull(schemaContext);

    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B)));
    assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A)));
    assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B)));
}
 
Example #4
Source File: LeafrefTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRequireInstanceSubstatement() {
    final SchemaPath schemaPath = SchemaPath.create(true, QName.create("test", "my-cont"),
        QName.create("test", "my-leafref"));
    final PathExpression path = new PathExpressionImpl("../my-leaf", false);
    final LeafrefTypeBuilder leafrefTypeBuilder = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(path);

    assertTrue(leafrefTypeBuilder.build().requireInstance());

    leafrefTypeBuilder.setRequireInstance(false);
    final LeafrefTypeDefinition falseLeafref = leafrefTypeBuilder.build();
    assertFalse(falseLeafref.requireInstance());

    leafrefTypeBuilder.setRequireInstance(true);
    final LeafrefTypeDefinition trueLeafref = leafrefTypeBuilder.build();
    assertTrue(trueLeafref.requireInstance());

    final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> falseBuilder =
            RestrictedTypes.newLeafrefBuilder(falseLeafref, schemaPath);
    assertFalse(falseBuilder.build().requireInstance());

    final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> trueBuilder =
            RestrictedTypes.newLeafrefBuilder(trueLeafref, schemaPath);
    assertTrue(trueBuilder.build().requireInstance());
}
 
Example #5
Source File: ActionEffectiveStatementImpl.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
ActionEffectiveStatementImpl(final ActionStatement declared, final SchemaPath path, final int flags,
        final StmtContext<QName, ActionStatement, ActionEffectiveStatement> ctx,
        final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    super(declared, ctx, substatements);
    this.path = requireNonNull(path);
    this.flags = flags;
}
 
Example #6
Source File: AbstractNonEmptyLeafListEffectiveStatement.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
AbstractNonEmptyLeafListEffectiveStatement(final LeafListStatement declared, final SchemaPath path, final int flags,
        final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
        final LeafListSchemaNode original, final ElementCountConstraint elementCountConstraint) {
    super(declared, path, flags, substatements);
    this.original = original;
    this.elementCountConstraint = elementCountConstraint;
}
 
Example #7
Source File: Bug6669Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testValidAugment2() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2");
    assertNotNull(context);

    final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
    assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
}
 
Example #8
Source File: Bug6771Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void groupingTest() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/grouping");
    assertNotNull(context);
    verifyLeafType(SchemaContextUtil
            .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
}
 
Example #9
Source File: OpenconfigVersionTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void nodeTest() throws Exception {
    SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/node-test",
        StatementParserMode.SEMVER_MODE);
    assertNotNull(context);

    Module foo = context.findModules(new URI("foo")).iterator().next();
    Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();

    assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
    assertEquals(SemVer.valueOf("2016.1.1"), foo.getSemanticVersion().get());
    Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
    assertEquals(SemVer.valueOf("2016.4.6"), bar.getSemanticVersion().get());

    QName root = QName.create("foo", "2016-01-01", "foo-root");
    QName container20160404 = QName.create("foo", "2016-01-01", "con20160404");
    SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, root, container20160404));
    assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);

    QName container20160405 = QName.create("foo", "2016-01-01", "con20160405");
    findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, root, container20160405));
    assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);

    QName container20160406 = QName.create("foo", "2016-01-01", "con20160406");
    findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, root, container20160406));
    assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);

    QName container20170406 = QName.create("foo", "2016-01-01", "con20170406");
    findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, root, container20170406));
    assertNull(findDataSchemaNode);
}
 
Example #10
Source File: EmptyAnyxmlEffectiveStatement.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
EmptyAnyxmlEffectiveStatement(final AnyxmlStatement declared, final SchemaPath path, final int flags,
        final @Nullable AnyxmlSchemaNode original) {
    super(declared);
    this.path = requireNonNull(path);
    this.flags = flags;
    this.original = original;
}
 
Example #11
Source File: ConcreteTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static ConcreteTypeBuilder<InstanceIdentifierTypeDefinition> concreteInstanceIdentifierBuilder(
        final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
    return new ConcreteTypeBuilder<InstanceIdentifierTypeDefinition>(baseType, path) {
        @Override
        public InstanceIdentifierTypeDefinition buildType() {
            return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance());
        }
    };
}
 
Example #12
Source File: NormalizedNodes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Lookup a node based on relative SchemaPath.
 *
 * @deprecated Use {@link #findNode(NormalizedNode, Descendant)} instead.
 */
@Deprecated(forRemoval = true)
public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> parent,
        final SchemaPath relativePath) {
    checkArgument(!relativePath.isAbsolute(), "%s is not a relative path", relativePath);
    return findNode(Optional.ofNullable(parent), Iterables.transform(relativePath.getPathFromRoot(),
        NodeIdentifier::new));
}
 
Example #13
Source File: SchemaContextUtilTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testFindDummyData() {

    QName qname = QName.create("namespace", "localname");
    SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true);
    assertNull("Should be null. Module TestQName not found",
            SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));

    PathExpression xpath = new PathExpressionImpl("/test:bookstore/test:book/test:title", true);
    assertNull("Should be null. Module bookstore not found",
            SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xpath));


    final PathExpression xPath = new PathExpressionImpl("/bookstore/book/title", true);
    assertEquals("Should be null. Module bookstore not found", null,
            SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));

    SchemaNode int32node = BaseTypes.int32Type();
    PathExpression xpathRelative = new PathExpressionImpl("../prefix", false);
    assertNull("Should be null, Module prefix not found",
            SchemaContextUtil.findDataSchemaNodeForRelativeXPath(
                    mockSchemaContext, mockModule, int32node, xpathRelative));

    assertNull("Should be null. Module TestQName not found",
            SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname)));

    assertNull("Should be null.", SchemaContextUtil.findParentModule(mockSchemaContext, int32node));
}
 
Example #14
Source File: DerivedTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static @NonNull DerivedTypeBuilder<Int64TypeDefinition> derivedInt64Builder(
        final Int64TypeDefinition baseType, final SchemaPath path) {
    return new DerivedTypeBuilder<Int64TypeDefinition>(baseType, path) {
        @Override
        public Int64TypeDefinition build() {
            return new DerivedInt64Type(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes());
        }
    };
}
 
Example #15
Source File: Bug5335Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void incorrectTest2() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2");
    assertNotNull(context);

    final SchemaPath schemaPath = SchemaPath.create(true, ROOT, PRESENCE_CONTAINER_F, MANDATORY_LEAF_B);
    final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
    assertNull(mandatoryLeaf);

    final String testLog = output.toString();
    assertTrue(testLog.contains(
        "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
}
 
Example #16
Source File: RpcEffectiveStatementImpl.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
RpcEffectiveStatementImpl(final RpcStatement declared, final SchemaPath path, final int flags,
        final StmtContext<QName, RpcStatement, RpcEffectiveStatement> ctx,
        final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    super(declared, ctx, substatements);
    this.path = requireNonNull(path);
    this.flags = flags;
}
 
Example #17
Source File: AnyXmlSupportTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void anyXmlNodeWithSimpleValueInContainer() throws IOException, URISyntaxException {
    final String inputJson = loadTextFile("/complexjson/anyxml-node-with-simple-value-in-container.json");

    // deserialization
    final NormalizedNodeResult result = new NormalizedNodeResult();
    final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
    final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
    jsonParser.parse(new JsonReader(new StringReader(inputJson)));
    final NormalizedNode<?, ?> transformedInput = result.getResult();
    assertNotNull(transformedInput);

    // lf12-any check
    final DOMSource Lf12AnyActualValue = getParsedAnyXmlValue(transformedInput, LF12_ANY);
    final DOMSource Lf12AnyExpectedValue = createAnyXmlSimpleValue("ns:complex:json", "lf12-any", "100.5");
    verifyTransformedAnyXmlNodeValue(Lf12AnyExpectedValue, Lf12AnyActualValue);

    // lf13-any check
    final DOMSource Lf13AnyActualValue = getParsedAnyXmlValue(transformedInput, LF13_ANY);
    final DOMSource Lf13AnyExpectedValue = createAnyXmlSimpleValue("ns:complex:json", "lf13-any", "true");
    verifyTransformedAnyXmlNodeValue(Lf13AnyExpectedValue, Lf13AnyActualValue);

    // lf14-any check
    final DOMSource Lf14AnyActualValue = getParsedAnyXmlValue(transformedInput, LF14_ANY);
    final DOMSource Lf14AnyExpectedValue = createAnyXmlSimpleValue("ns:complex:json", "lf14-any", "null");
    verifyTransformedAnyXmlNodeValue(Lf14AnyExpectedValue, Lf14AnyActualValue);

    final String serializationResult = normalizedNodesToJsonString(transformedInput, schemaContext,
            SchemaPath.ROOT);

    final JsonParser parser = new JsonParser();
    final JsonElement expected = parser.parse(inputJson);
    final JsonElement actual = parser.parse(serializationResult);
    assertTrue(expected.equals(actual));
}
 
Example #18
Source File: RestrictedTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static @NonNull RangeRestrictedTypeBuilder<Int8TypeDefinition, Byte> newInt8Builder(
        final Int8TypeDefinition baseType, final SchemaPath path) {
    return new RangeRestrictedTypeBuilderWithBase<>(baseType, path) {
        @Override
        Int8TypeDefinition buildType(final RangeConstraint<Byte> rangeConstraint) {
            return new RestrictedInt8Type(getBaseType(), getPath(), getUnknownSchemaNodes(), rangeConstraint);
        }
    };
}
 
Example #19
Source File: SchemaTracker.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new writer with the specified context and rooted in the specified schema path.
 *
 * @param context Associated {@link SchemaContext}
 * @param path schema path
 * @return A new {@link NormalizedNodeStreamWriter}
 */
public static @NonNull SchemaTracker create(final SchemaContext context, final SchemaPath path) {
    final Collection<SchemaNode> schemaNodes = SchemaUtils.findParentSchemaNodesOnPath(context, path);
    checkArgument(!schemaNodes.isEmpty(), "Unable to find schema node for supplied schema path: %s", path);
    if (schemaNodes.size() > 1) {
        LOG.warn("More possible schema nodes {} for supplied schema path {}", schemaNodes, path);
    }
    final Optional<DataNodeContainer> current = schemaNodes.stream()
            .filter(node -> node instanceof DataNodeContainer).map(DataNodeContainer.class::cast)
            .findFirst();
    checkArgument(current.isPresent(),
            "Schema path must point to container or list or an rpc input/output. Supplied path %s pointed to: %s",
            path, current);
    return new SchemaTracker(current.get());
}
 
Example #20
Source File: SchemaOrderedNormalizedNodeWriter.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
 *
 * @param writer
 *            Back-end writer
 * @param schemaContext
 *            Schema context
 * @param path
 *            path
 */
public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext,
        final SchemaPath path) {
    super(writer);
    this.schemaContext = schemaContext;
    final Collection<SchemaNode> schemaNodes = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, path);
    Preconditions.checkArgument(!schemaNodes.isEmpty(), "Unable to find schema node for supplied schema path: %s",
            path);
    if (schemaNodes.size() > 1) {
        LOG.warn("More possible schema nodes {} for supplied schema path {}", schemaNodes, path);
    }
    this.root = schemaNodes.iterator().next();
}
 
Example #21
Source File: UnionCodecStringTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static UnionTypeDefinition toUnionTypeDefinition(final TypeDefinition<?>... types) {
    final UnionTypeBuilder builder = BaseTypes.unionTypeBuilder(mock(SchemaPath.class));

    for (TypeDefinition<?> t : types) {
        builder.addType(t);
    }

    return builder.build();
}
 
Example #22
Source File: StatementContextBase.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
final @NonNull Optional<SchemaPath> substatementGetSchemaPath() {
    SchemaPath local = schemaPath;
    if (local == null) {
        synchronized (this) {
            local = schemaPath;
            if (local == null) {
                local = createSchemaPath(coerceParentContext());
                schemaPath = local;
            }
        }
    }

    return Optional.ofNullable(local);
}
 
Example #23
Source File: DerivedTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static @NonNull DerivedTypeBuilder<EnumTypeDefinition> derivedEnumerationBuilder(
        final EnumTypeDefinition baseType, final SchemaPath path) {
    return new DerivedTypeBuilder<EnumTypeDefinition>(baseType, path) {
        @Override
        public EnumTypeDefinition build() {
            return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes());
        }
    };
}
 
Example #24
Source File: ConcreteTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static ConcreteTypeBuilder<EnumTypeDefinition> concreteEnumerationBuilder(
        final EnumTypeDefinition baseType, final SchemaPath path) {
    return new ConcreteTypeBuilder<EnumTypeDefinition>(baseType, path) {
        @Override
        public EnumTypeDefinition buildType() {
            return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes());
        }
    };
}
 
Example #25
Source File: RestrictedTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static @NonNull TypeBuilder<BooleanTypeDefinition> newBooleanBuilder(
        final @NonNull BooleanTypeDefinition baseType, final @NonNull SchemaPath path) {
    return new AbstractRestrictedTypeBuilder<>(baseType, path) {
        @Override
        BooleanTypeDefinition buildType() {
            return new RestrictedBooleanType(getBaseType(), getPath(), getUnknownSchemaNodes());
        }
    };
}
 
Example #26
Source File: SchemaContextFactoryDeviationsTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testDeviationsSupportedInAllModules() throws Exception {
    final ListenableFuture<EffectiveModelContext> lf = createSchemaContext(null, FOO, BAR, BAZ, FOOBAR);
    assertTrue(lf.isDone());
    final SchemaContext schemaContext = lf.get();
    assertNotNull(schemaContext);

    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B)));
}
 
Example #27
Source File: DerivedTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static @NonNull DerivedTypeBuilder<BooleanTypeDefinition> derivedBooleanBuilder(
        final @NonNull BooleanTypeDefinition baseType, final @NonNull SchemaPath path) {
    return new DerivedTypeBuilder<BooleanTypeDefinition>(baseType, path) {
        @Override
        public BooleanTypeDefinition build() {
            return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes());
        }
    };
}
 
Example #28
Source File: Bug8803Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "top-cont"));
    final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(SCHEMA_CONTEXT, topContPath);
    assertTrue(dataSchemaNode instanceof ContainerSchemaNode);
    final ContainerSchemaNode topContSchema = (ContainerSchemaNode) dataSchemaNode;

    final InputStream resourceAsStream = Bug8803Test.class.getResourceAsStream("/bug8803/foo.xml");

    // deserialization
    final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);

    final NormalizedNodeResult result = new NormalizedNodeResult();
    final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
    final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, topContSchema);
    xmlParser.parse(reader);
    final NormalizedNode<?, ?> transformedInput = result.getResult();
    assertNotNull(transformedInput);

    // serialization
    final StringWriter writer = new StringWriter();
    final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(writer);

    final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(
            xmlStreamWriter, SCHEMA_CONTEXT);

    final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
            xmlNormalizedNodeStreamWriter);
    normalizedNodeWriter.write(transformedInput);
    normalizedNodeWriter.flush();

    final String serializedXml = writer.toString();
    assertFalse(serializedXml.isEmpty());
}
 
Example #29
Source File: ConcreteTypes.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static ConcreteTypeBuilder<UnionTypeDefinition> concreteUnionBuilder(final UnionTypeDefinition baseType,
        final SchemaPath path) {
    return new ConcreteTypeBuilder<UnionTypeDefinition>(baseType, path) {
        @Override
        public DerivedUnionType buildType() {
            return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(),
                    getReference(), getStatus(), getUnits(), getUnknownSchemaNodes());
        }
    };
}
 
Example #30
Source File: LeafrefTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMethodsOfLeafrefTest() {
    final SchemaPath schemaPath = SchemaPath.create(false, QName.create("test", "Cont1"),
        QName.create("test", "List1"));
    final PathExpression revision = new PathExpressionImpl("/test:Cont1/test:List1", false);
    final PathExpression revision2 = new PathExpressionImpl("/test:Cont1/test:List2", false);

    final LeafrefTypeDefinition leafref = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision)
        .build();
    final LeafrefTypeDefinition leafref2 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision2)
        .build();
    final LeafrefTypeDefinition leafref3 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision)
        .build();
    final LeafrefTypeDefinition leafref4 = leafref;

    assertNotNull("Object 'leafref' shouldn't be null.", leafref);
    assertNull("Base type of 'leafref' should be null.", leafref.getBaseType());
    assertEquals(Optional.empty(), leafref.getUnits());
    assertEquals(Optional.empty(), leafref.getDefaultValue());
    assertEquals(QName.create("test", "List1"), leafref.getQName());
    assertEquals("SchemaPath of 'leafref' is '/Cont1/List1'.", schemaPath, leafref.getPath());
    assertFalse(leafref.getDescription().isPresent());
    assertFalse(leafref.getReference().isPresent());
    assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus());
    assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.",
            leafref.getUnknownSchemaNodes().isEmpty());
    assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision,
            leafref.getPathStatement());
    assertNotNull("String representation of 'leafref' shouldn't be null.", leafref.toString());
    assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(),
            leafref2.hashCode());
    assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref3));
    assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref4));
    assertFalse("Objects of type Leafref shouldn't be equal.", leafref.equals(leafref2));
    assertFalse("Objects shouldn't be equal.", leafref.equals(null));
    assertFalse("Objects shouldn't be equal.", leafref.equals("test"));
}