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;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.junit.After;
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.rev220808.CancelResourceReserveInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ServiceNotificationTypes;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
41 public class PCEServiceWrapperTest extends AbstractTest {
44 private PathComputationService pathComputationServiceMock;
46 private NotificationPublishService notificationPublishServiceMock;
48 private PCEServiceWrapper pceServiceWrapperMock;
50 private AutoCloseable closeable;
53 public void openMocks() throws NoSuchMethodException {
54 closeable = MockitoAnnotations.openMocks(this);
58 public void performPCENullSdncRequestHeader() {
59 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
60 input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build();
61 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
62 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
63 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
64 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
65 pceResponse.getConfigurationResponseCommon().getResponseCode());
66 Mockito.verifyNoInteractions(this.pathComputationServiceMock);
70 public void performPCENullServiceName() {
71 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
72 input = new ServiceCreateInputBuilder(input).setServiceName(null).build();
73 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
74 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
75 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
76 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
77 pceResponse.getConfigurationResponseCommon().getResponseCode());
78 Mockito.verifyNoInteractions(this.pathComputationServiceMock);
82 public void performPCENullCommonId() {
83 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
84 input = new TempServiceCreateInputBuilder(input).setCommonId(null).build();
85 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
86 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
87 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
88 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
89 pceResponse.getConfigurationResponseCommon().getResponseCode());
90 Mockito.verifyNoInteractions(this.pathComputationServiceMock);
95 public void cancelPCEResourceNullServiceName() {
96 CancelResourceReserveOutput pceResponse =
97 this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult);
98 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
99 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
100 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
101 pceResponse.getConfigurationResponseCommon().getResponseCode());
102 Mockito.verifyNoInteractions(this.pathComputationServiceMock);
106 public void cancelPCEResourceValid() {
107 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
108 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
109 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
110 CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder()
111 .setConfigurationResponseCommon(configurationResponseCommon).build();
112 ListenableFuture<CancelResourceReserveOutput> response = ServiceDataUtils.returnFuture(output);
113 Mockito.when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class)))
114 .thenReturn(response);
115 CancelResourceReserveOutput pceResponse =
116 this.pceServiceWrapperMock.cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult);
117 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
118 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
119 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
120 pceResponse.getConfigurationResponseCommon().getResponseCode());
121 Assert.assertEquals("PCE calculation in progress",
122 pceResponse.getConfigurationResponseCommon().getResponseMessage());
123 verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class));
127 public void performPCEValid() {
128 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
129 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
130 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
131 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
132 .setConfigurationResponseCommon(configurationResponseCommon).build();
133 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
134 Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
135 .thenReturn(response);
136 ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
137 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
138 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
139 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
140 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
141 pceResponse.getConfigurationResponseCommon().getResponseCode());
142 Assert.assertEquals("PCE calculation in progress",
143 pceResponse.getConfigurationResponseCommon().getResponseMessage());
144 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
148 public void performPCETempValid() {
149 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
150 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
151 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
152 PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
153 .setConfigurationResponseCommon(configurationResponseCommon).build();
154 ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
155 Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
156 .thenReturn(response);
157 TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
158 PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
159 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
160 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
161 Assert.assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
162 Assert.assertEquals("PCE calculation in progress",
163 pceResponse.getConfigurationResponseCommon().getResponseMessage());
164 verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
167 @After public void releaseMocks() throws Exception {