blob: 039d303ab1069c8fc0e3786794579dfb238faeeb [file] [log] [blame]
xueliang9e3ab182016-10-04 13:11:40 +09001/*
2 * Copyright 2016-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.fujitsu;
18
19import org.junit.Before;
20import org.junit.Test;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030021import org.onosproject.netconf.TargetConfig;
xueliang9e3ab182016-10-04 13:11:40 +090022
23import static org.junit.Assert.assertTrue;
24import static org.junit.Assert.assertNotNull;
25import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
26
27/**
28 * Unit tests for methods of FujitsuVoltNeConfig.
29 */
30public class FujitsuVoltNeConfigTest {
31
32 private FujitsuNetconfControllerMock controller;
33 private FujitsuDriverHandlerAdapter driverHandler;
34 private FujitsuVoltNeConfig voltConfig;
35
36 private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListener();
37
38 @Before
39 public void setUp() throws Exception {
40 controller = new FujitsuNetconfControllerMock();
41 driverHandler = controller.setUp(listener);
42 voltConfig = new FujitsuVoltNeConfig();
43 voltConfig.setHandler(driverHandler);
44 }
45
46 /**
47 * Run to verify handling of valid input for get operation.
48 */
49 @Test
50 public void testGetAll() throws Exception {
51 String reply = voltConfig.getAll();
52 assertNotNull("Incorrect response", reply);
53 }
54
55 /**
56 * Verifies XML request string by comparing with generated string.
57 *
58 * @param request XML string for set operation
59 * @return true if XML string matches with generated
60 */
61 private boolean verifyGetRequest(String request) {
62 StringBuilder rpc = new StringBuilder();
63
64 rpc.append(TEST_VOLT_NE_OPEN + TEST_VOLT_NE_NAMESPACE);
65 rpc.append(TEST_ANGLE_RIGHT + TEST_NEW_LINE);
66 rpc.append(TEST_VOLT_NE_CLOSE);
67
68 String testRequest = rpc.toString();
xueliang9e3ab182016-10-04 13:11:40 +090069 boolean result = request.equals(testRequest);
70 assertTrue("Does not match with generated string", result);
71 return result;
72 }
73
74 /**
75 * Internal listener for device service events.
76 */
77 private class InternalSessionListener implements FujitsuNetconfSessionListenerTest {
78 @Override
79 public boolean verifyEditConfig(String request) {
80 return false;
81 }
82
83 @Override
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030084 public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
85 return false;
86 }
87
88 @Override
xueliang9e3ab182016-10-04 13:11:40 +090089 public boolean verifyEditConfig(String target, String mode, String request) {
90 return false;
91 }
92
93 @Override
94 public boolean verifyGet(String filterSchema, String withDefaultsMode) {
95 assertTrue("Incorrect withDefaultsMode",
96 withDefaultsMode.equals(TEST_REPORT_ALL));
97
98 filterSchema = filterSchema.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
99 assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
100 filterSchema.contains(TEST_VOLT_NAMESPACE));
101
102 boolean result = verifyGetRequest(filterSchema);
103 assertTrue("XML verification failure", result);
104 return true;
105 }
106
107 @Override
108 public String buildGetReply() {
109 return null;
110 }
111
112 @Override
113 public boolean verifyWrappedRpc(String request) {
114 return false;
115 }
116
117 @Override
118 public void verifyStartSubscription(String filterSchema) {
119 }
120 }
121
122}