Correct double-quoted string whitespace trimming
[yangtools.git] / yang / 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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
14
15 import java.io.IOException;
16 import java.util.Map;
17 import java.util.Optional;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
24 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
25 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
31 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
32
33 public class AnnotationTest {
34     private static final QName LAST_MODIFIED_QNAME = QName.create("http://example.org/example-last-modified",
35             "last-modified");
36     private static CrossSourceStatementReactor reactor;
37
38     @BeforeClass
39     public static void createReactor() {
40         reactor = RFC7950Reactors.vanillaReactorBuilder()
41                 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, AnnotationStatementSupport.getInstance())
42                 .build();
43     }
44
45     @Test
46     public void testAnnotationResolution() throws ReactorException, IOException, YangSyntaxErrorException {
47         final BuildAction build = reactor.newBuild();
48         build.addSource(YangStatementStreamSource.create(
49             YangTextSchemaSource.forResource("/ietf-yang-metadata@2016-08-05.yang")));
50         build.addSource(YangStatementStreamSource.create(
51             YangTextSchemaSource.forResource("/example-last-modified.yang")));
52         final SchemaContext context = build.buildEffective();
53
54         final Map<QName, AnnotationSchemaNode> annotations = AnnotationSchemaNode.findAll(context);
55         assertEquals(1, annotations.size());
56         final AnnotationSchemaNode annotation = annotations.get(LAST_MODIFIED_QNAME);
57         assertNotNull(annotation);
58
59         final Optional<AnnotationSchemaNode> findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED_QNAME);
60         assertTrue(findAnnotation.isPresent());
61         assertSame(annotation, findAnnotation.get());
62
63         assertEquals(BaseTypes.stringType(), annotation.getType());
64         assertEquals(Optional.empty(), annotation.getReference());
65         assertEquals(Optional.of("This annotation contains the date and time when the\n"
66                 + "annotated instance was last modified (or created)."), annotation.getDescription());
67     }
68 }