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