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 java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
16 import com.google.common.collect.ImmutableList;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.concurrent.CountDownLatch;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
24 import org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest;
25 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.OpendaylightMdsalListTestListener;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChangedBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 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, notificationService);
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 public NotifTestListenerChild(final CountDownLatch latch) {
73 private static class NotifTestListener implements OpendaylightMdsalListTestListener {
74 private List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
75 private CountDownLatch latch;
77 public NotifTestListener(CountDownLatch latch) {
82 public void onTwoLevelListChanged(TwoLevelListChanged notification) {
83 receivedNotifications.add(notification);
87 public List<TwoLevelListChanged> getReceivedNotifications() {
88 return receivedNotifications;