2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.stmt.test;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
23 public class AugmentTest {
25 private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
26 "/semantic-statement-parser/augment-arg-parsing/imported.yang");
28 private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
29 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
30 private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
31 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
32 private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
33 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
34 private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
35 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
36 private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
37 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
38 private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
39 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
40 private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
41 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
44 public void validAugAbsTest() throws SourceException, ReactorException {
46 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
47 addSources(reactor, IMPORTED, VALID_ARGS);
49 final EffectiveModelContext result = reactor.build();
50 assertNotNull(result);
54 public void invalidAugRel1Test() throws SourceException, ReactorException {
56 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57 addSources(reactor, INVALID_REL1);
61 fail("reactor.process should fail due to invalid relative path");
62 } catch (Exception e) {
63 assertEquals(IllegalArgumentException.class, e.getClass());
68 public void invalidAugRel2Test() throws SourceException, ReactorException {
70 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
71 addSources(reactor, INVALID_REL2);
75 fail("reactor.process should fail due to invalid relative path");
76 } catch (Exception e) {
77 assertEquals(IllegalArgumentException.class, e.getClass());
82 public void invalidAugAbs() throws SourceException, ReactorException {
84 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
85 addSources(reactor, INVALID_ABS);
89 fail("reactor.process should fail due to invalid absolute path");
90 } catch (Exception e) {
91 assertEquals(IllegalArgumentException.class, e.getClass());
96 public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
98 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
99 addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
103 fail("reactor.process should fail due to missing import from augment path");
104 } catch (Exception e) {
105 assertEquals(IllegalArgumentException.class, e.getClass());
110 public void invalidAugEmptyTest() throws SourceException {
112 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
113 addSources(reactor, INVALID_EMPTY);
117 fail("reactor.process should fail due to empty path");
118 } catch (Exception e) {
119 assertEquals(IllegalArgumentException.class, e.getClass());
124 public void invalidAugXPathTest() throws SourceException {
126 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
127 addSources(reactor, INVALID_XPATH);
131 fail("reactor.process should fail due to invalid XPath");
132 } catch (Exception e) {
133 assertEquals(IllegalArgumentException.class, e.getClass());
137 private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
138 for (YangStatementSourceImpl source : sources) {
139 reactor.addSource(source);