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