2 * Copyright © 2018 Orange Systems, 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
9 package org.opendaylight.transportpce.renderer.provisiondevice;
11 import java.util.ArrayList;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
17 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
19 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl22;
22 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
24 import org.opendaylight.transportpce.common.mapping.MappingUtils;
25 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
26 import org.opendaylight.transportpce.common.mapping.PortMapping;
27 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
28 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
29 import org.opendaylight.transportpce.common.mapping.PortMappingVersion22;
30 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
31 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl22;
35 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
36 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
37 import org.opendaylight.transportpce.renderer.utils.CreateOtsOmsDataUtils;
38 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
39 import org.opendaylight.transportpce.test.AbstractTest;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsInput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsOutput;
43 public class DeviceRendererServiceImplCreateOtsOmsTest extends AbstractTest {
45 private DeviceRendererService deviceRendererService;
46 private CrossConnect crossConnect;
47 private OpenRoadmInterfaces openRoadmInterfaces;
48 private OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
49 private DeviceTransactionManager deviceTransactionManager;
50 private MappingUtils mappingUtils;
51 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
52 private OpenRoadmInterfacesImpl22 openRoadmInterfacesImpl22;
53 private PortMappingVersion22 portMappingVersion22;
54 private PortMappingVersion121 portMappingVersion121;
55 private CrossConnectImpl121 crossConnectImpl121;
56 private CrossConnectImpl22 crossConnectImpl22;
58 private void setMountPoint(MountPoint mountPoint) {
59 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
60 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
61 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(this.deviceTransactionManager);
62 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl22(this.deviceTransactionManager);
63 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
64 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
65 openRoadmInterfacesImpl121, openRoadmInterfacesImpl22);
66 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
67 this.portMappingVersion22 = new PortMappingVersion22(getDataBroker(), this.deviceTransactionManager,
68 this.openRoadmInterfaces);
69 this.portMappingVersion121 = new PortMappingVersion121(getDataBroker(), this.deviceTransactionManager,
70 this.openRoadmInterfaces);
71 PortMapping portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
72 this.portMappingVersion121);
73 this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping, this.openRoadmInterfaces);
74 this.crossConnectImpl121 = new CrossConnectImpl121(this.deviceTransactionManager);
75 this.crossConnectImpl22 = new CrossConnectImpl22(this.deviceTransactionManager);
76 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager, this.mappingUtils,
77 this.crossConnectImpl121, this.crossConnectImpl22);
78 this.crossConnect = Mockito.spy(this.crossConnect);
79 this.deviceRendererService = new DeviceRendererServiceImpl(this.getDataBroker(),
80 this.deviceTransactionManager, this.openRoadmInterfaceFactory, this.openRoadmInterfaces,
81 this.crossConnect, portMapping);
85 public void testCreateOtsOmsWhenDeviceIsNotMounted() throws OpenRoadmInterfaceException {
87 CreateOtsOmsInput input = CreateOtsOmsDataUtils.buildCreateOtsOms();
88 CreateOtsOmsOutput result = this.deviceRendererService.createOtsOms(input);
89 Assert.assertFalse(result.isSuccess());
90 Assert.assertEquals("node 1 is not mounted on the controller",
95 public void testCreateOtsOmsWhenDeviceIsMountedWithNoMapping() throws OpenRoadmInterfaceException {
96 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
97 CreateOtsOmsInput input = CreateOtsOmsDataUtils.buildCreateOtsOms();
98 CreateOtsOmsOutput result = this.deviceRendererService.createOtsOms(input);
99 Assert.assertFalse(result.isSuccess());
103 public void testCreateOtsOmsWhenDeviceIsMountedWithMapping() throws OpenRoadmInterfaceException {
104 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
105 CreateOtsOmsInput input = CreateOtsOmsDataUtils.buildCreateOtsOms();
106 writePortMapping(input);
107 CreateOtsOmsOutput result = this.deviceRendererService.createOtsOms(input);
108 Assert.assertTrue(result.isSuccess());
111 private void writePortMapping(CreateOtsOmsInput input) {
112 MountPointUtils.writeMapping(
114 input.getLogicalConnectionPoint(),
115 this.deviceTransactionManager