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.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
26 public class AugmentArgumentParsingTest {
28 private static final StatementStreamSource IMPORTED = sourceForResource(
29 "/semantic-statement-parser/augment-arg-parsing/imported.yang");
30 private static final StatementStreamSource VALID_ARGS = sourceForResource(
31 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
32 private static final StatementStreamSource INVALID_REL1 = sourceForResource(
33 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
34 private static final StatementStreamSource INVALID_REL2 = sourceForResource(
35 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
36 private static final StatementStreamSource INVALID_ABS = sourceForResource(
37 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
38 private static final StatementStreamSource INVALID_ABS_PREFIXED_NO_IMP = sourceForResource(
39 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
40 private static final StatementStreamSource INVALID_EMPTY = sourceForResource(
41 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
42 private static final StatementStreamSource INVALID_XPATH = sourceForResource(
43 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
46 public void validAugAbsTest() throws ReactorException {
48 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
49 reactor.addSources(IMPORTED, VALID_ARGS);
51 final EffectiveModelContext result = reactor.build();
52 assertNotNull(result);
56 public void invalidAugRel1Test() {
58 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
59 reactor.addSources(INVALID_REL1);
63 fail("reactor.process should fail due to invalid relative path");
64 } catch (ReactorException e) {
65 assertSourceExceptionCause(e, "Augment argument './aug1/aug11' is not valid");
70 public void invalidAugRel2Test() {
72 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
73 reactor.addSources(INVALID_REL2);
77 fail("reactor.process should fail due to invalid relative path");
78 } catch (ReactorException e) {
79 assertSourceExceptionCause(e, "Augment argument '../aug1/aug11' is not valid");
84 public void invalidAugAbs() {
86 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
87 reactor.addSources(INVALID_ABS);
91 fail("reactor.process should fail due to invalid absolute path");
92 } catch (ReactorException e) {
93 assertSourceExceptionCause(e, "Augment argument '//aug1/aug11/aug111' is not valid");
98 public void invalidAugAbsPrefixedNoImp() {
100 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
101 reactor.addSources(INVALID_ABS_PREFIXED_NO_IMP);
105 fail("reactor.process should fail due to missing import from augment path");
106 } catch (ReactorException e) {
107 assertSourceExceptionCause(e, "Failed to parse node 'imp:aug1'");
113 public void invalidAugEmptyTest() throws SourceException {
115 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
116 reactor.addSources(INVALID_EMPTY);
120 fail("reactor.process should fail due to empty path");
121 } catch (Exception e) {
122 assertEquals(IllegalArgumentException.class, e.getClass());
128 public void invalidAugXPathTest() throws SourceException {
130 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
131 reactor.addSources(INVALID_XPATH);
135 fail("reactor.process should fail due to invalid XPath");
136 } catch (Exception e) {
137 assertEquals(IllegalArgumentException.class, e.getClass());
141 private static void assertSourceExceptionCause(final Throwable e, final String start) {
142 final Throwable cause = e.getCause();
143 assertTrue(cause instanceof SourceException);
144 assertTrue(cause.getMessage().startsWith(start));