fix some deprecated warnings
[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.controller.md.sal.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;
34
35 //writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
36 @SuppressWarnings("deprecation")
37 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
38
39     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
40
41     @Before
42     public void init() {
43         DataBroker dataBroker = this.getNewDataBroker();
44         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
45     }
46
47     @Test
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());
53     }
54
55     @Test
56     public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
57
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);
66
67         Assert.assertEquals("Service is not present ! ", result);
68     }
69
70     @Test
71     public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
72
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);
81
82         Assert.assertNull(result);
83     }
84
85     @Test
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);
97     }
98
99     @Test
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);
111     }
112
113     @Test
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);
125
126     }
127
128     @Test
129     public void getServiceFromEmptyDataStoreShouldBeEmpty() {
130         Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
131         Assert.assertFalse(optService.isPresent());
132     }
133
134     @Test
135     public void createServiceShouldBeSuccessForValidInput() {
136         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
137         OperationResult result = this.serviceDataStoreOperations.createService(createInput);
138         Assert.assertTrue(result.isSuccess());
139     }
140
141     @Test
142     public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
143         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
144         this.serviceDataStoreOperations.createService(createInput);
145
146         Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
147         Assert.assertTrue(optService.isPresent());
148         Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName());
149     }
150
151     @Test
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());
157     }
158
159 //    @Test
160 //    public void deleteServiceShouldBeFailedIfServiceDoNotExists() {
161 //        OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
162 //        Assert.assertFalse(result.isSuccess());
163 //    }
164
165     @Test
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());
172     }
173
174     @Test
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());
179     }
180
181     @Test
182     public void createTempServiceShouldBeSuccessForValidInput() {
183         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
184         OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
185         Assert.assertTrue(result.isSuccess());
186     }
187
188     @Test
189     public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
190         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
191         this.serviceDataStoreOperations.createTempService(createInput);
192
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());
197     }
198
199     @Test
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());
205     }
206
207     @Test
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());
214     }
215
216     @Test
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())
228             .build();
229         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
230             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
231             .build();
232         OperationResult result =
233             this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
234         Assert.assertTrue(result.isSuccess());
235     }
236
237     @Test
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)
248             .build();
249         OperationResult result =
250             this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
251         Assert.assertFalse(result.isSuccess());
252     }
253
254     @Test
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())
266             .build();
267         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
268             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
269             .build();
270         this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
271
272         OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
273         Assert.assertTrue(result.isSuccess());
274     }
275 }