Reintroduce SP 1.6 models in TPCE
[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 org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.MockitoAnnotations;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
15 import org.opendaylight.transportpce.common.OperationResult;
16 import org.opendaylight.transportpce.pce.service.PathComputationService;
17 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
18 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
19 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
20 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
21 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
22 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
23 import org.opendaylight.transportpce.test.AbstractTest;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
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
28
29 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
30
31     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
32     private PCEServiceWrapper pceServiceWrapper;
33     private ServicehandlerImpl serviceHandler;
34     private RendererServiceOperations rendererServiceOperations;
35
36     public ServiceDataStoreOperationsImplTest() {
37         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
38         PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(),
39             notificationPublishService);
40         this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService);
41         this.rendererServiceOperations = new StubRendererServiceOperations();
42         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService,
43             this.rendererServiceOperations);
44     }
45
46
47     @Before
48     public void init() {
49         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
50         MockitoAnnotations.initMocks(this);
51     }
52
53     @Test
54     public void modifyIfServiceNotPresent() {
55         OperationResult result = this.serviceDataStoreOperations.modifyService("service 1",
56             State.InService, State.InService);
57         Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage());
58     }
59
60     @Test
61     public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
62
63         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
64         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
65             true);
66         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
67             createInput, pathComputationRequestOutput, 3);
68
69         Assert.assertEquals("Service is not present ! ", result);
70
71     }
72
73     @Test
74     public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
75
76         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
77         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
78             true);
79         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
80             createInput, pathComputationRequestOutput, 2);
81
82         Assert.assertEquals(null, result);
83
84     }
85
86     @Test
87     public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
88         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
89         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
90             true);
91         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
92             pathComputationRequestOutput);
93         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
94             createInput, pathComputationRequestOutput, 0);
95         Assert.assertEquals(null, result);
96
97     }
98
99     @Test
100     public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
101         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
102         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
103             true);
104         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
105             pathComputationRequestOutput);
106         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
107             createInput, pathComputationRequestOutput, 1);
108         Assert.assertEquals(null, result);
109
110     }
111
112     @Test
113     public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
114         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
115         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
116             true);
117         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
118             pathComputationRequestOutput);
119         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
120             createInput, pathComputationRequestOutput, 2);
121         Assert.assertEquals(null, result);
122
123     }
124 }