Upgrade to Service Path 1.7
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / service / ServiceDataStoreOperationsImplTest.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.servicehandler.service;
9
10 import java.util.Optional;
11
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.rev200128.PathComputationRequestOutput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
35
36 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
37 @SuppressWarnings("deprecation")
38 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
39
40     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
41
42     @Before
43     public void init() {
44         DataBroker dataBroker = this.getNewDataBroker();
45         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
46     }
47
48     @Test
49     public void modifyIfServiceNotPresent() {
50         OperationResult result =
51                 this.serviceDataStoreOperations.modifyService("service 1", State.InService, AdminStates.InService);
52         Assert.assertFalse(result.isSuccess());
53         Assert.assertEquals("Service service 1 is not present!", result.getResultMessage());
54     }
55
56     @Test
57     public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
58
59         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
60         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
61                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
62                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
63         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
64                 .setConfigurationResponseCommon(configurationResponseCommon).build();
65         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
66             createInput, pathComputationRequestOutput, 3);
67
68         Assert.assertEquals("Service is not present ! ", result);
69     }
70
71     @Test
72     public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
73
74         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
75         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
76                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
77                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
78         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
79                 .setConfigurationResponseCommon(configurationResponseCommon).build();
80         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
81             createInput, pathComputationRequestOutput, 2);
82
83         Assert.assertNull(result);
84     }
85
86     @Test
87     public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
88         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
89         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
90                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
91                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
92         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
93                 .setConfigurationResponseCommon(configurationResponseCommon).build();
94         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
95         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
96             createInput, pathComputationRequestOutput, 0);
97         Assert.assertNull(result);
98     }
99
100     @Test
101     public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
102         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
103         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
104                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
105                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
106         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
107                 .setConfigurationResponseCommon(configurationResponseCommon).build();
108         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
109         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
110             createInput, pathComputationRequestOutput, 1);
111         Assert.assertNull(result);
112     }
113
114     @Test
115     public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
116         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
117         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
118                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
119                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
120         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
121                 .setConfigurationResponseCommon(configurationResponseCommon).build();
122         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
123         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
124             createInput, pathComputationRequestOutput, 2);
125         Assert.assertNull(result);
126
127     }
128
129     @Test
130     public void getServiceFromEmptyDataStoreShouldBeEmpty() {
131         Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
132         Assert.assertFalse(optService.isPresent());
133     }
134
135     @Test
136     public void createServiceShouldBeSuccessForValidInput() {
137         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
138         OperationResult result = this.serviceDataStoreOperations.createService(createInput);
139         Assert.assertTrue(result.isSuccess());
140     }
141
142     @Test
143     public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
144         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
145         this.serviceDataStoreOperations.createService(createInput);
146
147         Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
148         Assert.assertTrue(optService.isPresent());
149         Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName());
150     }
151
152     @Test
153     public void deleteServiceShouldBeSuccessfulForDeletingService() {
154         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
155         this.serviceDataStoreOperations.createService(createInput);
156         OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
157         Assert.assertTrue(result.isSuccess());
158     }
159
160 //    @Test
161 //    public void deleteServiceShouldBeFailedIfServiceDoNotExists() {
162 //        OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
163 //        Assert.assertFalse(result.isSuccess());
164 //    }
165
166     @Test
167     public 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         Assert.assertTrue(result.isSuccess());
173     }
174
175     @Test
176     public void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
177         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
178                 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
179         Assert.assertFalse(optService.isPresent());
180     }
181
182     @Test
183     public void createTempServiceShouldBeSuccessForValidInput() {
184         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
185         OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
186         Assert.assertTrue(result.isSuccess());
187     }
188
189     @Test
190     public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
191         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
192         this.serviceDataStoreOperations.createTempService(createInput);
193
194         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
195                 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
196         Assert.assertTrue(optService.isPresent());
197         Assert.assertEquals(createInput.getCommonId(), optService.get().getCommonId());
198     }
199
200     @Test
201     public void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
202         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
203         this.serviceDataStoreOperations.createTempService(createInput);
204         OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
205         Assert.assertTrue(result.isSuccess());
206     }
207
208     @Test
209     public void modifyTempServiceIsSuccessfulForPresentTempService() {
210         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
211         this.serviceDataStoreOperations.createTempService(createInput);
212         OperationResult result = this.serviceDataStoreOperations.modifyTempService(createInput.getCommonId(),
213             State.InService, AdminStates.InService);
214         Assert.assertTrue(result.isSuccess());
215     }
216
217     @Test
218     public 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().setAToZWavelengthNumber(1L).setRate(1L).build())
228                 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
229             .build();
230         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
231             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
232             .build();
233         OperationResult result =
234             this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
235         Assert.assertTrue(result.isSuccess());
236     }
237
238     @Test
239     public void createServicePathShouldFailForInvalidInput() {
240         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
241         this.serviceDataStoreOperations.createService(createInput);
242         ServiceInput serviceInput = new ServiceInput(createInput);
243         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
244             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
245             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
246         ResponseParameters responseParameters = new ResponseParametersBuilder().build();
247         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
248             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
249             .build();
250         OperationResult result =
251             this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
252         Assert.assertFalse(result.isSuccess());
253     }
254
255     @Test
256     public void deleteServicePathShouldBeSuccessForDeletingServicePath() {
257         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
258         this.serviceDataStoreOperations.createService(createInput);
259         ServiceInput serviceInput = new ServiceInput(createInput);
260         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
261             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
262             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
263         ResponseParameters responseParameters = new ResponseParametersBuilder()
264             .setPathDescription(new PathDescriptionBuilder()
265                 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
266                 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
267             .build();
268         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
269             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
270             .build();
271         this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
272
273         OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
274         Assert.assertTrue(result.isSuccess());
275     }
276 }