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