Committed by
Gerrit Code Review
[ONOS-5254] JUNIT Mocks for FUJITSU NETCONF
Change-Id: Iac2b6473a71c1d981b6d2dadc316a31d9b4a02df
Showing
8 changed files
with
722 additions
and
0 deletions
... | @@ -2,6 +2,7 @@ COMPILE_DEPS = [ | ... | @@ -2,6 +2,7 @@ COMPILE_DEPS = [ |
2 | '//lib:CORE_DEPS', | 2 | '//lib:CORE_DEPS', |
3 | '//drivers/utilities:onos-drivers-utilities', | 3 | '//drivers/utilities:onos-drivers-utilities', |
4 | '//protocols/netconf/api:onos-protocols-netconf-api', | 4 | '//protocols/netconf/api:onos-protocols-netconf-api', |
5 | + '//protocols/netconf/ctl:onos-protocols-netconf-ctl', | ||
5 | '//lib:org.apache.karaf.shell.console', | 6 | '//lib:org.apache.karaf.shell.console', |
6 | '//cli:onos-cli', | 7 | '//cli:onos-cli', |
7 | '//apps/optical-model:onos-apps-optical-model', | 8 | '//apps/optical-model:onos-apps-optical-model', | ... | ... |
... | @@ -56,6 +56,11 @@ | ... | @@ -56,6 +56,11 @@ |
56 | </dependency> | 56 | </dependency> |
57 | <dependency> | 57 | <dependency> |
58 | <groupId>org.onosproject</groupId> | 58 | <groupId>org.onosproject</groupId> |
59 | + <artifactId>onos-netconf-ctl</artifactId> | ||
60 | + <version>${project.version}</version> | ||
61 | + </dependency> | ||
62 | + <dependency> | ||
63 | + <groupId>org.onosproject</groupId> | ||
59 | <artifactId>onos-drivers-utilities</artifactId> | 64 | <artifactId>onos-drivers-utilities</artifactId> |
60 | <version>${project.version}</version> | 65 | <version>${project.version}</version> |
61 | </dependency> | 66 | </dependency> |
... | @@ -69,6 +74,11 @@ | ... | @@ -69,6 +74,11 @@ |
69 | <artifactId>org.apache.karaf.shell.console</artifactId> | 74 | <artifactId>org.apache.karaf.shell.console</artifactId> |
70 | <scope>provided</scope> | 75 | <scope>provided</scope> |
71 | </dependency> | 76 | </dependency> |
77 | + <dependency> | ||
78 | + <groupId>commons-io</groupId> | ||
79 | + <artifactId>commons-io</artifactId> | ||
80 | + <version>2.4</version> | ||
81 | + </dependency> | ||
72 | </dependencies> | 82 | </dependencies> |
73 | 83 | ||
74 | </project> | 84 | </project> | ... | ... |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuDriverHandlerAdapter.java
0 → 100644
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import org.onosproject.net.DeviceId; | ||
20 | +import org.onosproject.net.driver.Behaviour; | ||
21 | +import org.onosproject.net.driver.DefaultDriverHandler; | ||
22 | +import org.onosproject.net.driver.DriverData; | ||
23 | +import org.onosproject.mastership.MastershipService; | ||
24 | +import org.onosproject.mastership.MastershipServiceAdapter; | ||
25 | +import org.onosproject.netconf.NetconfController; | ||
26 | + | ||
27 | + | ||
28 | +/** | ||
29 | + * Mock DefaultDriverHandler. | ||
30 | + */ | ||
31 | +public class FujitsuDriverHandlerAdapter extends DefaultDriverHandler { | ||
32 | + | ||
33 | + private NetconfController controller; | ||
34 | + private final MastershipService mastershipService = new InternalMastershipServiceMock();; | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates new driver handler with the attached driver data. | ||
38 | + * | ||
39 | + * @param data driver data to attach | ||
40 | + */ | ||
41 | + public FujitsuDriverHandlerAdapter(DriverData data) { | ||
42 | + super(data); | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) { | ||
47 | + return true; | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public <T> T get(Class<T> serviceClass) { | ||
52 | + if (serviceClass == NetconfController.class) { | ||
53 | + return (T) this.controller; | ||
54 | + } else if (serviceClass == MastershipService.class) { | ||
55 | + return (T) this.mastershipService; | ||
56 | + } | ||
57 | + return null; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Set up initial environment. | ||
62 | + * | ||
63 | + * @param controller NETCONF controller instance | ||
64 | + */ | ||
65 | + public void setUp(NetconfController controller) { | ||
66 | + this.controller = controller; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Mock MastershipServiceAdapter. | ||
71 | + */ | ||
72 | + private class InternalMastershipServiceMock extends MastershipServiceAdapter { | ||
73 | + | ||
74 | + @Override | ||
75 | + public boolean isLocalMaster(DeviceId deviceId) { | ||
76 | + return true; | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | +} |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfControllerMock.java
0 → 100644
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import com.google.common.collect.ImmutableMap; | ||
20 | +import org.onlab.packet.IpAddress; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.driver.DefaultDriver; | ||
23 | +import org.onosproject.net.driver.DefaultDriverData; | ||
24 | +import org.onosproject.netconf.NetconfDevice; | ||
25 | +import org.onosproject.netconf.NetconfDeviceInfo; | ||
26 | +import org.onosproject.netconf.NetconfException; | ||
27 | +import org.onosproject.netconf.ctl.NetconfControllerImpl; | ||
28 | + | ||
29 | +import java.util.ArrayList; | ||
30 | +import java.util.Arrays; | ||
31 | +import java.util.Map; | ||
32 | +import java.util.Set; | ||
33 | +import java.util.concurrent.ConcurrentHashMap; | ||
34 | + | ||
35 | + | ||
36 | +/** | ||
37 | + * Mock NetconfControllerImpl. | ||
38 | + */ | ||
39 | +class FujitsuNetconfControllerMock extends NetconfControllerImpl { | ||
40 | + | ||
41 | + private static final String VOLT_DRIVER_NAME = "fujitsu-volt-netconf"; | ||
42 | + private static final String VOLT_DEVICE_USERNAME = "abc"; | ||
43 | + private static final String VOLT_DEVICE_PASSWORD = "123"; | ||
44 | + private static final String VOLT_DEVICE_IP = "10.10.10.11"; | ||
45 | + private static final int VOLT_DEVICE_PORT = 830; | ||
46 | + | ||
47 | + private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); | ||
48 | + | ||
49 | + @Override | ||
50 | + public NetconfDevice getNetconfDevice(DeviceId deviceInfo) { | ||
51 | + return netconfDeviceMap.get(deviceInfo); | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public NetconfDevice getNetconfDevice(IpAddress ip, int port) { | ||
56 | + for (DeviceId info : netconfDeviceMap.keySet()) { | ||
57 | + if (info.uri().getSchemeSpecificPart().equals(ip.toString() + ":" + port)) { | ||
58 | + return netconfDeviceMap.get(info); | ||
59 | + } | ||
60 | + } | ||
61 | + return null; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException { | ||
66 | + if (netconfDeviceMap.containsKey(deviceId)) { | ||
67 | + log.debug("Device {} is already present", deviceId); | ||
68 | + return netconfDeviceMap.get(deviceId); | ||
69 | + } else { | ||
70 | + log.debug("Creating NETCONF device {}", deviceId); | ||
71 | + String ip; | ||
72 | + int port; | ||
73 | + String[] info = deviceId.toString().split(":"); | ||
74 | + if (info.length == 3) { | ||
75 | + ip = info[1]; | ||
76 | + port = Integer.parseInt(info[2]); | ||
77 | + } else { | ||
78 | + ip = Arrays.asList(info).stream().filter(el -> !el.equals(info[0]) | ||
79 | + && !el.equals(info[info.length - 1])) | ||
80 | + .reduce((t, u) -> t + ":" + u) | ||
81 | + .get(); | ||
82 | + log.debug("ip v6 {}", ip); | ||
83 | + port = Integer.parseInt(info[info.length - 1]); | ||
84 | + } | ||
85 | + try { | ||
86 | + NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo( | ||
87 | + VOLT_DEVICE_USERNAME, | ||
88 | + VOLT_DEVICE_PASSWORD, | ||
89 | + IpAddress.valueOf(ip), | ||
90 | + port); | ||
91 | + NetconfDevice netconfDevice = new FujitsuNetconfDeviceMock(deviceInfo); | ||
92 | + netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice); | ||
93 | + return netconfDevice; | ||
94 | + } catch (NullPointerException e) { | ||
95 | + throw new NetconfException("Cannot connect a device " + deviceId, e); | ||
96 | + } | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public void disconnectDevice(DeviceId deviceId, boolean remove) { | ||
102 | + if (!netconfDeviceMap.containsKey(deviceId)) { | ||
103 | + log.warn("Device {} is not present", deviceId); | ||
104 | + } else { | ||
105 | + netconfDeviceMap.remove(deviceId); | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public Map<DeviceId, NetconfDevice> getDevicesMap() { | ||
111 | + return netconfDeviceMap; | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public Set<DeviceId> getNetconfDevices() { | ||
116 | + return netconfDeviceMap.keySet(); | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public void removeDevice(DeviceId deviceId) { | ||
121 | + if (!netconfDeviceMap.containsKey(deviceId)) { | ||
122 | + log.warn("Device {} is not present", deviceId); | ||
123 | + } else { | ||
124 | + netconfDeviceMap.remove(deviceId); | ||
125 | + } | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Sets up initial test environment. | ||
130 | + * | ||
131 | + * @param listener listener to be added | ||
132 | + * @return driver handler | ||
133 | + * @throws NetconfException when there is a problem | ||
134 | + */ | ||
135 | + public FujitsuDriverHandlerAdapter setUp(FujitsuNetconfSessionListenerTest listener) throws NetconfException { | ||
136 | + try { | ||
137 | + NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo( | ||
138 | + VOLT_DEVICE_USERNAME, VOLT_DEVICE_PASSWORD, | ||
139 | + IpAddress.valueOf(VOLT_DEVICE_IP), VOLT_DEVICE_PORT); | ||
140 | + | ||
141 | + NetconfDevice netconfDevice = connectDevice(deviceInfo.getDeviceId()); | ||
142 | + | ||
143 | + FujitsuNetconfSessionMock session = (FujitsuNetconfSessionMock) netconfDevice.getSession(); | ||
144 | + session.setListener(listener); | ||
145 | + | ||
146 | + DeviceId deviceId = deviceInfo.getDeviceId(); | ||
147 | + DefaultDriver driver = new DefaultDriver( | ||
148 | + VOLT_DRIVER_NAME, new ArrayList<>(), | ||
149 | + "Fujitsu", "1.0", "1.0", | ||
150 | + ImmutableMap.of(), ImmutableMap.of()); | ||
151 | + | ||
152 | + DefaultDriverData driverData = new DefaultDriverData(driver, deviceId); | ||
153 | + | ||
154 | + FujitsuDriverHandlerAdapter driverHandler; | ||
155 | + driverHandler = new FujitsuDriverHandlerAdapter(driverData); | ||
156 | + driverHandler.setUp(this); | ||
157 | + | ||
158 | + return driverHandler; | ||
159 | + } catch (NetconfException e) { | ||
160 | + throw new NetconfException("Cannot create a device ", e); | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | +} |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfDeviceMock.java
0 → 100644
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import org.onosproject.netconf.NetconfDevice; | ||
20 | +import org.onosproject.netconf.NetconfDeviceInfo; | ||
21 | +import org.onosproject.netconf.NetconfException; | ||
22 | +import org.onosproject.netconf.NetconfSession; | ||
23 | + | ||
24 | + | ||
25 | +/** | ||
26 | +* Mock DefaultNetconfDevice. | ||
27 | +*/ | ||
28 | +class FujitsuNetconfDeviceMock implements NetconfDevice { | ||
29 | + | ||
30 | + private NetconfDeviceInfo netconfDeviceInfo; | ||
31 | + private boolean deviceState = false; | ||
32 | + private NetconfSession netconfSession; | ||
33 | + | ||
34 | + /** | ||
35 | + * Creates a new NETCONF device with the information provided. | ||
36 | + * | ||
37 | + * @param deviceInfo information about the device to be created. | ||
38 | + * @throws NetconfException if there are problems in creating or establishing | ||
39 | + * the underlying NETCONF connection and session. | ||
40 | + */ | ||
41 | + public FujitsuNetconfDeviceMock(NetconfDeviceInfo deviceInfo) throws NetconfException { | ||
42 | + netconfDeviceInfo = deviceInfo; | ||
43 | + try { | ||
44 | + netconfSession = new FujitsuNetconfSessionMock(); | ||
45 | + deviceState = true; | ||
46 | + } catch (Exception e) { | ||
47 | + throw new NetconfException("Cannot create Connection and Session"); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean isActive() { | ||
53 | + return deviceState; | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public NetconfSession getSession() { | ||
58 | + return netconfSession; | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public void disconnect() { | ||
63 | + deviceState = false; | ||
64 | + netconfSession = null; | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public NetconfDeviceInfo getDeviceInfo() { | ||
69 | + return netconfDeviceInfo; | ||
70 | + } | ||
71 | + | ||
72 | +} |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionListenerTest.java
0 → 100644
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | + | ||
20 | +public interface FujitsuNetconfSessionListenerTest { | ||
21 | + | ||
22 | + /** | ||
23 | + * Verify editConfig request arguments. | ||
24 | + * | ||
25 | + * @param newConfiguration configuration to set | ||
26 | + * @return true if everuthing as expected | ||
27 | + */ | ||
28 | + boolean verifyEditConfig(String newConfiguration); | ||
29 | + | ||
30 | + /** | ||
31 | + * Verify editConfig request arguments. | ||
32 | + * | ||
33 | + * @param targetConfiguration the targetConfiguration to change | ||
34 | + * @param mode selected mode to change the configuration | ||
35 | + * @param newConfiguration configuration to set | ||
36 | + * @return true if everuthing as expected | ||
37 | + */ | ||
38 | + boolean verifyEditConfig(String targetConfiguration, String mode, String newConfiguration); | ||
39 | + | ||
40 | + /** | ||
41 | + * Verify get request arguments. | ||
42 | + * | ||
43 | + * @param filterSchema XML subtrees to include in the reply | ||
44 | + * @param withDefaultsMode with-defaults mode | ||
45 | + * @return true if everuthing as expected | ||
46 | + */ | ||
47 | + boolean verifyGet(String filterSchema, String withDefaultsMode); | ||
48 | + | ||
49 | + /** | ||
50 | + * Build get RPC response if necessary. | ||
51 | + * | ||
52 | + * @return String or null if not support | ||
53 | + */ | ||
54 | + String buildGetReply(); | ||
55 | + | ||
56 | + /** | ||
57 | + * Verify rpc request arguments. | ||
58 | + * | ||
59 | + * @param request the XML containing the request to the server. | ||
60 | + * @return true if everuthing as expected | ||
61 | + */ | ||
62 | + boolean verifyWrappedRpc(String request); | ||
63 | + | ||
64 | + /** | ||
65 | + * Verify rpc request arguments. | ||
66 | + * | ||
67 | + * @param filterSchema XML subtrees to indicate specific notification | ||
68 | + */ | ||
69 | + void verifyStartSubscription(String filterSchema); | ||
70 | + | ||
71 | +} |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionMock.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015-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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
20 | +import org.onosproject.netconf.NetconfDeviceOutputEventListener; | ||
21 | +import org.onosproject.netconf.NetconfException; | ||
22 | +import org.onosproject.netconf.NetconfSession; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | +import java.util.concurrent.CompletableFuture; | ||
26 | + | ||
27 | + | ||
28 | +/** | ||
29 | + * Mock NetconfSessionImpl. | ||
30 | + */ | ||
31 | +public class FujitsuNetconfSessionMock implements NetconfSession { | ||
32 | + | ||
33 | + private FujitsuNetconfSessionListenerTest listener; | ||
34 | + | ||
35 | + /** | ||
36 | + * Registers a listener to be invoked for verification. | ||
37 | + * | ||
38 | + * @param listener listener to be added | ||
39 | + */ | ||
40 | + public void setListener(FujitsuNetconfSessionListenerTest listener) { | ||
41 | + this.listener = listener; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public CompletableFuture<String> request(String request) throws NetconfException { | ||
46 | + return null; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public String get(String request) throws NetconfException { | ||
51 | + return null; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public String get(String filterSchema, String withDefaultsMode) | ||
56 | + throws NetconfException { | ||
57 | + boolean result = true; | ||
58 | + String reply = null; | ||
59 | + if (listener != null) { | ||
60 | + result = listener.verifyGet(filterSchema, withDefaultsMode); | ||
61 | + if (result) { | ||
62 | + reply = listener.buildGetReply(); | ||
63 | + } | ||
64 | + } | ||
65 | + return result ? ((reply == null) ? filterSchema : reply) : null; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public String doWrappedRpc(String request) throws NetconfException { | ||
70 | + boolean result = true; | ||
71 | + if (listener != null) { | ||
72 | + result = listener.verifyWrappedRpc(request); | ||
73 | + } | ||
74 | + return result ? request : null; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public String requestSync(String request) throws NetconfException { | ||
79 | + return null; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public String getConfig(String targetConfiguration) throws NetconfException { | ||
84 | + return null; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public String getConfig(String targetConfiguration, String configurationFilterSchema) | ||
89 | + throws NetconfException { | ||
90 | + return null; | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public boolean editConfig(String newConfiguration) throws NetconfException { | ||
95 | + boolean result = true; | ||
96 | + if (listener != null) { | ||
97 | + result = listener.verifyEditConfig(newConfiguration); | ||
98 | + } | ||
99 | + return result; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public boolean editConfig(String targetConfiguration, String mode, String newConfiguration) | ||
104 | + throws NetconfException { | ||
105 | + boolean result = true; | ||
106 | + if (listener != null) { | ||
107 | + result = listener.verifyEditConfig(targetConfiguration, mode, newConfiguration); | ||
108 | + } | ||
109 | + return result; | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public boolean copyConfig(String targetConfiguration, String newConfiguration) | ||
114 | + throws NetconfException { | ||
115 | + return false; | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public boolean deleteConfig(String targetConfiguration) throws NetconfException { | ||
120 | + return false; | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public void startSubscription() throws NetconfException { | ||
125 | + } | ||
126 | + | ||
127 | + @Beta | ||
128 | + @Override | ||
129 | + public void startSubscription(String filterSchema) throws NetconfException { | ||
130 | + if (listener != null) { | ||
131 | + listener.verifyStartSubscription(filterSchema); | ||
132 | + } | ||
133 | + return; | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public void endSubscription() throws NetconfException { | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public boolean lock(String configType) throws NetconfException { | ||
142 | + return false; | ||
143 | + } | ||
144 | + | ||
145 | + @Override | ||
146 | + public boolean unlock(String configType) throws NetconfException { | ||
147 | + return false; | ||
148 | + } | ||
149 | + | ||
150 | + @Override | ||
151 | + public boolean lock() throws NetconfException { | ||
152 | + return false; | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public boolean unlock() throws NetconfException { | ||
157 | + return false; | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public boolean close() throws NetconfException { | ||
162 | + return false; | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public String getSessionId() { | ||
167 | + return null; | ||
168 | + } | ||
169 | + | ||
170 | + @Override | ||
171 | + public String getServerCapabilities() { | ||
172 | + return null; | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
176 | + public void setDeviceCapabilities(List<String> capabilities) { | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { | ||
181 | + } | ||
182 | + | ||
183 | + @Override | ||
184 | + public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { | ||
185 | + } | ||
186 | + | ||
187 | +} |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtilityMock.java
0 → 100644
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +/** | ||
20 | + * Mock FujitsuVoltXmlUtility. | ||
21 | + * This is to avoid using the same names/definitions | ||
22 | + * in FujitsuVoltXmlUtility in test codes - not tied to actual codes. | ||
23 | + */ | ||
24 | +final class FujitsuVoltXmlUtilityMock { | ||
25 | + | ||
26 | + public static final String TEST_COLON = ":"; | ||
27 | + public static final String TEST_DOT = "."; | ||
28 | + public static final String TEST_HYPHEN = "-"; | ||
29 | + public static final String TEST_SLASH = "/"; | ||
30 | + public static final String TEST_SPACE = " "; | ||
31 | + public static final String TEST_NEW_LINE = "\n"; | ||
32 | + public static final String TEST_ANGLE_LEFT = "<"; | ||
33 | + public static final String TEST_ANGLE_RIGHT = ">"; | ||
34 | + | ||
35 | + public static final String TEST_REPORT_ALL = "report-all"; | ||
36 | + public static final String TEST_RUNNING = "running"; | ||
37 | + | ||
38 | + public static final String TEST_VOLT_NE_NAMESPACE = | ||
39 | + "xmlns=\"http://fujitsu.com/ns/volt/1.1\""; | ||
40 | + public static final String TEST_VOLT_NE = "volt-ne"; | ||
41 | + public static final String TEST_PONLINK_ID = "ponlink-id"; | ||
42 | + public static final String TEST_ONU_ID = "onu-id"; | ||
43 | + public static final String TEST_ROOT = "fakeroot"; | ||
44 | + | ||
45 | + public static final String TEST_VOLT_NE_OPEN = TEST_ANGLE_LEFT + TEST_VOLT_NE + TEST_SPACE; | ||
46 | + public static final String TEST_VOLT_NE_CLOSE = TEST_ANGLE_LEFT + TEST_SLASH + TEST_VOLT_NE + TEST_ANGLE_RIGHT; | ||
47 | + | ||
48 | + public static final String TEST_BASE_NAMESPACE = | ||
49 | + " xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"; | ||
50 | + | ||
51 | + public static final String TEST_DUPLICATE_SPACES_REGEX = " +"; | ||
52 | + public static final String TEST_WHITESPACES_REGEX = "\\s+"; | ||
53 | + public static final String TEST_EMPTY_STRING = ""; | ||
54 | + | ||
55 | + public static final String TEST_VOLT_NAMESPACE = TEST_VOLT_NE_OPEN + | ||
56 | + TEST_VOLT_NE_NAMESPACE; | ||
57 | + | ||
58 | + | ||
59 | + private FujitsuVoltXmlUtilityMock() { | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * Builds XML start tag with name provided. | ||
64 | + * | ||
65 | + * @param name tag name | ||
66 | + * @return string | ||
67 | + */ | ||
68 | + public static String startTag(String name) { | ||
69 | + return startTag(name, true); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Builds XML end tag with name provided. | ||
74 | + * | ||
75 | + * @param name tag name | ||
76 | + * @return string | ||
77 | + */ | ||
78 | + public static String endTag(String name) { | ||
79 | + return endTag(name, true); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * Builds XML empty tag with name provided. | ||
84 | + * | ||
85 | + * @param name tag name | ||
86 | + * @return string | ||
87 | + */ | ||
88 | + public static String emptyTag(String name) { | ||
89 | + return emptyTag(name, true); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Builds XML start tag with name provided. | ||
94 | + * | ||
95 | + * @param name tag name | ||
96 | + * @param addNewLine option to add new line character after tag | ||
97 | + * @return string | ||
98 | + */ | ||
99 | + public static String startTag(String name, boolean addNewLine) { | ||
100 | + if (addNewLine) { | ||
101 | + return (TEST_ANGLE_LEFT + name + TEST_ANGLE_RIGHT + TEST_NEW_LINE); | ||
102 | + } else { | ||
103 | + return (TEST_ANGLE_LEFT + name + TEST_ANGLE_RIGHT); | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Builds XML end tag with name provided. | ||
109 | + * | ||
110 | + * @param name tag name | ||
111 | + * @param addNewLine option to add new line character after tag | ||
112 | + * @return string | ||
113 | + */ | ||
114 | + public static String endTag(String name, boolean addNewLine) { | ||
115 | + if (addNewLine) { | ||
116 | + return (TEST_ANGLE_LEFT + TEST_SLASH + name + TEST_ANGLE_RIGHT + TEST_NEW_LINE); | ||
117 | + } else { | ||
118 | + return (TEST_ANGLE_LEFT + TEST_SLASH + name + TEST_ANGLE_RIGHT); | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Builds XML empty element tag with name provided. | ||
124 | + * | ||
125 | + * @param name tag name | ||
126 | + * @param addNewLine option to add new line character after tag | ||
127 | + * @return string | ||
128 | + */ | ||
129 | + public static String emptyTag(String name, boolean addNewLine) { | ||
130 | + if (addNewLine) { | ||
131 | + return (TEST_ANGLE_LEFT + name + TEST_SLASH + TEST_ANGLE_RIGHT + TEST_NEW_LINE); | ||
132 | + } else { | ||
133 | + return (TEST_ANGLE_LEFT + name + TEST_SLASH + TEST_ANGLE_RIGHT); | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | +} |
-
Please register or login to post a comment