Fixup Augmentable and Identifiable methods changing
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / BackwardsCompatibleNotificationBrokerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
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;
32
33 public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificationBrokerTest {
34
35     private NotificationProviderService notificationProviderService;
36
37     @Before
38     public void initTest() {
39         final NotificationService notificationService = getNotificationService();
40         final NotificationPublishService notificationPublishService = getNotificationPublishService();
41         notificationProviderService = new HeliumNotificationProviderServiceAdapter(notificationPublishService,
42                 notificationService);
43     }
44
45     private TwoLevelListChanged createTestData() {
46         final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
47         tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()));
48         return tb.build();
49     }
50
51     @Test
52     public void testNotifSubscriptionForwarded() throws InterruptedException {
53         final CountDownLatch latch = new CountDownLatch(1);
54         final TwoLevelListChanged testData = createTestData();
55
56         final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch);
57         final ListenerRegistration<NotificationListener> listenerRegistration =
58                 notificationProviderService.registerNotificationListener(testNotifListener);
59         notificationProviderService.publish(testData);
60
61         latch.await(500L, TimeUnit.MILLISECONDS);
62         assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
63         assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
64         listenerRegistration.close();
65     }
66
67     private static class NotifTestListenerChild extends  NotifTestListener {
68
69         NotifTestListenerChild(final CountDownLatch latch) {
70             super(latch);
71         }
72     }
73
74     private static class NotifTestListener implements OpendaylightMdsalListTestListener {
75         private final List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
76         private final CountDownLatch latch;
77
78         NotifTestListener(final CountDownLatch latch) {
79             this.latch = latch;
80         }
81
82         @Override
83         public void onTwoLevelListChanged(final TwoLevelListChanged notification) {
84             receivedNotifications.add(notification);
85             latch.countDown();
86         }
87
88         public List<TwoLevelListChanged> getReceivedNotifications() {
89             return receivedNotifications;
90         }
91     }
92 }