f470fa03ee6a5faa8707bb018cbbdff48f9715f2
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / utils / MountPointUtils.java
1 /*
2  * Copyright © 2018 Orange Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.renderer.utils;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
14 import org.mockito.Mockito;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.Network;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.Nodes;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.NodesKey;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.Mapping;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.MappingBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.MappingKey;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailOutput;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailOutputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceService;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.get.connection.port.trail.output.Ports;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
33
34
35 public final class MountPointUtils {
36
37     public static MountPointStub getMountPoint(List<Ports> ports, DataBroker dataBroker) {
38         RpcConsumerRegistry rpcConsumerRegistry = Mockito.spy(RpcConsumerRegistry.class);
39         OrgOpenroadmDeviceService orgOpenroadmDeviceService = Mockito.spy(OrgOpenroadmDeviceService.class);
40         GetConnectionPortTrailOutputBuilder getConnectionPortTrailOutputBldr
41                 = new GetConnectionPortTrailOutputBuilder();
42         getConnectionPortTrailOutputBldr.setPorts(ports);
43         ListenableFuture<RpcResult<GetConnectionPortTrailOutput>> rpcResultFuture =
44                 RpcResultBuilder.success(getConnectionPortTrailOutputBldr.build()).buildFuture();
45         Mockito.doReturn(rpcResultFuture).when(orgOpenroadmDeviceService).getConnectionPortTrail(Mockito.any());
46         Mockito.doReturn(orgOpenroadmDeviceService).when(rpcConsumerRegistry).getRpcService(Mockito.any());
47         MountPointStub mountPoint = new MountPointStub(dataBroker);
48         mountPoint.setRpcConsumerRegistry(rpcConsumerRegistry);
49         return mountPoint;
50     }
51
52     public static boolean writeMapping(String nodeId, String logicalConnPoint,
53                                        DeviceTransactionManager deviceTransactionManager) {
54         MappingBuilder mappingBuilder = new MappingBuilder();
55         mappingBuilder.withKey(new MappingKey(logicalConnPoint));
56         mappingBuilder.setLogicalConnectionPoint(logicalConnPoint);
57         mappingBuilder.setSupportingOts("OTS");
58         mappingBuilder.setSupportingCircuitPackName("2/0");
59         mappingBuilder.setSupportingOms("OMS");
60         mappingBuilder.setSupportingPort("8080");
61         mappingBuilder.setSupportingCircuitPackName("circuit1");
62         InstanceIdentifier<Mapping> portMappingIID =
63                 InstanceIdentifier.builder(Network.class).child(Nodes.class, new NodesKey(nodeId))
64                         .child(Mapping.class, new MappingKey(logicalConnPoint)).build();
65         try {
66             return TransactionUtils.writeTransaction(deviceTransactionManager,
67                     nodeId, LogicalDatastoreType.CONFIGURATION, portMappingIID, mappingBuilder.build());
68         } catch (ExecutionException | InterruptedException e) {
69             return false;
70         }
71     }
72
73     private MountPointUtils() {
74
75     }
76
77 }