blob: 4ef61daebfd7a80b49f8b94e2a91f6201d8c0fd0 [file] [log] [blame]
Eunjin Choi8fcdf282017-05-17 16:56:52 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.drivers.cisco.rest;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import org.junit.Test;
22
23import java.io.IOException;
24import java.io.InputStream;
25import java.util.ArrayList;
26
27import static org.junit.Assert.assertEquals;
28
29/**
30 * Tests Cisco NX-API request message generator for Cisco NXOS devices.
31 */
32public class NxApiRequestTest {
33 public static final String REQ_FILE1 = "/testNxApiRequest1.json";
34 public static final String REQ_FILE2 = "/testNxApiRequest2.json";
35
36 @Test
37 public void oneRequestTest() throws IOException {
38 InputStream streamOrig = getClass().getResourceAsStream(REQ_FILE1);
39 ObjectMapper om = new ObjectMapper();
40 JsonNode node1 = om.readTree(streamOrig);
41
42 ArrayList<String> cmds = new ArrayList<>();
43 cmds.add("show interface");
44
45 JsonNode node2 = om.readTree(NxApiRequest.generate(cmds, NxApiRequest.CommandType.CLI));
46
47 assertEquals(node1.toString(), node2.toString());
48 }
49
50 @Test
51 public void manyRequestsTest() throws IOException {
52 InputStream streamOrig = getClass().getResourceAsStream(REQ_FILE2);
53 ObjectMapper om = new ObjectMapper();
54 JsonNode node1 = om.readTree(streamOrig);
55
56 ArrayList<String> cmds = new ArrayList<>();
57 cmds.add("show interface");
58 cmds.add("show ver");
59
60 JsonNode node2 = om.readTree(NxApiRequest.generate(cmds, NxApiRequest.CommandType.CLI));
61
62 assertEquals(node1.toString(), node2.toString());
63 }
64}