Use new Uint* constants
[bgpcep.git] / bgp / cli / src / test / java / org / opendaylight / protocol / bgp / cli / utils / GlobalStateCliUtilsTest.java
1 /*
2  * Copyright (c) 2017 AT&T Intellectual Property. 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.cli.utils;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.protocol.bgp.cli.utils.BGPOperationalStateUtilsTest.RIB_ID;
12
13 import com.google.common.io.Resources;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.PrintStream;
17 import java.nio.charset.StandardCharsets;
18 import java.util.Collections;
19 import org.junit.Test;
20 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.StateBuilder;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAfiSafiStateAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAfiSafiStateAugmentationBuilder;
28 import org.opendaylight.yangtools.yang.common.Uint32;
29
30 public class GlobalStateCliUtilsTest {
31     private final ByteArrayOutputStream output = new ByteArrayOutputStream();
32     private final PrintStream stream = new PrintStream(this.output);
33
34     @Test
35     public void testEmptyGlobalStateCliUtil() throws IOException {
36         final GlobalBuilder builder = buildGlobal(false);
37         GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
38
39         final String expected = Resources.toString(getClass().getClassLoader().getResource("empty-global.txt"),
40             StandardCharsets.UTF_8);
41         assertEquals(expected, this.output.toString());
42     }
43
44     @Test
45     public void testGlobalStateCliUtil() throws IOException {
46         final GlobalBuilder builder = buildGlobal(true);
47         GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
48
49         final String expected = Resources.toString(getClass().getClassLoader().getResource("global.txt"),
50             StandardCharsets.UTF_8);
51         assertEquals(expected, this.output.toString());
52     }
53
54     static GlobalBuilder buildGlobal(final boolean withStateAug) {
55         final GlobalBuilder builder = new GlobalBuilder().setState(new StateBuilder()
56                 .setAs(AsNumber.getDefaultInstance("100"))
57                 .setTotalPaths(Uint32.ONE)
58                 .setTotalPrefixes(Uint32.TWO)
59                 .build());
60
61         final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
62                 .common.afi.safi.list.afi.safi.StateBuilder stateBuilder =
63                 new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
64                         .common.afi.safi.list.afi.safi.StateBuilder();
65         if (withStateAug) {
66             stateBuilder.addAugmentation(GlobalAfiSafiStateAugmentation.class,
67                     new GlobalAfiSafiStateAugmentationBuilder()
68                         .setTotalPaths(Uint32.valueOf(3))
69                         .setTotalPrefixes(Uint32.valueOf(4))
70                         .build());
71         }
72
73
74         builder.setAfiSafis(new AfiSafisBuilder()
75                 .setAfiSafi(Collections.singletonList(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
76                         .setState(stateBuilder.build()).build())).build());
77         return builder;
78     }
79 }