2 * @author Maros Marsalek
6 * Copyright (c) 2012 by Cisco Systems, Inc.
9 package org.opendaylight.bgpcep.programming.impl;
11 import com.google.common.collect.Lists;
12 import junit.framework.Assert;
13 import org.mockito.invocation.InvocationOnMock;
14 import org.mockito.stubbing.Answer;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatusChanged;
19 import org.opendaylight.yangtools.yang.binding.Notification;
21 import java.util.List;
23 import static junit.framework.Assert.assertTrue;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.doAnswer;
27 import static org.mockito.Mockito.mock;
29 final class MockedNotificationServiceWrapper {
30 private List<Notification> publishedNotifications;
32 MockedNotificationServiceWrapper() {
33 publishedNotifications = Lists.newArrayList();
36 NotificationProviderService getMockedNotificationService() {
37 NotificationProviderService mockedNotificationService = mock(NotificationProviderService.class);
39 doAnswer(new Answer() {
41 public Object answer(InvocationOnMock invocation) throws Throwable {
42 Object notif = invocation.getArguments()[0];
43 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
44 publishedNotifications.add((Notification) notif);
47 }).when(mockedNotificationService).publish(any(Notification.class));
48 return mockedNotificationService;
51 void assertNotificationsCount(int count) {
52 assertEquals(count, publishedNotifications.size());
55 public void assertInstructionStatusChangedNotification(int idx, InstructionId id, InstructionStatus status) {
56 assertTrue(InstructionStatusChanged.class.isAssignableFrom(publishedNotifications.get(idx).getClass()));
57 InstructionStatusChanged firstNotification = (InstructionStatusChanged) publishedNotifications.get(idx);
58 assertInstructionStatusChangedNotification(id, status, firstNotification);
61 private void assertInstructionStatusChangedNotification(InstructionId id, InstructionStatus status,
62 InstructionStatusChanged firstNotification) {
63 Assert.assertEquals(id, firstNotification.getId());
64 Assert.assertEquals(status, firstNotification.getStatus());