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.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25 public class AugmentArgumentParsingTest {
27 private static final StatementStreamSource IMPORTED = sourceForResource(
28 "/semantic-statement-parser/augment-arg-parsing/imported.yang");
29 private static final StatementStreamSource VALID_ARGS = sourceForResource(
30 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
31 private static final StatementStreamSource INVALID_REL1 = sourceForResource(
32 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
33 private static final StatementStreamSource INVALID_REL2 = sourceForResource(
34 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
35 private static final StatementStreamSource INVALID_ABS = sourceForResource(
36 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
37 private static final StatementStreamSource INVALID_ABS_PREFIXED_NO_IMP = sourceForResource(
38 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
39 private static final StatementStreamSource INVALID_EMPTY = sourceForResource(
40 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
41 private static final StatementStreamSource INVALID_XPATH = sourceForResource(
42 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
45 public void validAugAbsTest() throws ReactorException {
47 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
48 reactor.addSources(IMPORTED, VALID_ARGS);
50 final EffectiveModelContext result = reactor.build();
51 assertNotNull(result);
55 public void invalidAugRel1Test() {
57 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
58 reactor.addSources(INVALID_REL1);
62 fail("reactor.process should fail due to invalid relative path");
63 } catch (ReactorException e) {
64 assertSourceExceptionCause(e, "Augment argument './aug1/aug11' is not valid");
69 public void invalidAugRel2Test() {
71 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
72 reactor.addSources(INVALID_REL2);
76 fail("reactor.process should fail due to invalid relative path");
77 } catch (ReactorException e) {
78 assertSourceExceptionCause(e, "Augment argument '../aug1/aug11' is not valid");
83 public void invalidAugAbs() {
85 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
86 reactor.addSources(INVALID_ABS);
90 fail("reactor.process should fail due to invalid absolute path");
91 } catch (ReactorException e) {
92 assertSourceExceptionCause(e, "Augment argument '//aug1/aug11/aug111' is not valid");
97 public void invalidAugAbsPrefixedNoImp() {
99 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
100 reactor.addSources(INVALID_ABS_PREFIXED_NO_IMP);
104 fail("reactor.process should fail due to missing import from augment path");
105 } catch (ReactorException e) {
106 assertSourceExceptionCause(e, "Failed to parse node 'imp:aug1'");
110 @Test(expected = IllegalArgumentException.class)
112 public void invalidAugEmptyTest() throws ReactorException {
114 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
115 reactor.addSources(INVALID_EMPTY);
118 fail("reactor.process should fail due to empty path");
121 @Test(expected = IllegalArgumentException.class)
123 public void invalidAugXPathTest() throws ReactorException {
125 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
126 reactor.addSources(INVALID_XPATH);
128 fail("reactor.process should fail due to invalid XPath");
131 private static void assertSourceExceptionCause(final Throwable exception, final String start) {
132 final Throwable cause = exception.getCause();
133 assertTrue(cause instanceof SourceException);
134 assertTrue(cause.getMessage().startsWith(start));