Introduced InterfaceManager in VPP renderer
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / event / NodeOperEventTest.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.groupbasedpolicy.renderer.vpp.event;
10
11 import org.junit.Assert;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.rules.ExpectedException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 public class NodeOperEventTest {
29
30     private final static TopologyKey TOPO_KEY = new TopologyKey(new TopologyId("topo1"));
31     private final static NodeKey NODE_KEY = new NodeKey(new NodeId("node1"));
32     private final static InstanceIdentifier<Node> NODE_IID = InstanceIdentifier.builder(NetworkTopology.class)
33         .child(Topology.class, TOPO_KEY)
34         .child(Node.class, NODE_KEY)
35         .build();
36     private final static NetconfNode NETCONF_NODE_AUG_CONNECTED =
37             new NetconfNodeBuilder().setConnectionStatus(ConnectionStatus.Connected).build();
38     private final static NetconfNode NETCONF_NODE_AUG_CONNECTING =
39             new NetconfNodeBuilder().setConnectionStatus(ConnectionStatus.Connecting).build();
40
41     @Rule
42     public ExpectedException thrown = ExpectedException.none();
43
44     @Test
45     public void testConstructor_nodeCreated() {
46         Node node = new NodeBuilder().setKey(NODE_KEY)
47             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
48             .build();
49         NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
50         Assert.assertTrue(event.getAfter().isPresent());
51         Assert.assertFalse(event.getBefore().isPresent());
52     }
53
54     @Test
55     public void testConstructor_nodeDeleted() {
56         Node node = new NodeBuilder().setKey(NODE_KEY)
57             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
58             .build();
59         NodeOperEvent event = new NodeOperEvent(NODE_IID, node, null);
60         Assert.assertFalse(event.getAfter().isPresent());
61         Assert.assertTrue(event.getBefore().isPresent());
62     }
63
64     @Test
65     public void testConstructor_nodeUpdated() {
66         Node node = new NodeBuilder().setKey(NODE_KEY)
67             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
68             .build();
69         NodeOperEvent event = new NodeOperEvent(NODE_IID, node, node);
70         Assert.assertTrue(event.getAfter().isPresent());
71         Assert.assertTrue(event.getBefore().isPresent());
72     }
73
74     @Test
75     public void testConstructor_beforeNodeMissingNetconfNodeAug_Exception() {
76         Node node = new NodeBuilder().setKey(NODE_KEY).build();
77         thrown.expect(IllegalArgumentException.class);
78         new NodeOperEvent(NODE_IID, node, null);
79     }
80
81     @Test
82     public void testConstructor_afterNodeMissingNetconfNodeAug_Exception() {
83         Node node = new NodeBuilder().setKey(NODE_KEY).build();
84         thrown.expect(IllegalArgumentException.class);
85         new NodeOperEvent(NODE_IID, null, node);
86     }
87
88     @Test
89     public void testConstructor_nullNodes_Exception() {
90         thrown.expect(IllegalArgumentException.class);
91         new NodeOperEvent(NODE_IID, null, null);
92     }
93
94     @Test
95     public void testConstructor_nullIid_Exception() {
96         Node node = new NodeBuilder().setKey(NODE_KEY)
97             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
98             .build();
99         thrown.expect(NullPointerException.class);
100         new NodeOperEvent(null, node, node);
101     }
102
103     @Test
104     public void testIsAfterConnected() {
105         Node node = new NodeBuilder().setKey(NODE_KEY)
106             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
107             .build();
108         NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
109         Assert.assertTrue(event.isAfterConnected());
110     }
111
112     @Test
113     public void testIsBeforeConnected() {
114         Node node = new NodeBuilder().setKey(NODE_KEY)
115             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
116             .build();
117         NodeOperEvent event = new NodeOperEvent(NODE_IID, node, null);
118         Assert.assertTrue(event.isBeforeConnected());
119     }
120
121     @Test
122     public void testIsAfterConnected_false() {
123         Node node = new NodeBuilder().setKey(NODE_KEY)
124             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTING)
125             .build();
126         NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
127         Assert.assertFalse(event.isAfterConnected());
128     }
129     
130     @Test
131     public void testIsBeforeConnected_false() {
132         Node node = new NodeBuilder().setKey(NODE_KEY)
133             .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTING)
134             .build();
135         NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
136         Assert.assertFalse(event.isBeforeConnected());
137     }
138
139 }