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;
12 import java.io.ByteArrayOutputStream;
13 import java.io.IOException;
14 import java.io.PrintStream;
15 import java.util.Collections;
16 import org.apache.commons.io.IOUtils;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupStateAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupStateAugmentationBuilder;
22 public final class PeerGroupStateCliUtilsTest {
24 private static final String TEST_GROUP = "test-group";
25 static final String UTF8 = "UTF-8";
26 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
27 private final PrintStream stream = new PrintStream(this.output);
30 public void testEmptyPeerGroupStateCli() throws IOException {
31 final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
32 PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
34 final String expected = IOUtils.toString(
35 getClass().getClassLoader().getResourceAsStream("empty-peer-group.txt"), UTF8);
36 assertEquals(expected, this.output.toString());
40 public void testPeerGroupStateCli() throws IOException {
41 final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
43 final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
48 peerGroup.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
49 .StateBuilder().addAugmentation(PeerGroupStateAugmentation.class, groupState).build());
50 PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
52 final String expected = IOUtils.toString(
53 getClass().getClassLoader().getResourceAsStream("peer-group.txt"), UTF8);
54 assertEquals(expected, this.output.toString());