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 org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
15 import com.google.common.collect.ImmutableList;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.concurrent.CountDownLatch;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
22 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
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, notificationService);
44 private TwoLevelListChanged createTestData() {
45 final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
46 tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().setKey(new TopLevelListKey("test")).build()));
51 public void testNotifSubscriptionForwarded() throws InterruptedException {
52 final CountDownLatch latch = new CountDownLatch(1);
53 final TwoLevelListChanged testData = createTestData();
55 final NotifTestListener testNotifListener = new NotifTestListener(latch);
56 final ListenerRegistration<NotificationListener> listenerRegistration =
57 notificationProviderService.registerNotificationListener(testNotifListener);
58 notificationProviderService.publish(testData);
61 assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
62 assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
63 listenerRegistration.close();
66 private static class NotifTestListener implements OpendaylightMdsalListTestListener {
67 private List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
68 private CountDownLatch latch;
70 public NotifTestListener(CountDownLatch latch) {
75 public void onTwoLevelListChanged(TwoLevelListChanged notification) {
76 receivedNotifications.add(notification);
80 public List<TwoLevelListChanged> getReceivedNotifications() {
81 return receivedNotifications;