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.Matchers.any;
13 import static org.mockito.Mockito.doAnswer;
14 import static org.mockito.Mockito.mock;
16 import com.google.common.collect.Lists;
17 import java.util.List;
18 import org.junit.Assert;
19 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatus;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatusChanged;
23 import org.opendaylight.yangtools.yang.binding.Notification;
25 final class MockedNotificationServiceWrapper {
26 private final List<Notification> publishedNotifications;
28 MockedNotificationServiceWrapper() {
29 this.publishedNotifications = Lists.newArrayList();
32 NotificationPublishService getMockedNotificationService() throws InterruptedException {
33 final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
35 doAnswer(invocation -> {
36 final Object notif = invocation.getArguments()[0];
37 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
38 MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
40 }).when(mockedNotificationService).putNotification(any(Notification.class));
41 return mockedNotificationService;
44 void assertNotificationsCount(final int count) {
45 assertEquals(count, this.publishedNotifications.size());
48 void assertInstructionStatusChangedNotification(final int idx, final InstructionId id, final InstructionStatus status) {
49 assertTrue(InstructionStatusChanged.class.isAssignableFrom(this.publishedNotifications.get(idx).getClass()));
50 final InstructionStatusChanged firstNotification = (InstructionStatusChanged) this.publishedNotifications.get(idx);
51 assertInstructionStatusChangedNotification(id, status, firstNotification);
54 private void assertInstructionStatusChangedNotification(final InstructionId id, final InstructionStatus status,
55 final InstructionStatusChanged firstNotification) {
56 Assert.assertEquals(id, firstNotification.getId());
57 Assert.assertEquals(status, firstNotification.getStatus());