import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.util.Map;
import java.util.Optional;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
public class AnnotationTest {
private static final QName LAST_MODIFIED_QNAME = QName.create("http://example.org/example-last-modified",
"last-modified");
- private static CrossSourceStatementReactor reactor;
+ private static CrossSourceStatementReactor REACTOR;
@BeforeClass
public static void createReactor() {
- reactor = RFC7950Reactors.vanillaReactorBuilder()
+ REACTOR = RFC7950Reactors.vanillaReactorBuilder()
.addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
new AnnotationStatementSupport(YangParserConfiguration.DEFAULT))
.build();
@AfterClass
public static void freeReactor() {
- reactor = null;
+ REACTOR = null;
}
@Test
- public void testAnnotationResolution() throws ReactorException, IOException, YangSyntaxErrorException {
- final BuildAction build = reactor.newBuild();
- build.addSource(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource("/ietf-yang-metadata@2016-08-05.yang")));
- build.addSource(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource("/example-last-modified.yang")));
- final SchemaContext context = build.buildEffective();
+ public void testAnnotationResolution() throws Exception {
+ final var context = REACTOR.newBuild()
+ .addSources(YangStatementStreamSource.create(
+ YangTextSchemaSource.forResource("/ietf-yang-metadata@2016-08-05.yang")),
+ YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-last-modified.yang")))
+ .buildEffective();
- final Map<QName, AnnotationSchemaNode> annotations = AnnotationSchemaNode.findAll(context);
+ final var annotations = AnnotationSchemaNode.findAll(context);
assertEquals(1, annotations.size());
- final AnnotationSchemaNode annotation = annotations.get(LAST_MODIFIED_QNAME);
+ final var annotation = annotations.get(LAST_MODIFIED_QNAME);
assertNotNull(annotation);
- final Optional<AnnotationSchemaNode> findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED_QNAME);
+ final var findAnnotation = AnnotationSchemaNode.find(context, LAST_MODIFIED_QNAME);
assertTrue(findAnnotation.isPresent());
- assertSame(annotation, findAnnotation.get());
+ assertSame(annotation, findAnnotation.orElseThrow());
assertEquals(BaseTypes.stringType(), annotation.getType());
assertEquals(Optional.empty(), annotation.getReference());