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.parser.stmt.rfc7950;
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;
16 import java.util.Collection;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 public class Bug6880Test {
28 private static final String FOO_NS = "foo";
31 public void valid10Test() throws Exception {
32 final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
33 assertNotNull(schemaContext);
35 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext,
36 SchemaPath.create(true, QName.create(FOO_NS, "my-leaf-list")));
37 assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
38 final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
40 final Collection<? extends Object> defaults = myLeafList.getDefaults();
41 assertEquals(2, defaults.size());
42 assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
46 public void invalid10Test() throws Exception {
48 StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang");
49 fail("Test should fail due to invalid Yang 1.0");
50 } catch (final SomeModifiersUnresolvedException e) {
51 assertTrue(e.getCause().getMessage().startsWith("DEFAULT is not valid for LEAF_LIST"));