blob: 79f0042a5778aac467c77ab22cc313e267c1eb41 [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;
21
22import static org.junit.Assert.assertTrue;
23import static org.junit.Assert.assertNotNull;
24import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
25
26/**
27 * Unit tests for methods of FujitsuVoltNeConfig.
28 */
29public class FujitsuVoltNeConfigTest {
30
31 private FujitsuNetconfControllerMock controller;
32 private FujitsuDriverHandlerAdapter driverHandler;
33 private FujitsuVoltNeConfig voltConfig;
34
35 private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListener();
36
37 @Before
38 public void setUp() throws Exception {
39 controller = new FujitsuNetconfControllerMock();
40 driverHandler = controller.setUp(listener);
41 voltConfig = new FujitsuVoltNeConfig();
42 voltConfig.setHandler(driverHandler);
43 }
44
45 /**
46 * Run to verify handling of valid input for get operation.
47 */
48 @Test
49 public void testGetAll() throws Exception {
50 String reply = voltConfig.getAll();
51 assertNotNull("Incorrect response", reply);
52 }
53
54 /**
55 * Verifies XML request string by comparing with generated string.
56 *
57 * @param request XML string for set operation
58 * @return true if XML string matches with generated
59 */
60 private boolean verifyGetRequest(String request) {
61 StringBuilder rpc = new StringBuilder();
62
63 rpc.append(TEST_VOLT_NE_OPEN + TEST_VOLT_NE_NAMESPACE);
64 rpc.append(TEST_ANGLE_RIGHT + TEST_NEW_LINE);
65 rpc.append(TEST_VOLT_NE_CLOSE);
66
67 String testRequest = rpc.toString();
68 String regex = TEST_WHITESPACES_REGEX;
69 int index = rpc.indexOf(regex);
70 while (index >= ZERO) {
71 testRequest = rpc.replace(index, index + regex.length(), TEST_EMPTY_STRING).toString();
72 request = request.replaceAll(regex, TEST_EMPTY_STRING);
73 }
74 boolean result = request.equals(testRequest);
75 assertTrue("Does not match with generated string", result);
76 return result;
77 }
78
79 /**
80 * Internal listener for device service events.
81 */
82 private class InternalSessionListener implements FujitsuNetconfSessionListenerTest {
83 @Override
84 public boolean verifyEditConfig(String request) {
85 return false;
86 }
87
88 @Override
89 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}