45af340678912c4a193f09cbdd968c0007e54976
[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 com.google.common.io.Resources;
13 import java.io.ByteArrayOutputStream;
14 import java.io.IOException;
15 import java.io.PrintStream;
16 import java.nio.charset.StandardCharsets;
17 import java.util.Collections;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.PeerGroupStateAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.PeerGroupStateAugmentationBuilder;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23
24 public final class PeerGroupStateCliUtilsTest {
25
26     private static final String TEST_GROUP = "test-group";
27     private final ByteArrayOutputStream output = new ByteArrayOutputStream();
28     private final PrintStream stream = new PrintStream(this.output);
29
30     @Test
31     public void testEmptyPeerGroupStateCli() throws IOException {
32         final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
33         PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
34
35         final String expected = Resources.toString(getClass().getClassLoader().getResource("empty-peer-group.txt"),
36             StandardCharsets.UTF_8);
37         assertEquals(expected, this.output.toString());
38     }
39
40     @Test
41     public void testPeerGroupStateCli() throws IOException {
42         final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
43
44         final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
45                 .setTotalPrefixes(Uint32.ONE)
46                 .setTotalPaths(Uint32.valueOf(2))
47                 .build();
48
49         peerGroup.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
50                 .StateBuilder().addAugmentation(PeerGroupStateAugmentation.class, groupState).build());
51         PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
52
53         final String expected = Resources.toString(getClass().getClassLoader().getResource("peer-group.txt"),
54             StandardCharsets.UTF_8);
55         assertEquals(expected, this.output.toString());
56     }
57 }