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;
12 import static org.opendaylight.protocol.bgp.cli.utils.PeerGroupStateCliUtilsTest.UTF8;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.PrintStream;
17 import java.util.Collections;
18 import org.apache.commons.io.IOUtils;
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;
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 = IOUtils.toString(
39 getClass().getClassLoader().getResourceAsStream("empty-global.txt"), UTF8);
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 = IOUtils.toString(
49 getClass().getClassLoader().getResourceAsStream("global.txt"), UTF8);
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"))
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(GlobalAfiSafiStateAugmentation.class,
66 new GlobalAfiSafiStateAugmentationBuilder().setTotalPaths(3L).setTotalPrefixes(4L).build());
70 builder.setAfiSafis(new AfiSafisBuilder()
71 .setAfiSafi(Collections.singletonList(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
72 .setState(stateBuilder.build()).build())).build());