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;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.verifyNoInteractions;
15 import static org.mockito.Mockito.when;
17 import com.google.common.util.concurrent.ListenableFuture;
18 import org.junit.jupiter.api.Test;
19 import org.junit.jupiter.api.extension.ExtendWith;
20 import org.mockito.InjectMocks;
21 import org.mockito.Mock;
22 import org.mockito.junit.jupiter.MockitoExtension;
23 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
24 import org.opendaylight.transportpce.common.ResponseCodes;
25 import org.opendaylight.transportpce.pce.service.PathComputationService;
26 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ServiceNotificationTypes;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
42 @ExtendWith(MockitoExtension.class)
43 public class PCEServiceWrapperTest extends AbstractTest {
46 private PathComputationService pathComputationServiceMock;
48 private NotificationPublishService notificationPublishServiceMock;
50 private PCEServiceWrapper pceServiceWrapperMock;
54 void performPCENullSdncRequestHeader() {
55 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
56 input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build();
57 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
58 assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
59 assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode());
60 verifyNoInteractions(this.pathComputationServiceMock);
64 void performPCENullServiceName() {
65 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
66 input = new ServiceCreateInputBuilder(input).setServiceName(null).build();
67 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
68 assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
69 assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode());
70 verifyNoInteractions(this.pathComputationServiceMock);
74 void performPCENullCommonId() {
75 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
76 input = new TempServiceCreateInputBuilder(input).setCommonId(null).build();
77 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
78 assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
79 assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode());
80 verifyNoInteractions(this.pathComputationServiceMock);
85 void cancelPCEResourceNullServiceName() {
86 CancelResourceReserveOutput pceResponse =
87 this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult);
88 assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
89 assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode());
90 verifyNoInteractions(this.pathComputationServiceMock);
94 void cancelPCEResourceValid() {
95 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
96 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
97 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
98 CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder()
99 .setConfigurationResponseCommon(configurationResponseCommon).build();
100 ListenableFuture<CancelResourceReserveOutput> response = ServiceDataUtils.returnFuture(output);
101 when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class)))
102 .thenReturn(response);
103 CancelResourceReserveOutput pceResponse = this.pceServiceWrapperMock
104 .cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult);
105 assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
106 assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
107 assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage());
108 verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class));
112 void performPCEValid() {
113 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
114 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
115 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
116 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
117 .setConfigurationResponseCommon(configurationResponseCommon).build();
118 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
119 when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
120 .thenReturn(response);
121 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
122 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
123 assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
124 assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
125 assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage());
126 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
130 void performPCETempValid() {
131 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
132 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
133 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
134 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
135 .setConfigurationResponseCommon(configurationResponseCommon).build();
136 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
137 when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
138 .thenReturn(response);
139 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
140 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
141 assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
142 assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
143 assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage());
144 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));