b5c502ab89f57784610707aae764aba4cf15e46c
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6880Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertThrows;
16 import static org.junit.Assert.assertTrue;
17
18 import java.util.Collection;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27
28 public class Bug6880Test {
29     @Test
30     public void valid10Test() throws Exception {
31         final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
32         assertNotNull(schemaContext);
33
34         final DataSchemaNode findDataSchemaNode = schemaContext.findDataTreeChild(QName.create("foo", "my-leaf-list"))
35             .orElse(null);
36         assertThat(findDataSchemaNode, instanceOf(LeafListSchemaNode.class));
37         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
38
39         final Collection<? extends Object> defaults = myLeafList.getDefaults();
40         assertEquals(2, defaults.size());
41         assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
42     }
43
44     @Test
45     public void invalid10Test() {
46         final ReactorException ex = assertThrows(ReactorException.class,
47             () -> StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang"));
48         final Throwable cause = ex.getCause();
49         assertThat(cause, instanceOf(SourceException.class));
50         assertThat(cause.getMessage(), startsWith("DEFAULT is not valid for LEAF_LIST"));
51     }
52 }