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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertSame;
13 import static org.junit.jupiter.api.Assertions.assertTrue;
15 import java.util.Optional;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
18 import org.opendaylight.yangtools.yang.common.AnnotationName;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
21 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
22 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
27 class AnnotationTest {
28 private static final AnnotationName LAST_MODIFIED =
29 new AnnotationName(QName.create("http://example.org/example-last-modified", "last-modified"));
32 void testAnnotationResolution() throws Exception {
33 final var reactor = RFC7950Reactors.vanillaReactorBuilder()
34 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
35 new AnnotationStatementSupport(YangParserConfiguration.DEFAULT))
37 final var context = reactor.newBuild()
39 YangStatementStreamSource.create(
40 YangTextSource.forResource(AnnotationTest.class, "/ietf-yang-metadata@2016-08-05.yang")),
41 YangStatementStreamSource.create(
42 YangTextSource.forResource(AnnotationTest.class, "/example-last-modified.yang")))
45 final var annotations = AnnotationSchemaNode.findAll(context);
46 assertEquals(1, annotations.size());
47 final var annotation = annotations.get(LAST_MODIFIED);
48 assertNotNull(annotation);
50 final var findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED);
51 assertTrue(findAnnotation.isPresent());
52 assertSame(annotation, findAnnotation.orElseThrow());
54 assertEquals(BaseTypes.stringType(), annotation.getType());
55 assertEquals(Optional.empty(), annotation.getReference());
56 assertEquals(Optional.of("This annotation contains the date and time when the\n"
57 + "annotated instance was last modified (or created)."), annotation.getDescription());