33da2fe7ece7e8635add12a28e7d993fe986e086
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / Mdsal724Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.dom.codec.impl;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
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.mdsal.binding.dom.codec.api.IncorrectNestingException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInput;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20
21 public class Mdsal724Test extends AbstractBindingCodecTest {
22     @Test
23     public void testNotificationInstanceIdentifier() {
24         // An InstanceIdentifier pointing at a notification, unsafe to create
25         @SuppressWarnings({ "rawtypes", "unchecked" })
26         final var iid = InstanceIdentifier.create((Class) OutOfPixieDustNotification.class);
27
28         final var ex = assertThrows(IllegalArgumentException.class, () -> codecContext.toYangInstanceIdentifier(iid));
29         assertThat(ex.getMessage(), startsWith("Supplied class must not be a notification ("));
30     }
31
32     @Test
33     public void testRpcInputInstanceIdentifier() {
34         // An InstanceIdentifier pointing at a notification, unsafe to create
35         @SuppressWarnings({ "rawtypes", "unchecked" })
36         final var iid = InstanceIdentifier.create((Class) KnockKnockInput.class);
37         final var ex = assertThrows(IncorrectNestingException.class, () -> codecContext.toYangInstanceIdentifier(iid));
38         assertEquals("interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock."
39             + "rev180723.KnockKnockInput is not top-level item.", ex.getMessage());
40     }
41 }