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;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
18 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
22 public class AugmentTest {
24 private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
25 "/semantic-statement-parser/augment-arg-parsing/imported.yang", false);
27 private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
28 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang", false);
29 private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
30 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang", false);
31 private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
32 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang", false);
33 private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
34 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang", false);
35 private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
36 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang", false);
37 private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
38 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang", false);
39 private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
40 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang", false);
43 public void validAugAbsTest() throws SourceException, ReactorException {
45 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46 addSources(reactor, IMPORTED, VALID_ARGS);
48 final EffectiveModelContext result = reactor.build();
49 assertNotNull(result);
53 public void invalidAugRel1Test() throws SourceException, ReactorException {
55 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
56 addSources(reactor, INVALID_REL1);
60 fail("reactor.process should fail due to invalid relative path");
61 } catch (Exception e) {
62 assertEquals(IllegalArgumentException.class, e.getClass());
67 public void invalidAugRel2Test() throws SourceException, ReactorException {
69 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
70 addSources(reactor, INVALID_REL2);
74 fail("reactor.process should fail due to invalid relative path");
75 } catch (Exception e) {
76 assertEquals(IllegalArgumentException.class, e.getClass());
81 public void invalidAugAbs() throws SourceException, ReactorException {
83 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
84 addSources(reactor, INVALID_ABS);
88 fail("reactor.process should fail due to invalid absolute path");
89 } catch (Exception e) {
90 assertEquals(IllegalArgumentException.class, e.getClass());
95 public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
97 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
98 addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
102 fail("reactor.process should fail due to missing import from augment path");
103 } catch (Exception e) {
104 assertEquals(IllegalArgumentException.class, e.getClass());
109 public void invalidAugEmptyTest() throws SourceException {
111 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
112 addSources(reactor, INVALID_EMPTY);
116 fail("reactor.process should fail due to empty path");
117 } catch (Exception e) {
118 assertEquals(IllegalArgumentException.class, e.getClass());
123 public void invalidAugXPathTest() throws SourceException {
125 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
126 addSources(reactor, INVALID_XPATH);
130 fail("reactor.process should fail due to invalid XPath");
131 } catch (Exception e) {
132 assertEquals(IllegalArgumentException.class, e.getClass());
136 private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
137 for (YangStatementSourceImpl source : sources) {
138 reactor.addSource(source);