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);
28 private static final YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
29 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang", false);
30 private static final YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
31 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang", false);
32 private static final YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
33 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang", false);
34 private static final YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
35 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang", false);
36 private static final YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
37 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang", false);
38 private static final YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
39 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang", false);
40 private static final YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
41 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang", false);
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());
111 public void invalidAugEmptyTest() throws SourceException {
113 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
114 addSources(reactor, INVALID_EMPTY);
118 fail("reactor.process should fail due to empty path");
119 } catch (Exception e) {
120 assertEquals(IllegalArgumentException.class, e.getClass());
126 public void invalidAugXPathTest() throws SourceException {
128 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
129 addSources(reactor, INVALID_XPATH);
133 fail("reactor.process should fail due to invalid XPath");
134 } catch (Exception e) {
135 assertEquals(IllegalArgumentException.class, e.getClass());
139 private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
140 for (YangStatementSourceImpl source : sources) {
141 reactor.addSource(source);