Promote SchemaSourceRepresentation
[yangtools.git] / parser / rfc7952-parser-support / src / test / java / org / opendaylight / yangtools / rfc7952 / parser / AnnotationTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.rfc7952.parser;
9
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;
14
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;
26
27 class AnnotationTest {
28     private static final AnnotationName LAST_MODIFIED =
29         new AnnotationName(QName.create("http://example.org/example-last-modified", "last-modified"));
30
31     @Test
32     void testAnnotationResolution() throws Exception {
33         final var reactor = RFC7950Reactors.vanillaReactorBuilder()
34             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
35                 new AnnotationStatementSupport(YangParserConfiguration.DEFAULT))
36             .build();
37         final var context = reactor.newBuild()
38             .addSources(
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")))
43             .buildEffective();
44
45         final var annotations = AnnotationSchemaNode.findAll(context);
46         assertEquals(1, annotations.size());
47         final var annotation = annotations.get(LAST_MODIFIED);
48         assertNotNull(annotation);
49
50         final var findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED);
51         assertTrue(findAnnotation.isPresent());
52         assertSame(annotation, findAnnotation.orElseThrow());
53
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());
58     }
59 }