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 org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.transportpce.common.OperationResult;
15 import org.opendaylight.transportpce.common.ResponseCodes;
16 import org.opendaylight.transportpce.servicehandler.ServiceInput;
17 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
18 import org.opendaylight.transportpce.test.AbstractTest;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.response.parameters.PathDescriptionBuilder;
33 import java.util.Optional;
36 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
38 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> oService = this.serviceDataStoreOperations.getService("service 1");
131 Assert.assertFalse(oService.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> oService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
147 Assert.assertTrue(oService.isPresent());
148 Assert.assertEquals(createInput.getServiceName(), oService.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 =
170 this.serviceDataStoreOperations.modifyService(createInput.getServiceName(), 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> oService = this.serviceDataStoreOperations.getTempService("service 1");
178 Assert.assertFalse(oService.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> oService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
195 Assert.assertTrue(oService.isPresent());
196 Assert.assertEquals(createInput.getCommonId(), oService.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 =
212 this.serviceDataStoreOperations.modifyTempService(createInput.getCommonId(), 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()).build();
228 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
229 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters).build();
230 OperationResult result =
231 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
232 Assert.assertTrue(result.isSuccess());
236 public void createServicePathShouldFailForInvalidInput() {
237 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
238 this.serviceDataStoreOperations.createService(createInput);
239 ServiceInput serviceInput = new ServiceInput(createInput);
240 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
241 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
242 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
243 ResponseParameters responseParameters = new ResponseParametersBuilder().build();
244 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
245 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters).build();
246 OperationResult result =
247 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
248 Assert.assertFalse(result.isSuccess());
252 public void deleteServicePathShouldBeSuccessForDeletingServicePath() {
253 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
254 this.serviceDataStoreOperations.createService(createInput);
255 ServiceInput serviceInput = new ServiceInput(createInput);
256 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
257 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
258 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
259 ResponseParameters responseParameters = new ResponseParametersBuilder()
260 .setPathDescription(new PathDescriptionBuilder()
261 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
262 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build()).build();
263 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
264 .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters).build();
265 this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
267 OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
268 Assert.assertTrue(result.isSuccess());