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 java.util.Optional;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.transportpce.common.OperationResult;
17 import org.opendaylight.transportpce.common.ResponseCodes;
18 import org.opendaylight.transportpce.servicehandler.ServiceInput;
19 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
20 import org.opendaylight.transportpce.test.AbstractTest;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutputBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.response.parameters.PathDescriptionBuilder;
35 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
36 @SuppressWarnings("deprecation")
37 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
39 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
43 DataBroker dataBroker = this.getNewDataBroker();
44 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
48 public void modifyIfServiceNotPresent() {
49 OperationResult result =
50 this.serviceDataStoreOperations.modifyService("service 1", State.InService, State.InService);
51 Assert.assertFalse(result.isSuccess());
52 Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage());
56 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
58 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
59 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
60 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
61 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
62 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
63 .setConfigurationResponseCommon(configurationResponseCommon).build();
64 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
65 createInput, pathComputationRequestOutput, 3);
67 Assert.assertEquals("Service is not present ! ", result);
71 public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
73 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
74 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
75 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
76 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
77 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
78 .setConfigurationResponseCommon(configurationResponseCommon).build();
79 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
80 createInput, pathComputationRequestOutput, 2);
82 Assert.assertNull(result);
86 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
87 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
88 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
89 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
90 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
91 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
92 .setConfigurationResponseCommon(configurationResponseCommon).build();
93 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
94 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
95 createInput, pathComputationRequestOutput, 0);
96 Assert.assertNull(result);
100 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
101 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
102 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
103 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
104 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
105 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
106 .setConfigurationResponseCommon(configurationResponseCommon).build();
107 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
108 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
109 createInput, pathComputationRequestOutput, 1);
110 Assert.assertNull(result);
114 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
115 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
116 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
117 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
118 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
119 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
120 .setConfigurationResponseCommon(configurationResponseCommon).build();
121 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
122 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
123 createInput, pathComputationRequestOutput, 2);
124 Assert.assertNull(result);
129 public void getServiceFromEmptyDataStoreShouldBeEmpty() {
130 Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
131 Assert.assertFalse(optService.isPresent());
135 public void createServiceShouldBeSuccessForValidInput() {
136 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
137 OperationResult result = this.serviceDataStoreOperations.createService(createInput);
138 Assert.assertTrue(result.isSuccess());
142 public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
143 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
144 this.serviceDataStoreOperations.createService(createInput);
146 Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
147 Assert.assertTrue(optService.isPresent());
148 Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName());
152 public void deleteServiceShouldBeSuccessfulForDeletingService() {
153 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
154 this.serviceDataStoreOperations.createService(createInput);
155 OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
156 Assert.assertTrue(result.isSuccess());
160 // public void deleteServiceShouldBeFailedIfServiceDoNotExists() {
161 // OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
162 // Assert.assertFalse(result.isSuccess());
166 public void modifyServiceIsSuccessfulForPresentService() {
167 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
168 this.serviceDataStoreOperations.createService(createInput);
169 OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(),
170 State.InService, State.InService);
171 Assert.assertTrue(result.isSuccess());
175 public void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
176 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
177 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
178 Assert.assertFalse(optService.isPresent());
182 public void createTempServiceShouldBeSuccessForValidInput() {
183 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
184 OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
185 Assert.assertTrue(result.isSuccess());
189 public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
190 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
191 this.serviceDataStoreOperations.createTempService(createInput);
193 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
194 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
195 Assert.assertTrue(optService.isPresent());
196 Assert.assertEquals(createInput.getCommonId(), optService.get().getCommonId());
200 public void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
201 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
202 this.serviceDataStoreOperations.createTempService(createInput);
203 OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
204 Assert.assertTrue(result.isSuccess());
208 public void modifyTempServiceIsSuccessfulForPresentTempService() {
209 TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
210 this.serviceDataStoreOperations.createTempService(createInput);
211 OperationResult result = this.serviceDataStoreOperations.modifyTempService(createInput.getCommonId(),
212 State.InService, State.InService);
213 Assert.assertTrue(result.isSuccess());
217 public void createServicePathShouldBeSuccessfulForValidInput() {
218 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
219 this.serviceDataStoreOperations.createService(createInput);
220 ServiceInput serviceInput = new ServiceInput(createInput);
221 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
222 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
223 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
224 ResponseParameters responseParameters = new ResponseParametersBuilder()
225 .setPathDescription(new PathDescriptionBuilder()
226 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
227 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
229 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
230 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
232 OperationResult result =
233 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
234 Assert.assertTrue(result.isSuccess());
238 public void createServicePathShouldFailForInvalidInput() {
239 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
240 this.serviceDataStoreOperations.createService(createInput);
241 ServiceInput serviceInput = new ServiceInput(createInput);
242 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
243 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
244 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
245 ResponseParameters responseParameters = new ResponseParametersBuilder().build();
246 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
247 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
249 OperationResult result =
250 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
251 Assert.assertFalse(result.isSuccess());
255 public void deleteServicePathShouldBeSuccessForDeletingServicePath() {
256 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
257 this.serviceDataStoreOperations.createService(createInput);
258 ServiceInput serviceInput = new ServiceInput(createInput);
259 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
260 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
261 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
262 ResponseParameters responseParameters = new ResponseParametersBuilder()
263 .setPathDescription(new PathDescriptionBuilder()
264 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
265 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
267 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
268 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
270 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
272 OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
273 Assert.assertTrue(result.isSuccess());