Fix netconf-connector-config groupId
[netconf.git] / netconf / netconf-topology / src / test / java / org / opendaylight / netconf / topology / impl / NetconfNodeOperationalDataAggregatorTest.java
1 /*
2  * Copyright (c) 2016 Cisco 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.netconf.topology.impl;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15
16 import com.google.common.collect.Lists;
17 import com.google.common.util.concurrent.Futures;
18 import com.google.common.util.concurrent.ListenableFuture;
19 import java.util.List;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.ClusteredConnectionStatusBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.clustered.connection.status.NodeStatus;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.clustered.connection.status.NodeStatusBuilder;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
32
33 public class NetconfNodeOperationalDataAggregatorTest {
34
35     private List<ListenableFuture<Node>> stateFutures;
36
37     private NetconfNodeOperationalDataAggregator aggregator;
38
39     @Before
40     public void setUp() {
41         aggregator = new NetconfNodeOperationalDataAggregator();
42         stateFutures = Lists.newArrayList();
43     }
44
45     @Test
46     public void testCombineCreateAttempts() throws ExecutionException, InterruptedException {
47         NetconfNode testingNode = new NetconfNodeBuilder().setAvailableCapabilities(
48                 new AvailableCapabilitiesBuilder().setAvailableCapability(Lists.<String>newArrayList()).build())
49                 .setClusteredConnectionStatus(new ClusteredConnectionStatusBuilder().setNodeStatus(Lists.newArrayList(
50                         new NodeStatusBuilder().setStatus(NodeStatus.Status.Connected).build())).build())
51                 .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.Connected).build();
52         stateFutures.add(Futures.immediateFuture(new NodeBuilder().addAugmentation(NetconfNode.class, testingNode).build()));
53
54         ListenableFuture<Node> aggregatedCreateFuture = aggregator.combineCreateAttempts(stateFutures);
55         assertTrue(aggregatedCreateFuture.isDone());
56
57         NetconfNode aggregatedNode = aggregatedCreateFuture.get().getAugmentation(NetconfNode.class);
58         assertEquals(aggregatedNode.getClusteredConnectionStatus().getNodeStatus().get(0).getStatus(),
59                 NodeStatus.Status.Connected);
60     }
61
62     @Test
63     public void testSuccessfulCombineUpdateAttempts() throws ExecutionException, InterruptedException {
64         NetconfNode testingNode = new NetconfNodeBuilder().setAvailableCapabilities(
65                 new AvailableCapabilitiesBuilder().setAvailableCapability(Lists.<String>newArrayList()).build())
66                 .setClusteredConnectionStatus(new ClusteredConnectionStatusBuilder().setNodeStatus(Lists.newArrayList(
67                         new NodeStatusBuilder().setStatus(NodeStatus.Status.Connected).build())).build())
68                 .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.Connected).build();
69         stateFutures.add(Futures.immediateFuture(new NodeBuilder().addAugmentation(NetconfNode.class, testingNode).build()));
70
71         ListenableFuture<Node> aggregatedUpdateFuture = aggregator.combineUpdateAttempts(stateFutures);
72         assertTrue(aggregatedUpdateFuture.isDone());
73
74         NetconfNode aggregatedNode = aggregatedUpdateFuture.get().getAugmentation(NetconfNode.class);
75         assertEquals(aggregatedNode.getClusteredConnectionStatus().getNodeStatus().get(0).getStatus(),
76                 NodeStatus.Status.Connected);
77     }
78
79     @Test
80     public void testSuccessfulCombineDeleteAttempts() throws ExecutionException, InterruptedException {
81         List deleteStateFutures = Lists.newArrayList(Futures.immediateFuture(null), Futures.immediateFuture(null));
82
83         ListenableFuture<Void> deleteFuture = aggregator.combineDeleteAttempts(deleteStateFutures);
84         assertTrue(deleteFuture.isDone());
85         assertEquals(deleteFuture.get(), null);
86     }
87
88     @Test
89     public void testFailedCombineDeleteAttempts() {
90         Exception cause = new Exception("Fail");
91         List deleteStateFutures = Lists.newArrayList(Futures.immediateFuture(null), Futures.immediateFuture(null),
92                 Futures.immediateFailedFuture(cause));
93
94         ListenableFuture<Void> deleteFuture = aggregator.combineDeleteAttempts(deleteStateFutures);
95         assertTrue(deleteFuture.isDone());
96
97         try {
98             deleteFuture.get();
99             fail("Exception expected");
100         } catch(Exception e) {
101             assertSame(e.getCause(), cause);
102         }
103     }
104 }