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;
33 public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificationBrokerTest {
35 private NotificationProviderService notificationProviderService;
38 public void initTest() {
39 final NotificationService notificationService = getNotificationService();
40 final NotificationPublishService notificationPublishService = getNotificationPublishService();
41 notificationProviderService = new HeliumNotificationProviderServiceAdapter(notificationPublishService,
45 private TwoLevelListChanged createTestData() {
46 final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
47 tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().setKey(new TopLevelListKey("test")).build()));
52 public void testNotifSubscriptionForwarded() throws InterruptedException {
53 final CountDownLatch latch = new CountDownLatch(1);
54 final TwoLevelListChanged testData = createTestData();
56 final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch);
57 final ListenerRegistration<NotificationListener> listenerRegistration =
58 notificationProviderService.registerNotificationListener(testNotifListener);
59 notificationProviderService.publish(testData);
61 latch.await(500L, TimeUnit.MILLISECONDS);
62 assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
63 assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
64 listenerRegistration.close();
67 private static class NotifTestListenerChild extends NotifTestListener {
69 NotifTestListenerChild(final CountDownLatch latch) {
74 private static class NotifTestListener implements OpendaylightMdsalListTestListener {
75 private final List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
76 private final CountDownLatch latch;
78 NotifTestListener(CountDownLatch latch) {
83 public void onTwoLevelListChanged(TwoLevelListChanged notification) {
84 receivedNotifications.add(notification);
88 public List<TwoLevelListChanged> getReceivedNotifications() {
89 return receivedNotifications;