2 * Copyright (c) 2017 AT&T Intellectual Property. 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
8 package org.opendaylight.protocol.bgp.cli.utils;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.protocol.bgp.cli.utils.BGPOperationalStateUtilsTest.RIB_ID;
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;
29 public class GlobalStateCliUtilsTest {
30 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
31 private final PrintStream stream = new PrintStream(this.output);
34 public void testEmptyGlobalStateCliUtil() throws IOException {
35 final GlobalBuilder builder = buildGlobal(false);
36 GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
38 final String expected = Resources.toString(getClass().getClassLoader().getResource("empty-global.txt"),
39 StandardCharsets.UTF_8);
40 assertEquals(expected, this.output.toString());
44 public void testGlobalStateCliUtil() throws IOException {
45 final GlobalBuilder builder = buildGlobal(true);
46 GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
48 final String expected = Resources.toString(getClass().getClassLoader().getResource("global.txt"),
49 StandardCharsets.UTF_8);
50 assertEquals(expected, this.output.toString());
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)
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();
65 stateBuilder.addAugmentation(new GlobalAfiSafiStateAugmentationBuilder()
66 .setTotalPaths(Uint32.valueOf(3))
67 .setTotalPrefixes(Uint32.valueOf(4))
72 .setAfiSafis(new AfiSafisBuilder()
73 .setAfiSafi(Collections.singletonList(new AfiSafiBuilder()
74 .setAfiSafiName(IPV4UNICAST.class)
75 .setState(stateBuilder.build())