Enforce InstanceIdentifier creation
[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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInput;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17
18 public class Mdsal724Test {
19     @Test
20     @SuppressWarnings({ "rawtypes", "unchecked" })
21     public void testNotificationInstanceIdentifier() {
22         // An InstanceIdentifier pointing at a notification, unsafe to create
23         final var ex = assertThrows(IllegalArgumentException.class,
24             () -> InstanceIdentifier.create((Class) OutOfPixieDustNotification.class));
25         assertEquals("interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test"
26             + ".bi.ba.notification.rev150205.OutOfPixieDustNotification is not a valid path argument", ex.getMessage());
27     }
28
29     @Test
30     @SuppressWarnings({ "rawtypes", "unchecked" })
31     public void testRpcInputInstanceIdentifier() {
32         // An InstanceIdentifier pointing at a notification, unsafe to create
33         final var ex = assertThrows(IllegalArgumentException.class,
34             () -> InstanceIdentifier.create((Class) KnockKnockInput.class));
35         assertEquals("interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock"
36             + ".rev180723.KnockKnockInput is not a valid path argument", ex.getMessage());
37     }
38 }