2 * Copyright (c) 2016 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;
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.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
24 public class AugmentArgumentParsingTest {
26 private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
27 "/semantic-statement-parser/augment-arg-parsing/imported.yang", false);
29 private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
30 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang", false);
31 private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
32 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang", false);
33 private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
34 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang", false);
35 private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
36 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang", false);
37 private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
38 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang", false);
39 private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
40 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang", false);
41 private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
42 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang", false);
45 public void validAugAbsTest() throws SourceException, ReactorException {
47 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
48 addSources(reactor, IMPORTED, VALID_ARGS);
50 final EffectiveModelContext result = reactor.build();
51 assertNotNull(result);
55 public void invalidAugRel1Test() throws SourceException, ReactorException {
57 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
58 addSources(reactor, INVALID_REL1);
62 fail("reactor.process should fail due to invalid relative path");
63 } catch (Exception e) {
64 assertEquals(IllegalArgumentException.class, e.getClass());
69 public void invalidAugRel2Test() throws SourceException, ReactorException {
71 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
72 addSources(reactor, INVALID_REL2);
76 fail("reactor.process should fail due to invalid relative path");
77 } catch (Exception e) {
78 assertEquals(IllegalArgumentException.class, e.getClass());
83 public void invalidAugAbs() throws SourceException, ReactorException {
85 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
86 addSources(reactor, INVALID_ABS);
90 fail("reactor.process should fail due to invalid absolute path");
91 } catch (Exception e) {
92 assertEquals(IllegalArgumentException.class, e.getClass());
97 public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
99 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
100 addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
104 fail("reactor.process should fail due to missing import from augment path");
105 } catch (Exception e) {
106 assertEquals(IllegalArgumentException.class, e.getClass());
112 public void invalidAugEmptyTest() throws SourceException {
114 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
115 addSources(reactor, INVALID_EMPTY);
119 fail("reactor.process should fail due to empty path");
120 } catch (Exception e) {
121 assertEquals(IllegalArgumentException.class, e.getClass());
127 public void invalidAugXPathTest() throws SourceException {
129 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
130 addSources(reactor, INVALID_XPATH);
134 fail("reactor.process should fail due to invalid XPath");
135 } catch (Exception e) {
136 assertEquals(IllegalArgumentException.class, e.getClass());
140 private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
141 for (YangStatementSourceImpl source : sources) {
142 reactor.addSource(source);