2b6c77ce07ca8af060a7390e065fedb9cb9ff67c
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.test.example;
23
24 import java.util.Arrays;
25 import org.mockito.Mockito;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfAccessorImpl;
28 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfCommunicatorManager;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
38
39 public class TestNetconfHelper extends Mockito {
40
41     /**
42      * Provide a test node.
43      * @param nodeIdString
44      */
45     public static Node getTestNode(NodeId nodeId, String capabilityString) {
46         NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder();
47         netconfNodeBuilder.setConnectionStatus(ConnectionStatus.Connected);
48         AvailableCapabilityBuilder availableCapabilityBuilder = new AvailableCapabilityBuilder();
49         availableCapabilityBuilder.setCapability(capabilityString);
50         AvailableCapabilitiesBuilder availableCapabilitesBuilder = new AvailableCapabilitiesBuilder();
51         availableCapabilitesBuilder.setAvailableCapability(Arrays.asList(availableCapabilityBuilder.build()));
52         netconfNodeBuilder.setAvailableCapabilities(availableCapabilitesBuilder.build());
53         NetconfNode rootNodeNetconf = netconfNodeBuilder.build();
54
55         NodeBuilder nodeBuilder = new NodeBuilder();
56
57         nodeBuilder.addAugmentation(rootNodeNetconf);
58         nodeBuilder.setNodeId(nodeId);
59         return nodeBuilder.build();
60     }
61
62     /**
63      * Provide a test NetconfAccessorImpl
64      * @return object NetconfAccessorImpl
65      */
66     public static NetconfAccessorImpl getNetconfAcessorImpl() {
67         NetconfCommunicatorManager netconfCommunicatorManager = mock(NetconfCommunicatorManager.class);
68         DomContext domContext = mock(DomContext.class);
69         String nodeIdString = "Test";
70         String capabilityStringForNetworkElement = "network-element";
71         NodeId nodeId = new NodeId(nodeIdString);
72         NetconfNode testNode = TestNetconfHelper.getTestNode(nodeId, capabilityStringForNetworkElement)
73                 .augmentation(NetconfNode.class);
74
75         NetconfNodeStateServiceImpl netconfNodeStateService = mock(NetconfNodeStateServiceImpl.class);
76         NetconfAccessorImpl netconfAccessor =
77                 new NetconfAccessorImpl(nodeId, testNode, netconfCommunicatorManager, domContext, netconfNodeStateService);
78         return netconfAccessor;
79     }
80 }