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
8 package org.opendaylight.mdsal.binding.dom.adapter.invoke;
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.assertNotNull;
14 import static org.junit.Assert.assertThrows;
15 import static org.mockito.Mockito.mock;
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.util.concurrent.UncheckedExecutionException;
19 import java.lang.invoke.MethodHandle;
20 import java.lang.invoke.WrongMethodTypeException;
21 import org.junit.Test;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener;
23 import org.opendaylight.yangtools.yang.binding.Augmentation;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.Notification;
26 import org.opendaylight.yangtools.yang.binding.NotificationListener;
27 import org.opendaylight.yangtools.yang.common.QName;
29 public class NotificationListenerInvokerTest {
31 public void fromTest() throws Exception {
32 assertNotNull(NotificationListenerInvoker.from(OpendaylightTestNotificationListener.class));
36 public void fromWithExceptionTest() {
37 final var cause = assertThrows(UncheckedExecutionException.class,
38 () -> NotificationListenerInvoker.from(TestPrivateInterface.class))
40 assertThat(cause, instanceOf(IllegalStateException.class));
41 assertThat(cause.getCause(), instanceOf(IllegalAccessException.class));
45 public void invokeNotification() {
46 final NotificationListener notificationListener = mock(NotificationListener.class);
47 final MethodHandle methodHandle = mock(MethodHandle.class);
48 final NotificationListenerInvoker notificationListenerInvoker =
49 new NotificationListenerInvoker(ImmutableMap.of(QName.create("test", "test"), methodHandle));
51 final var ex = assertThrows(WrongMethodTypeException.class,
52 () -> notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"),
54 assertEquals("expected null but found (NotificationListener,DataContainer)void", ex.getMessage());
57 private interface TestPrivateInterface extends NotificationListener, Augmentation {
58 QName QNAME = QName.create("test", "test");
60 void onTestNotificationInterface(TestNotificationInterface notif);
63 public interface TestNotificationInterface extends DataObject, Notification<TestNotificationInterface> {
64 QName QNAME = QName.create("test", "test");