Introduced InterfaceManager in VPP renderer
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / event / VppEndpointConfEventTest.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.groupbasedpolicy.common.rev140421.ContextId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 public class VppEndpointConfEventTest {
25
26     private final static String ADDRESS = "1.1.1.1/32";
27     private final static ContextId CONTEXT_ID = new ContextId("ctx1");
28     private final static VppEndpointKey BASIC_VPP_EP_KEY =
29             new VppEndpointKey(ADDRESS, AddressType.class, CONTEXT_ID, ContextType.class);
30     private final static InstanceIdentifier<VppEndpoint> BASIC_VPP_EP_IID =
31             InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, BASIC_VPP_EP_KEY).build();
32
33     @Rule
34     public ExpectedException thrown = ExpectedException.none();
35
36     @Test
37     public void testConstructor_vppEpCreated() {
38         VppEndpoint vppEndpoint = basicVppEpBuilder().build();
39         VppEndpointConfEvent event = new VppEndpointConfEvent(BASIC_VPP_EP_IID, null, vppEndpoint);
40         Assert.assertTrue(event.getAfter().isPresent());
41         Assert.assertFalse(event.getBefore().isPresent());
42     }
43
44     @Test
45     public void testConstructor_vppEpDeleted() {
46         VppEndpoint vppEndpoint = basicVppEpBuilder().build();
47         VppEndpointConfEvent event = new VppEndpointConfEvent(BASIC_VPP_EP_IID, vppEndpoint, null);
48         Assert.assertFalse(event.getAfter().isPresent());
49         Assert.assertTrue(event.getBefore().isPresent());
50     }
51
52     @Test
53     public void testConstructor_vppEpUpdated() {
54         VppEndpoint vppEndpoint = basicVppEpBuilder().build();
55         VppEndpointConfEvent event = new VppEndpointConfEvent(BASIC_VPP_EP_IID, vppEndpoint, vppEndpoint);
56         Assert.assertTrue(event.getAfter().isPresent());
57         Assert.assertTrue(event.getBefore().isPresent());
58     }
59
60     @Test
61     public void testConstructor_nullVppEp_Exception() {
62         thrown.expect(IllegalArgumentException.class);
63         new VppEndpointConfEvent(BASIC_VPP_EP_IID, null, null);
64     }
65
66     private VppEndpointBuilder basicVppEpBuilder() {
67         return new VppEndpointBuilder().setAddress(ADDRESS)
68             .setAddressType(AddressType.class)
69             .setContextId(CONTEXT_ID)
70             .setContextType(ContextType.class);
71     }
72
73 }