2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.servicehandler.service;
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;
30 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
32 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
33 private PCEServiceWrapper pceServiceWrapper;
34 private ServicehandlerImpl serviceHandler;
35 private RendererServiceOperations rendererServiceOperations;
36 private NetworkModelWavelengthService networkModelWavelengthService;
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);
53 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
54 MockitoAnnotations.initMocks(this);
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());
65 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
67 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
68 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
70 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
71 createInput, pathComputationRequestOutput, 3);
73 Assert.assertEquals("Service is not present ! ", result);
78 public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
80 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
81 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
83 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
84 createInput, pathComputationRequestOutput, 2);
86 Assert.assertEquals(null, result);
91 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
92 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
93 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);
104 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
105 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
106 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);
117 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
118 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
119 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);