Fix code generation with leafrefs pointing to optional members
[mdsal.git] / binding / mdsal-binding-generator / src / test / java / org / opendaylight / mdsal / binding / generator / impl / Bug4621Test.java
1 /*
2  * Copyright (c) 2015 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.mdsal.binding.generator.impl;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertThrows;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
17
18 public class Bug4621Test {
19     @Test
20     public void testMissingLeafrefTarget() {
21         final var context = YangParserTestUtils.parseYangResource("/bug4621.yang");
22         final var uoe = assertThrows(UnsupportedOperationException.class,
23             () -> DefaultBindingGenerator.generateFor(context));
24         assertEquals("Cannot ascertain type", uoe.getMessage());
25         final var cause = uoe.getCause();
26         assertThat(cause, instanceOf(IllegalArgumentException.class));
27         assertEquals("Failed to find leafref target /foo:neighbor/foo:mystring1", cause.getMessage());
28     }
29 }