Cleanup deprecation warnings in bgp/cli
[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.GlobalAfiSafiStateAugmentationBuilder;
27 import org.opendaylight.yangtools.yang.common.Uint32;
28
29 public class GlobalStateCliUtilsTest {
30     private final ByteArrayOutputStream output = new ByteArrayOutputStream();
31     private final PrintStream stream = new PrintStream(this.output);
32
33     @Test
34     public void testEmptyGlobalStateCliUtil() throws IOException {
35         final GlobalBuilder builder = buildGlobal(false);
36         GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
37
38         final String expected = Resources.toString(getClass().getClassLoader().getResource("empty-global.txt"),
39             StandardCharsets.UTF_8);
40         assertEquals(expected, this.output.toString());
41     }
42
43     @Test
44     public void testGlobalStateCliUtil() throws IOException {
45         final GlobalBuilder builder = buildGlobal(true);
46         GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
47
48         final String expected = Resources.toString(getClass().getClassLoader().getResource("global.txt"),
49             StandardCharsets.UTF_8);
50         assertEquals(expected, this.output.toString());
51     }
52
53     static GlobalBuilder buildGlobal(final boolean withStateAug) {
54         final GlobalBuilder builder = new GlobalBuilder().setState(new StateBuilder()
55                 .setAs(AsNumber.getDefaultInstance("100"))
56                 .setTotalPaths(Uint32.ONE)
57                 .setTotalPrefixes(Uint32.TWO)
58                 .build());
59
60         final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
61                 .common.afi.safi.list.afi.safi.StateBuilder stateBuilder =
62                 new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
63                         .common.afi.safi.list.afi.safi.StateBuilder();
64         if (withStateAug) {
65             stateBuilder.addAugmentation(new GlobalAfiSafiStateAugmentationBuilder()
66                 .setTotalPaths(Uint32.valueOf(3))
67                 .setTotalPrefixes(Uint32.valueOf(4))
68                 .build());
69         }
70
71         return builder
72                 .setAfiSafis(new AfiSafisBuilder()
73                     .setAfiSafi(Collections.singletonList(new AfiSafiBuilder()
74                         .setAfiSafiName(IPV4UNICAST.class)
75                         .setState(stateBuilder.build())
76                         .build()))
77                     .build());
78     }
79 }