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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
15 import org.junit.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
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.ReactorDeclaredModel;
24 public class AugmentArgumentParsingTest {
26 private static final StatementStreamSource IMPORTED = sourceForResource(
27 "/semantic-statement-parser/augment-arg-parsing/imported.yang");
28 private static final StatementStreamSource VALID_ARGS = sourceForResource(
29 "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
30 private static final StatementStreamSource INVALID_REL1 = sourceForResource(
31 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
32 private static final StatementStreamSource INVALID_REL2 = sourceForResource(
33 "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
34 private static final StatementStreamSource INVALID_ABS = sourceForResource(
35 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
36 private static final StatementStreamSource INVALID_ABS_PREFIXED_NO_IMP = sourceForResource(
37 "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
38 private static final StatementStreamSource INVALID_EMPTY = sourceForResource(
39 "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
40 private static final StatementStreamSource INVALID_XPATH = sourceForResource(
41 "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
44 public void validAugAbsTest() throws ReactorException {
45 final ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
46 .addSources(IMPORTED, VALID_ARGS)
48 assertNotNull(result);
52 public void invalidAugRel1Test() {
53 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_REL1);
57 fail("reactor.process should fail due to invalid relative path");
58 } catch (ReactorException e) {
59 assertSourceExceptionCause(e, "Augment argument './aug1/aug11' is not valid");
64 public void invalidAugRel2Test() {
65 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_REL2);
69 fail("reactor.process should fail due to invalid relative path");
70 } catch (ReactorException e) {
71 assertSourceExceptionCause(e, "Augment argument '../aug1/aug11' is not valid");
76 public void invalidAugAbs() {
77 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_ABS);
81 fail("reactor.process should fail due to invalid absolute path");
82 } catch (ReactorException e) {
83 assertSourceExceptionCause(e, "Augment argument '//aug1/aug11/aug111' is not valid");
88 public void invalidAugAbsPrefixedNoImp() {
89 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_ABS_PREFIXED_NO_IMP);
93 fail("reactor.process should fail due to missing import from augment path");
94 } catch (ReactorException e) {
95 assertSourceExceptionCause(e, "Failed to parse node 'imp:aug1'");
99 @Test(expected = IllegalArgumentException.class)
101 public void invalidAugEmptyTest() throws ReactorException {
102 RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_EMPTY).build();
103 fail("reactor.process should fail due to empty path");
106 @Test(expected = IllegalArgumentException.class)
108 public void invalidAugXPathTest() throws ReactorException {
109 RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_XPATH).build();
110 fail("reactor.process should fail due to invalid XPath");
113 private static void assertSourceExceptionCause(final Throwable exception, final String start) {
114 final Throwable cause = exception.getCause();
115 assertTrue(cause instanceof SourceException);
116 assertTrue(cause.getMessage().startsWith(start));