2 * Copyright © 2018 Orange, 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.service;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
12 import static org.mockito.Mockito.verifyZeroInteractions;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
23 import org.opendaylight.transportpce.common.ResponseCodes;
24 import org.opendaylight.transportpce.pce.service.PathComputationService;
25 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
26 import org.opendaylight.transportpce.test.AbstractTest;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
41 public class PCEServiceWrapperTest extends AbstractTest {
44 private PathComputationService pathComputationServiceMock;
46 private NotificationPublishService notificationPublishServiceMock;
48 private PCEServiceWrapper pceServiceWrapperMock;
51 public void init() throws NoSuchMethodException {
52 MockitoAnnotations.initMocks(this);
56 public void performPCENullSdncRequestHeader() {
57 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
58 input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build();
59 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
60 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
61 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
62 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
63 pceResponse.getConfigurationResponseCommon().getResponseCode());
64 verifyZeroInteractions(this.pathComputationServiceMock);
68 public void performPCENullServiceName() {
69 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
70 input = new ServiceCreateInputBuilder(input).setServiceName(null).build();
71 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
72 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
73 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
74 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
75 pceResponse.getConfigurationResponseCommon().getResponseCode());
76 verifyZeroInteractions(this.pathComputationServiceMock);
80 public void performPCENullCommonId() {
81 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
82 input = new TempServiceCreateInputBuilder(input).setCommonId(null).build();
83 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
84 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
85 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
86 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
87 pceResponse.getConfigurationResponseCommon().getResponseCode());
88 verifyZeroInteractions(this.pathComputationServiceMock);
93 public void cancelPCEResourceNullServiceName() {
94 CancelResourceReserveOutput pceResponse =
95 this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult);
96 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
97 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
98 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
99 pceResponse.getConfigurationResponseCommon().getResponseCode());
100 verifyZeroInteractions(this.pathComputationServiceMock);
104 public void cancelPCEResourceValid() {
105 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
106 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
107 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
108 CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder()
109 .setConfigurationResponseCommon(configurationResponseCommon).build();
110 ListenableFuture<CancelResourceReserveOutput> response = ServiceDataUtils.returnFuture(output);
111 Mockito.when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class)))
112 .thenReturn(response);
113 CancelResourceReserveOutput pceResponse =
114 this.pceServiceWrapperMock.cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult);
115 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
116 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
117 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
118 pceResponse.getConfigurationResponseCommon().getResponseCode());
119 Assert.assertEquals("PCE calculation in progress",
120 pceResponse.getConfigurationResponseCommon().getResponseMessage());
121 verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class));
125 public void performPCEValid() {
126 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
127 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
128 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
129 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
130 .setConfigurationResponseCommon(configurationResponseCommon).build();
131 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
132 Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
133 .thenReturn(response);
134 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
135 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
136 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
137 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
138 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
139 pceResponse.getConfigurationResponseCommon().getResponseCode());
140 Assert.assertEquals("PCE calculation in progress",
141 pceResponse.getConfigurationResponseCommon().getResponseMessage());
142 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
146 public void performPCETempValid() {
147 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
148 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
149 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
150 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
151 .setConfigurationResponseCommon(configurationResponseCommon).build();
152 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
153 Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
154 .thenReturn(response);
155 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
156 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
157 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
158 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
159 Assert.assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
160 Assert.assertEquals("PCE calculation in progress",
161 pceResponse.getConfigurationResponseCommon().getResponseMessage());
162 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));