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.transportpce.servicehandler.utils;
10 import static org.junit.Assert.assertTrue;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doAnswer;
13 import static org.mockito.Mockito.mock;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSpBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.PathTopologyBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes;
21 import org.opendaylight.yangtools.yang.binding.Notification;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public final class MockedNotificationServiceWrapper {
27 private static final Logger LOG = LoggerFactory.getLogger(MockedNotificationServiceWrapper.class);
28 private final NotificationPublishService notificationPublishService;
29 private Boolean rendererFailed = false;
31 public MockedNotificationServiceWrapper(NotificationPublishService notificationPublishService) {
32 this.notificationPublishService = notificationPublishService;
35 public NotificationPublishService getMockedNotificationService() throws InterruptedException {
36 final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
37 doAnswer(invocation -> {
38 final Object notif = invocation.getArguments()[0];
39 LOG.info("notif received : {}", notif);
40 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
41 if (this.rendererFailed) {
42 LOG.info("putting failed renderer notification");
43 RendererRpcResultSp serviceRpcResultSp = new RendererRpcResultSpBuilder()
44 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
45 .setServiceName("service 1").setStatus(RpcStatusEx.Failed).setStatusMessage("Renderer Failed")
46 .setPathTopology(new PathTopologyBuilder().build()).build();
47 MockedNotificationServiceWrapper.this.notificationPublishService.putNotification(serviceRpcResultSp);
48 this.rendererFailed = false;
50 MockedNotificationServiceWrapper.this.notificationPublishService.putNotification((Notification) notif);
53 }).when(mockedNotificationService).putNotification(any(Notification.class));
54 return mockedNotificationService;
57 public void setRendererFailed() {
58 this.rendererFailed = true;