aac78442dd60a14a1e668311218380a652ded349
[bgpcep.git] / bgp / cli / src / test / java / org / opendaylight / protocol / bgp / cli / utils / PeerGroupStateCliUtilsTest.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
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.rev171207.PeerGroupStateAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.PeerGroupStateAugmentationBuilder;
21
22 public final class PeerGroupStateCliUtilsTest {
23
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);
28
29     @Test
30     public void testEmptyPeerGroupStateCli() throws IOException {
31         final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
32         PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
33
34         final String expected = IOUtils.toString(
35                 getClass().getClassLoader().getResourceAsStream("empty-peer-group.txt"), UTF8);
36         assertEquals(expected, this.output.toString());
37     }
38
39     @Test
40     public void testPeerGroupStateCli() throws IOException {
41         final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
42
43         final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
44                 .setTotalPrefixes(1L)
45                 .setTotalPaths(2L)
46                 .build();
47
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);
51
52         final String expected = IOUtils.toString(
53                 getClass().getClassLoader().getResourceAsStream("peer-group.txt"), UTF8);
54         assertEquals(expected, this.output.toString());
55     }
56 }