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.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;
32 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
34 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
35 private PCEServiceWrapper pceServiceWrapper;
36 private ServicehandlerImpl serviceHandler;
37 private RendererServiceOperations rendererServiceOperations;
38 private NetworkModelWavelengthService networkModelWavelengthService;
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);
59 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
60 MockitoAnnotations.initMocks(this);
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());
71 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
73 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
74 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
76 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
77 createInput, pathComputationRequestOutput, 3);
79 Assert.assertEquals("Service is not present ! ", result);
84 public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
86 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
87 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
89 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
90 createInput, pathComputationRequestOutput, 2);
92 Assert.assertEquals(null, result);
97 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
98 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
99 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
101 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
102 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
103 createInput, pathComputationRequestOutput, 0);
104 Assert.assertEquals(null, result);
109 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
110 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
111 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
113 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
114 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
115 createInput, pathComputationRequestOutput, 1);
116 Assert.assertEquals(null, result);
121 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
122 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
123 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
125 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
126 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
127 createInput, pathComputationRequestOutput, 2);
128 Assert.assertEquals(null, result);