2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.rfc7952.parser;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
15 import java.io.IOException;
17 import java.util.Optional;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
25 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
26 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
27 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
29 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
32 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
33 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
35 public class AnnotationTest {
36 private static final QName LAST_MODIFIED_QNAME = QName.create("http://example.org/example-last-modified",
38 private static CrossSourceStatementReactor reactor;
41 public static void createReactor() {
42 reactor = RFC7950Reactors.vanillaReactorBuilder()
43 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
44 new AnnotationStatementSupport(YangParserConfiguration.DEFAULT))
49 public static void freeReactor() {
54 public void testAnnotationResolution() throws ReactorException, IOException, YangSyntaxErrorException {
55 final BuildAction build = reactor.newBuild();
56 build.addSource(YangStatementStreamSource.create(
57 YangTextSchemaSource.forResource("/ietf-yang-metadata@2016-08-05.yang")));
58 build.addSource(YangStatementStreamSource.create(
59 YangTextSchemaSource.forResource("/example-last-modified.yang")));
60 final SchemaContext context = build.buildEffective();
62 final Map<QName, AnnotationSchemaNode> annotations = AnnotationSchemaNode.findAll(context);
63 assertEquals(1, annotations.size());
64 final AnnotationSchemaNode annotation = annotations.get(LAST_MODIFIED_QNAME);
65 assertNotNull(annotation);
67 final Optional<AnnotationSchemaNode> findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED_QNAME);
68 assertTrue(findAnnotation.isPresent());
69 assertSame(annotation, findAnnotation.get());
71 assertEquals(BaseTypes.stringType(), annotation.getType());
72 assertEquals(Optional.empty(), annotation.getReference());
73 assertEquals(Optional.of("This annotation contains the date and time when the\n"
74 + "annotated instance was last modified (or created)."), annotation.getDescription());