ac1f9a9452254fd52b1dd0ec8d324e4bd2feeb5b
[bgpcep.git] / bgp / rib-spi / src / test / java / org / opendaylight / protocol / bgp / rib / spi / PeerRoleUtilTest.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 package org.opendaylight.protocol.bgp.rib.spi;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12
13 import com.google.common.base.Optional;
14 import java.lang.reflect.Constructor;
15 import java.lang.reflect.InvocationTargetException;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
19
20 public class PeerRoleUtilTest {
21     @Test(expected = UnsupportedOperationException.class)
22     public void testPrivateConstructor() throws Throwable {
23         final Constructor<PeerRoleUtil> c = PeerRoleUtil.class.getDeclaredConstructor();
24         c.setAccessible(true);
25         try {
26             c.newInstance();
27         } catch (final InvocationTargetException e) {
28             throw e.getCause();
29         }
30     }
31
32     @Test
33     public void roleForChange() {
34         assertNull(PeerRoleUtil.roleForChange(Optional.fromNullable(null)));
35         assertEquals(PeerRole.Ebgp, PeerRoleUtil.roleForChange(Optional.of(new ImmutableLeafNodeBuilder<>()
36             .withNodeIdentifier(PeerRoleUtil.PEER_ROLE_NID).withValue("ebgp").build())));
37     }
38
39     @Test
40     public void roleForString() {
41         assertEquals("ebgp",PeerRoleUtil.roleForString(PeerRole.Ebgp));
42         assertEquals("ibgp",PeerRoleUtil.roleForString(PeerRole.Ibgp));
43         assertEquals("rr-client",PeerRoleUtil.roleForString(PeerRole.RrClient));
44         assertEquals("internal",PeerRoleUtil.roleForString(PeerRole.Internal));
45     }
46 }