2 * Copyright (c) 2015 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.controller.md.sal.binding.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import com.google.common.collect.ImmutableList;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.CountDownLatch;
17 import java.util.concurrent.TimeUnit;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
21 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
22 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
23 import org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest;
24 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.OpendaylightMdsalListTestListener;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChangedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.binding.NotificationListener;
34 public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificationBrokerTest {
36 private NotificationProviderService notificationProviderService;
39 public void initTest() {
40 final NotificationService notificationService = getNotificationService();
41 final NotificationPublishService notificationPublishService = getNotificationPublishService();
42 notificationProviderService = new HeliumNotificationProviderServiceAdapter(notificationPublishService,
46 private static TwoLevelListChanged createTestData() {
47 final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
48 tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()));
53 public void testNotifSubscriptionForwarded() throws InterruptedException {
54 final CountDownLatch latch = new CountDownLatch(1);
55 final TwoLevelListChanged testData = createTestData();
57 final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch);
58 final ListenerRegistration<NotificationListener> listenerRegistration =
59 notificationProviderService.registerNotificationListener(testNotifListener);
60 notificationProviderService.publish(testData);
62 latch.await(500L, TimeUnit.MILLISECONDS);
63 assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
64 assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
65 listenerRegistration.close();
68 private static class NotifTestListenerChild extends NotifTestListener {
70 NotifTestListenerChild(final CountDownLatch latch) {
75 private static class NotifTestListener implements OpendaylightMdsalListTestListener {
76 private final List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
77 private final CountDownLatch latch;
79 NotifTestListener(final CountDownLatch latch) {
84 public void onTwoLevelListChanged(final TwoLevelListChanged notification) {
85 receivedNotifications.add(notification);
89 public List<TwoLevelListChanged> getReceivedNotifications() {
90 return receivedNotifications;