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.provisiondevice.RendererServiceOperations;
20 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
21 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
22 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
23 import org.opendaylight.transportpce.test.AbstractTest;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
29 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
31 private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
32 private PCEServiceWrapper pceServiceWrapper;
33 private ServicehandlerImpl serviceHandler;
34 private RendererServiceOperations rendererServiceOperations;
36 public ServiceDataStoreOperationsImplTest() {
37 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
38 PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(),
39 notificationPublishService);
40 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService);
41 this.rendererServiceOperations = new StubRendererServiceOperations();
42 this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService,
43 this.rendererServiceOperations);
49 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.getDataBroker());
50 MockitoAnnotations.initMocks(this);
54 public void modifyIfServiceNotPresent() {
55 OperationResult result = this.serviceDataStoreOperations.modifyService("service 1",
56 State.InService, State.InService);
57 Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage());
61 public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
63 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
64 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
66 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
67 createInput, pathComputationRequestOutput, 3);
69 Assert.assertEquals("Service is not present ! ", result);
74 public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
76 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
77 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
79 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
80 createInput, pathComputationRequestOutput, 2);
82 Assert.assertEquals(null, result);
87 public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
88 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
89 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
91 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
92 pathComputationRequestOutput);
93 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
94 createInput, pathComputationRequestOutput, 0);
95 Assert.assertEquals(null, result);
100 public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
101 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
102 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
104 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
105 pathComputationRequestOutput);
106 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
107 createInput, pathComputationRequestOutput, 1);
108 Assert.assertEquals(null, result);
113 public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
114 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
115 PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput,
117 OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput,
118 pathComputationRequestOutput);
119 String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
120 createInput, pathComputationRequestOutput, 2);
121 Assert.assertEquals(null, result);