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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertNull;
13 import static org.junit.jupiter.api.Assertions.assertTrue;
14 import static org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl.LogMessages;
16 import java.util.Optional;
17 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20 import org.opendaylight.transportpce.common.OperationResult;
21 import org.opendaylight.transportpce.common.ResponseCodes;
22 import org.opendaylight.transportpce.servicehandler.ServiceInput;
23 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
24 import org.opendaylight.transportpce.test.AbstractTest;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParameters;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
39 import org.opendaylight.yangtools.yang.common.Uint32;
41 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
42 @SuppressWarnings("deprecation")
43 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
45 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
49 DataBroker dataBroker = this.getNewDataBroker();
50 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
54 void modifyIfServiceNotPresent() {
55 OperationResult result = this.serviceDataStoreOperations
56 .modifyService("service 1", State.InService, AdminStates.InService);
57 assertFalse(result.isSuccess());
58 assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage());
62 void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
63 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
64 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
65 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
66 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
67 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
68 .setConfigurationResponseCommon(configurationResponseCommon).build();
69 String result = serviceDataStoreOperations
70 .writeOrModifyOrDeleteServiceList("serviceCreateInput", createInput, pathComputationRequestOutput, 3);
71 assertEquals(LogMessages.SERVICE_NOT_FOUND, result);
75 void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
76 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
77 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
78 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
79 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
80 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
81 .setConfigurationResponseCommon(configurationResponseCommon).build();
82 String result = serviceDataStoreOperations
83 .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 2);
88 void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
89 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
90 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
91 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
92 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
93 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
94 .setConfigurationResponseCommon(configurationResponseCommon).build();
95 this.serviceDataStoreOperations.createService(createInput);
96 String result = serviceDataStoreOperations
97 .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 0);
102 void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
103 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
104 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
105 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
106 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
107 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
108 .setConfigurationResponseCommon(configurationResponseCommon).build();
109 this.serviceDataStoreOperations.createService(createInput);
110 String result = serviceDataStoreOperations
111 .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 1);
116 void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
117 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
118 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
119 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
120 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
121 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
122 .setConfigurationResponseCommon(configurationResponseCommon).build();
123 this.serviceDataStoreOperations.createService(createInput);
124 String result = serviceDataStoreOperations
125 .writeOrModifyOrDeleteServiceList("service 1",createInput, pathComputationRequestOutput, 2);
130 void getServiceFromEmptyDataStoreShouldBeEmpty() {
131 Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
132 assertFalse(optService.isPresent());
136 void createServiceShouldBeSuccessForValidInput() {
137 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
138 OperationResult result = this.serviceDataStoreOperations.createService(createInput);
139 assertTrue(result.isSuccess());
143 void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
144 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
145 this.serviceDataStoreOperations.createService(createInput);
147 Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
148 assertTrue(optService.isPresent());
149 assertEquals(createInput.getServiceName(), optService.get().getServiceName());
153 void deleteServiceShouldBeSuccessfulForDeletingService() {
154 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
155 this.serviceDataStoreOperations.createService(createInput);
156 OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
157 assertTrue(result.isSuccess());
161 void deleteServiceShouldBeSuccessEvenIfServiceDoNotExists() {
162 OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
163 assertTrue(result.isSuccess());
167 void modifyServiceIsSuccessfulForPresentService() {
168 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
169 this.serviceDataStoreOperations.createService(createInput);
170 OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(),
171 State.InService, AdminStates.InService);
172 assertTrue(result.isSuccess());
176 void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
177 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
178 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
179 assertFalse(optService.isPresent());
183 void createTempServiceShouldBeSuccessForValidInput() {
184 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
185 OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
186 assertTrue(result.isSuccess());
190 void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
191 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
192 this.serviceDataStoreOperations.createTempService(createInput);
194 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
195 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
196 assertTrue(optService.isPresent());
197 assertEquals(createInput.getCommonId(), optService.get().getCommonId());
201 void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
202 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
203 this.serviceDataStoreOperations.createTempService(createInput);
204 OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
205 assertTrue(result.isSuccess());
209 void modifyTempServiceIsSuccessfulForPresentTempService() {
210 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
211 this.serviceDataStoreOperations.createTempService(createInput);
212 OperationResult result = this.serviceDataStoreOperations.modifyTempService(
213 createInput.getCommonId(), State.InService, AdminStates.InService);
214 assertTrue(result.isSuccess());
218 void createServicePathShouldBeSuccessfulForValidInput() {
219 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
220 this.serviceDataStoreOperations.createService(createInput);
221 ServiceInput serviceInput = new ServiceInput(createInput);
222 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
223 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
224 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
225 ResponseParameters responseParameters = new ResponseParametersBuilder()
226 .setPathDescription(new PathDescriptionBuilder()
227 .setAToZDirection(new AToZDirectionBuilder()
228 .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
229 .setZToADirection(new ZToADirectionBuilder()
230 .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
232 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
233 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
235 OperationResult result = this.serviceDataStoreOperations
236 .createServicePath(serviceInput, pathComputationRequestOutput);
237 assertTrue(result.isSuccess());
241 void createServicePathShouldFailForInvalidInput() {
242 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
243 this.serviceDataStoreOperations.createService(createInput);
244 ServiceInput serviceInput = new ServiceInput(createInput);
245 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
246 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
247 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
248 ResponseParameters responseParameters = new ResponseParametersBuilder().build();
249 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
250 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
252 OperationResult result = this.serviceDataStoreOperations
253 .createServicePath(serviceInput, pathComputationRequestOutput);
254 assertFalse(result.isSuccess());
258 void deleteServicePathShouldBeSuccessForDeletingServicePath() {
259 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
260 this.serviceDataStoreOperations.createService(createInput);
261 ServiceInput serviceInput = new ServiceInput(createInput);
262 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
263 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
264 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
265 ResponseParameters responseParameters = new ResponseParametersBuilder()
266 .setPathDescription(new PathDescriptionBuilder()
267 .setAToZDirection(new AToZDirectionBuilder()
268 .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
269 .setZToADirection(new ZToADirectionBuilder()
270 .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
272 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
273 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
275 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
277 OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
278 assertTrue(result.isSuccess());