2 * Copyright (c) 2014 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.bgpcep.programming.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doAnswer;
14 import static org.mockito.Mockito.mock;
15 import static org.opendaylight.protocol.util.CheckTestUtil.checkEquals;
17 import java.util.ArrayList;
18 import java.util.List;
19 import org.junit.Assert;
20 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatus;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatusChanged;
24 import org.opendaylight.yangtools.yang.binding.Notification;
26 final class MockedNotificationServiceWrapper {
27 private final List<Notification> publishedNotifications = new ArrayList<>();
29 NotificationPublishService getMockedNotificationService() throws InterruptedException {
30 final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
32 doAnswer(invocation -> {
33 final Object notif = invocation.getArguments()[0];
34 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
35 MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
37 }).when(mockedNotificationService).putNotification(any(Notification.class));
38 return mockedNotificationService;
41 void assertNotificationsCount(final int count) throws Exception {
42 checkEquals(() -> assertEquals(count, this.publishedNotifications.size()));
45 void assertInstructionStatusChangedNotification(final int idx, final InstructionId id,
46 final InstructionStatus status) {
47 assertTrue(InstructionStatusChanged.class.isAssignableFrom(this.publishedNotifications.get(idx).getClass()));
48 final InstructionStatusChanged firstNotification =
49 (InstructionStatusChanged) this.publishedNotifications.get(idx);
50 assertInstructionStatusChangedNotification(id, status, firstNotification);
53 private static void assertInstructionStatusChangedNotification(final InstructionId id,
54 final InstructionStatus status, final InstructionStatusChanged firstNotification) {
55 Assert.assertEquals(id, firstNotification.getId());
56 Assert.assertEquals(status, firstNotification.getStatus());