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;
15 import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
17 import com.google.common.collect.Lists;
18 import java.util.List;
19 import org.junit.Assert;
20 import org.opendaylight.controller.md.sal.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;
29 MockedNotificationServiceWrapper() {
30 this.publishedNotifications = Lists.newArrayList();
33 NotificationPublishService getMockedNotificationService() throws InterruptedException {
34 final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
36 doAnswer(invocation -> {
37 final Object notif = invocation.getArguments()[0];
38 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
39 MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
41 }).when(mockedNotificationService).putNotification(any(Notification.class));
42 return mockedNotificationService;
45 void assertNotificationsCount(final int count) throws Exception {
46 checkEquals(()-> assertEquals(count, this.publishedNotifications.size()));
49 void assertInstructionStatusChangedNotification(final int idx, final InstructionId id, final InstructionStatus status) {
50 assertTrue(InstructionStatusChanged.class.isAssignableFrom(this.publishedNotifications.get(idx).getClass()));
51 final InstructionStatusChanged firstNotification = (InstructionStatusChanged) this.publishedNotifications.get(idx);
52 assertInstructionStatusChangedNotification(id, status, firstNotification);
55 private void assertInstructionStatusChangedNotification(final InstructionId id, final InstructionStatus status,
56 final InstructionStatusChanged firstNotification) {
57 Assert.assertEquals(id, firstNotification.getId());
58 Assert.assertEquals(status, firstNotification.getStatus());