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.rfc7950.reactor.RFC7950Reactors;
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;
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 {
46 final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
47 .addSources(IMPORTED, VALID_ARGS)
49 assertNotNull(result);
53 public void invalidAugRel1Test() {
54 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_REL1);
58 fail("reactor.process should fail due to invalid relative path");
59 } catch (ReactorException e) {
60 assertSourceExceptionCause(e, "Augment argument './aug1/aug11' is not valid");
65 public void invalidAugRel2Test() {
66 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_REL2);
70 fail("reactor.process should fail due to invalid relative path");
71 } catch (ReactorException e) {
72 assertSourceExceptionCause(e, "Augment argument '../aug1/aug11' is not valid");
77 public void invalidAugAbs() {
78 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_ABS);
82 fail("reactor.process should fail due to invalid absolute path");
83 } catch (ReactorException e) {
84 assertSourceExceptionCause(e, "Augment argument '//aug1/aug11/aug111' is not valid");
89 public void invalidAugAbsPrefixedNoImp() {
90 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_ABS_PREFIXED_NO_IMP);
94 fail("reactor.process should fail due to missing import from augment path");
95 } catch (ReactorException e) {
96 assertSourceExceptionCause(e, "Failed to parse node 'imp:aug1'");
100 @Test(expected = IllegalArgumentException.class)
102 public void invalidAugEmptyTest() throws ReactorException {
103 RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_EMPTY).build();
104 fail("reactor.process should fail due to empty path");
107 @Test(expected = IllegalArgumentException.class)
109 public void invalidAugXPathTest() throws ReactorException {
110 RFC7950Reactors.defaultReactor().newBuild().addSources(INVALID_XPATH).build();
111 fail("reactor.process should fail due to invalid XPath");
114 private static void assertSourceExceptionCause(final Throwable exception, final String start) {
115 final Throwable cause = exception.getCause();
116 assertTrue(cause instanceof SourceException);
117 assertTrue(cause.getMessage().startsWith(start));