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.rev200520.ServiceRpcResultSp;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceRpcResultSpBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.service.rpc.result.sp.PathTopologyBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.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 Notification publishedNotification;
29 private final NotificationPublishService notificationPublishService;
30 private Boolean rendererFailed = false;
32 public MockedNotificationServiceWrapper(NotificationPublishService notificationPublishService) {
33 this.publishedNotification = null;
34 this.notificationPublishService = notificationPublishService;
37 public NotificationPublishService getMockedNotificationService() throws InterruptedException {
38 final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
39 doAnswer(invocation -> {
40 final Object notif = invocation.getArguments()[0];
41 LOG.info("notif received : {}", notif);
42 assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
43 if (this.rendererFailed) {
44 LOG.info("putting failed renderer notification");
45 ServiceRpcResultSp serviceRpcResultSp = new ServiceRpcResultSpBuilder()
46 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
47 .setServiceName("service 1").setStatus(RpcStatusEx.Failed).setStatusMessage("Renderer Failed")
48 .setPathTopology(new PathTopologyBuilder().build()).build();
49 MockedNotificationServiceWrapper.this.notificationPublishService.putNotification(serviceRpcResultSp);
50 this.rendererFailed = false;
52 MockedNotificationServiceWrapper.this.notificationPublishService.putNotification((Notification) notif);
55 }).when(mockedNotificationService).putNotification(any(Notification.class));
56 return mockedNotificationService;
59 public void setRendererFailed() {
60 this.rendererFailed = true;