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.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl.LogMessages;
12 import java.util.Optional;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.transportpce.common.OperationResult;
18 import org.opendaylight.transportpce.common.ResponseCodes;
19 import org.opendaylight.transportpce.servicehandler.ServiceInput;
20 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
21 import org.opendaylight.transportpce.test.AbstractTest;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.AToZDirectionBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ZToADirectionBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
36 import org.opendaylight.yangtools.yang.common.Uint32;
38 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
39 @SuppressWarnings("deprecation")
40 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
42 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
46 DataBroker dataBroker = this.getNewDataBroker();
47 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
51 public void modifyIfServiceNotPresent() {
52 OperationResult result =
53 this.serviceDataStoreOperations.modifyService("service 1", State.InService, AdminStates.InService);
54 Assert.assertFalse(result.isSuccess());
55 Assert.assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage());
59 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
61 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
62 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
63 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
64 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
65 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
66 .setConfigurationResponseCommon(configurationResponseCommon).build();
67 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
68 createInput, pathComputationRequestOutput, 3);
70 Assert.assertEquals(LogMessages.SERVICE_NOT_FOUND, result);
74 public 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.writeOrModifyOrDeleteServiceList("service 1",
83 createInput, pathComputationRequestOutput, 2);
85 Assert.assertNull(result);
89 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
90 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
91 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
92 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
93 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
94 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
95 .setConfigurationResponseCommon(configurationResponseCommon).build();
96 this.serviceDataStoreOperations.createService(createInput);
97 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
98 createInput, pathComputationRequestOutput, 0);
99 Assert.assertNull(result);
103 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
104 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
106 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
107 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
108 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
109 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
110 .setConfigurationResponseCommon(configurationResponseCommon).build();
111 this.serviceDataStoreOperations.createService(createInput);
112 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
113 createInput, pathComputationRequestOutput, 1);
114 Assert.assertNull(result);
118 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
119 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
120 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
121 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
122 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
123 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
124 .setConfigurationResponseCommon(configurationResponseCommon).build();
125 this.serviceDataStoreOperations.createService(createInput);
126 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
127 createInput, pathComputationRequestOutput, 2);
128 Assert.assertNull(result);
133 public void getServiceFromEmptyDataStoreShouldBeEmpty() {
134 Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
135 Assert.assertFalse(optService.isPresent());
139 public void createServiceShouldBeSuccessForValidInput() {
140 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
141 OperationResult result = this.serviceDataStoreOperations.createService(createInput);
142 Assert.assertTrue(result.isSuccess());
146 public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
147 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
148 this.serviceDataStoreOperations.createService(createInput);
150 Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
151 Assert.assertTrue(optService.isPresent());
152 Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName());
156 public void deleteServiceShouldBeSuccessfulForDeletingService() {
157 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
158 this.serviceDataStoreOperations.createService(createInput);
159 OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
160 Assert.assertTrue(result.isSuccess());
164 // public void deleteServiceShouldBeFailedIfServiceDoNotExists() {
165 // OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
166 // Assert.assertFalse(result.isSuccess());
170 public void modifyServiceIsSuccessfulForPresentService() {
171 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
172 this.serviceDataStoreOperations.createService(createInput);
173 OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(),
174 State.InService, AdminStates.InService);
175 Assert.assertTrue(result.isSuccess());
179 public void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
180 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
181 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
182 Assert.assertFalse(optService.isPresent());
186 public void createTempServiceShouldBeSuccessForValidInput() {
187 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
188 OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
189 Assert.assertTrue(result.isSuccess());
193 public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
194 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
195 this.serviceDataStoreOperations.createTempService(createInput);
197 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
198 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
199 Assert.assertTrue(optService.isPresent());
200 Assert.assertEquals(createInput.getCommonId(), optService.get().getCommonId());
204 public void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
205 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
206 this.serviceDataStoreOperations.createTempService(createInput);
207 OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
208 Assert.assertTrue(result.isSuccess());
212 public void modifyTempServiceIsSuccessfulForPresentTempService() {
213 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
214 this.serviceDataStoreOperations.createTempService(createInput);
215 OperationResult result = this.serviceDataStoreOperations.modifyTempService(
216 createInput.getCommonId(), State.InService, AdminStates.InService);
217 Assert.assertTrue(result.isSuccess());
221 public void createServicePathShouldBeSuccessfulForValidInput() {
222 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
223 this.serviceDataStoreOperations.createService(createInput);
224 ServiceInput serviceInput = new ServiceInput(createInput);
225 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
226 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
227 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
228 ResponseParameters responseParameters = new ResponseParametersBuilder()
229 .setPathDescription(new PathDescriptionBuilder()
230 .setAToZDirection(new AToZDirectionBuilder()
231 .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
232 .setZToADirection(new ZToADirectionBuilder()
233 .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
235 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
236 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
238 OperationResult result =
239 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
240 Assert.assertTrue(result.isSuccess());
244 public void createServicePathShouldFailForInvalidInput() {
245 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
246 this.serviceDataStoreOperations.createService(createInput);
247 ServiceInput serviceInput = new ServiceInput(createInput);
248 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
249 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
250 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
251 ResponseParameters responseParameters = new ResponseParametersBuilder().build();
252 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
253 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
255 OperationResult result =
256 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
257 Assert.assertFalse(result.isSuccess());
261 public void deleteServicePathShouldBeSuccessForDeletingServicePath() {
262 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
263 this.serviceDataStoreOperations.createService(createInput);
264 ServiceInput serviceInput = new ServiceInput(createInput);
265 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
266 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
267 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
268 ResponseParameters responseParameters = new ResponseParametersBuilder()
269 .setPathDescription(new PathDescriptionBuilder()
270 .setAToZDirection(new AToZDirectionBuilder()
271 .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
272 .setZToADirection(new ZToADirectionBuilder()
273 .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
275 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
276 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
278 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
280 OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
281 Assert.assertTrue(result.isSuccess());