Update stubRenderer
[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         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService,
46                 this.rendererServiceOperations, this.networkModelWavelengthService);
47     }
48
49
50     @Before
51     public void init() {
52         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
53         MockitoAnnotations.initMocks(this);
54     }
55
56     @Test
57     public void modifyIfServiceNotPresent() {
58         OperationResult result = this.serviceDataStoreOperations.modifyService("service 1",
59             State.InService, State.InService);
60         Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage());
61     }
62
63     @Test
64     public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
65
66         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
67         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
68             true);
69         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
70             createInput, pathComputationRequestOutput, 3);
71
72         Assert.assertEquals("Service is not present ! ", result);
73
74     }
75
76     @Test
77     public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
78
79         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
80         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
81             true);
82         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
83             createInput, pathComputationRequestOutput, 2);
84
85         Assert.assertEquals(null, result);
86
87     }
88
89     @Test
90     public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
91         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
92         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
93             true);
94         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
95             pathComputationRequestOutput);
96         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
97             createInput, pathComputationRequestOutput, 0);
98         Assert.assertEquals(null, result);
99
100     }
101
102     @Test
103     public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
104         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
105         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
106             true);
107         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
108             pathComputationRequestOutput);
109         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
110             createInput, pathComputationRequestOutput, 1);
111         Assert.assertEquals(null, result);
112
113     }
114
115     @Test
116     public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
117         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
118         PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
119             true);
120         OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
121             pathComputationRequestOutput);
122         String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
123             createInput, pathComputationRequestOutput, 2);
124         Assert.assertEquals(null, result);
125
126     }
127 }