Update release in docs/conf.yaml
[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 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;
15
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.rev240205.PathComputationRequestOutput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PathComputationRequestOutputBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.service.path.rpc.result.PathDescription;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParameters;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
40 import org.opendaylight.yangtools.yang.common.Uint32;
41
42 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
43 @SuppressWarnings("deprecation")
44 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
45
46     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
47
48     @BeforeEach
49     void init() {
50         DataBroker dataBroker = this.getNewDataBroker();
51         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
52     }
53
54     @Test
55     void modifyIfServiceNotPresent() {
56         OperationResult result = this.serviceDataStoreOperations
57             .modifyService("service 1", State.InService, AdminStates.InService);
58         assertFalse(result.isSuccess());
59         assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage());
60     }
61
62     @Test
63     void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
64         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
65         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
66                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
67                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
68         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
69                 .setConfigurationResponseCommon(configurationResponseCommon).build();
70         String result = serviceDataStoreOperations
71             .writeOrModifyOrDeleteServiceList("serviceCreateInput", createInput, pathComputationRequestOutput, 3);
72         assertEquals(LogMessages.SERVICE_NOT_FOUND, result);
73     }
74
75     @Test
76     void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
77         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
78         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
79                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
80                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
81         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
82                 .setConfigurationResponseCommon(configurationResponseCommon).build();
83         String result = serviceDataStoreOperations
84             .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 2);
85         assertNull(result);
86     }
87
88     @Test
89     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
98             .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 0);
99         assertNull(result);
100     }
101
102     @Test
103     void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
104         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
105         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
106                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
107                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
108         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
109                 .setConfigurationResponseCommon(configurationResponseCommon).build();
110         this.serviceDataStoreOperations.createService(createInput);
111         String result = serviceDataStoreOperations
112             .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 1);
113         assertNull(result);
114     }
115
116     @Test
117     void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
118         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
119         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
120                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
121                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
122         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
123                 .setConfigurationResponseCommon(configurationResponseCommon).build();
124         this.serviceDataStoreOperations.createService(createInput);
125         String result = serviceDataStoreOperations
126             .writeOrModifyOrDeleteServiceList("service 1",createInput, pathComputationRequestOutput, 2);
127         assertNull(result);
128     }
129
130     @Test
131     void getServiceFromEmptyDataStoreShouldBeEmpty() {
132         Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
133         assertFalse(optService.isPresent());
134     }
135
136     @Test
137     void createServiceShouldBeSuccessForValidInput() {
138         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
139         OperationResult result = this.serviceDataStoreOperations.createService(createInput);
140         assertTrue(result.isSuccess());
141     }
142
143     @Test
144     void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
145         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
146         this.serviceDataStoreOperations.createService(createInput);
147
148         Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
149         assertTrue(optService.isPresent());
150         assertEquals(createInput.getServiceName(), optService.orElseThrow().getServiceName());
151     }
152
153     @Test
154     void deleteServiceShouldBeSuccessfulForDeletingService() {
155         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
156         this.serviceDataStoreOperations.createService(createInput);
157         OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
158         assertTrue(result.isSuccess());
159     }
160
161     @Test
162     void deleteServiceShouldBeSuccessEvenIfServiceDoNotExists() {
163         OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
164         assertTrue(result.isSuccess());
165     }
166
167     @Test
168     void modifyServiceIsSuccessfulForPresentService() {
169         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
170         this.serviceDataStoreOperations.createService(createInput);
171         OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(),
172             State.InService, AdminStates.InService);
173         assertTrue(result.isSuccess());
174     }
175
176     @Test
177     void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
178         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list
179                 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
180         assertFalse(optService.isPresent());
181     }
182
183     @Test
184     void createTempServiceShouldBeSuccessForValidInput() {
185         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
186         PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
187         OperationResult result = this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
188         assertTrue(result.isSuccess());
189     }
190
191     @Test
192     void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
193         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
194         PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
195         this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
196
197         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list
198                 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
199         assertTrue(optService.isPresent());
200         assertEquals(createInput.getCommonId(), optService.orElseThrow().getCommonId());
201     }
202
203     @Test
204     void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
205         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
206         PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
207         this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
208         OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
209         assertTrue(result.isSuccess());
210     }
211
212     @Test
213     void modifyTempServiceIsSuccessfulForPresentTempService() {
214         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
215         PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
216         this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
217         OperationResult result = this.serviceDataStoreOperations.modifyTempService(
218             createInput.getCommonId(), State.InService, AdminStates.InService);
219         assertTrue(result.isSuccess());
220     }
221
222     @Test
223     void createServicePathShouldBeSuccessfulForValidInput() {
224         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
225         this.serviceDataStoreOperations.createService(createInput);
226         ServiceInput serviceInput = new ServiceInput(createInput);
227         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
228                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
229                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
230         ResponseParameters responseParameters = new ResponseParametersBuilder()
231             .setPathDescription(new PathDescriptionBuilder()
232                 .setAToZDirection(new AToZDirectionBuilder()
233                         .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
234                 .setZToADirection(new ZToADirectionBuilder()
235                         .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
236             .build();
237         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
238             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
239             .build();
240         OperationResult result = this.serviceDataStoreOperations
241             .createServicePath(serviceInput, pathComputationRequestOutput);
242         assertTrue(result.isSuccess());
243     }
244
245     @Test
246     void createServicePathShouldFailForInvalidInput() {
247         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
248         this.serviceDataStoreOperations.createService(createInput);
249         ServiceInput serviceInput = new ServiceInput(createInput);
250         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
251             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
252             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
253         ResponseParameters responseParameters = new ResponseParametersBuilder().build();
254         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
255             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
256             .build();
257         OperationResult result = this.serviceDataStoreOperations
258             .createServicePath(serviceInput, pathComputationRequestOutput);
259         assertFalse(result.isSuccess());
260     }
261
262     @Test
263     void deleteServicePathShouldBeSuccessForDeletingServicePath() {
264         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
265         this.serviceDataStoreOperations.createService(createInput);
266         ServiceInput serviceInput = new ServiceInput(createInput);
267         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
268             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
269             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
270         ResponseParameters responseParameters = new ResponseParametersBuilder()
271             .setPathDescription(new PathDescriptionBuilder()
272                 .setAToZDirection(new AToZDirectionBuilder()
273                         .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
274                 .setZToADirection(new ZToADirectionBuilder()
275                         .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
276             .build();
277         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
278             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
279             .build();
280         this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
281
282         OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
283         assertTrue(result.isSuccess());
284     }
285 }