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 org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
20 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
21 import org.opendaylight.controller.md.sal.binding.impl.compat.HeliumNotificationProviderServiceAdapter;
22 import org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest;
23 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.OpendaylightMdsalListTestListener;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChangedBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.binding.NotificationListener;
32 public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificationBrokerTest {
34 private NotificationProviderService notificationProviderService;
37 public void initTest() {
38 final NotificationService notificationService = getNotificationService();
39 final NotificationPublishService notificationPublishService = getNotificationPublishService();
40 notificationProviderService = new HeliumNotificationProviderServiceAdapter(notificationPublishService, notificationService);
43 private TwoLevelListChanged createTestData() {
44 final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
45 tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().setKey(new TopLevelListKey("test")).build()));
50 public void testNotifSubscriptionForwarded() throws InterruptedException {
51 final CountDownLatch latch = new CountDownLatch(1);
52 final TwoLevelListChanged testData = createTestData();
54 final NotifTestListener testNotifListener = new NotifTestListener(latch);
55 final ListenerRegistration<NotificationListener> listenerRegistration =
56 notificationProviderService.registerNotificationListener(testNotifListener);
57 notificationProviderService.publish(testData);
60 assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
61 assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
62 listenerRegistration.close();
65 private static class NotifTestListener implements OpendaylightMdsalListTestListener {
66 private List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
67 private CountDownLatch latch;
69 public NotifTestListener(CountDownLatch latch) {
74 public void onTwoLevelListChanged(TwoLevelListChanged notification) {
75 receivedNotifications.add(notification);
79 public List<TwoLevelListChanged> getReceivedNotifications() {
80 return receivedNotifications;