2 * Copyright (c) 2016 Cisco 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.groupbasedpolicy.renderer.vpp.event;
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;
28 public class NodeOperEventTest {
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)
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();
42 public ExpectedException thrown = ExpectedException.none();
45 public void testConstructor_nodeCreated() {
46 Node node = new NodeBuilder().setKey(NODE_KEY)
47 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
49 NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
50 Assert.assertTrue(event.getAfter().isPresent());
51 Assert.assertFalse(event.getBefore().isPresent());
55 public void testConstructor_nodeDeleted() {
56 Node node = new NodeBuilder().setKey(NODE_KEY)
57 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
59 NodeOperEvent event = new NodeOperEvent(NODE_IID, node, null);
60 Assert.assertFalse(event.getAfter().isPresent());
61 Assert.assertTrue(event.getBefore().isPresent());
65 public void testConstructor_nodeUpdated() {
66 Node node = new NodeBuilder().setKey(NODE_KEY)
67 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
69 NodeOperEvent event = new NodeOperEvent(NODE_IID, node, node);
70 Assert.assertTrue(event.getAfter().isPresent());
71 Assert.assertTrue(event.getBefore().isPresent());
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);
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);
89 public void testConstructor_nullNodes_Exception() {
90 thrown.expect(IllegalArgumentException.class);
91 new NodeOperEvent(NODE_IID, null, null);
95 public void testConstructor_nullIid_Exception() {
96 Node node = new NodeBuilder().setKey(NODE_KEY)
97 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
99 thrown.expect(NullPointerException.class);
100 new NodeOperEvent(null, node, node);
104 public void testIsAfterConnected() {
105 Node node = new NodeBuilder().setKey(NODE_KEY)
106 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
108 NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
109 Assert.assertTrue(event.isAfterConnected());
113 public void testIsBeforeConnected() {
114 Node node = new NodeBuilder().setKey(NODE_KEY)
115 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTED)
117 NodeOperEvent event = new NodeOperEvent(NODE_IID, node, null);
118 Assert.assertTrue(event.isBeforeConnected());
122 public void testIsAfterConnected_false() {
123 Node node = new NodeBuilder().setKey(NODE_KEY)
124 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTING)
126 NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
127 Assert.assertFalse(event.isAfterConnected());
131 public void testIsBeforeConnected_false() {
132 Node node = new NodeBuilder().setKey(NODE_KEY)
133 .addAugmentation(NetconfNode.class, NETCONF_NODE_AUG_CONNECTING)
135 NodeOperEvent event = new NodeOperEvent(NODE_IID, null, node);
136 Assert.assertFalse(event.isBeforeConnected());