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 this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService,
46 this.rendererServiceOperations, this.networkModelWavelengthService);
52 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
53 MockitoAnnotations.initMocks(this);
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());
64 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
66 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
67 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
69 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
70 createInput, pathComputationRequestOutput, 3);
72 Assert.assertEquals("Service is not present ! ", result);
77 public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
79 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
80 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
82 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
83 createInput, pathComputationRequestOutput, 2);
85 Assert.assertEquals(null, result);
90 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
91 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
92 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);
103 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
104 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
105 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);
116 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
117 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
118 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
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);