From: Maros Marsalek Date: Mon, 3 Mar 2014 12:35:48 +0000 (+0100) Subject: BUG-459 Remove deprecated NetconfClient class. X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~233^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=490e58f15373444b94642aebb2afbec9a62b9a57 BUG-459 Remove deprecated NetconfClient class. NetconfClient moved to test sources, now will be used only by tests. Change-Id: Ia98abe3f6fa4f05566b71d57c519c2149726bcb6 Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/netconf/netconf-client/pom.xml b/opendaylight/netconf/netconf-client/pom.xml index b0f5f74810..25ed0e7ab1 100644 --- a/opendaylight/netconf/netconf-client/pom.xml +++ b/opendaylight/netconf/netconf-client/pom.xml @@ -68,6 +68,19 @@ + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + package + + test-jar + + + + diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java deleted file mode 100644 index 6ae966d1f7..0000000000 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.client; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; - -/** - * Class extending {@link NetconfClientSessionListener} to provide notification capability. - */ -public abstract class AbstractNetconfClientNotifySessionListener extends SimpleNetconfClientSessionListener { - /* - * Maybe some capabilities could be expressed as internal NetconfClientSessionListener handlers. - * It would enable NetconfClient functionality to be extended by using namespace handlers. - * So far let just enable notification capability by extending and let parent class intact. - */ - - /** - * As class purpose is to provide notification capability to session listener - * onMessage method is not allowed to be further overridden. - * {@see #onNotification(NetconfClientSession, NetconfMessage)} - * - * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - */ - @Override - public final void onMessage(NetconfClientSession session, NetconfMessage message) { - if (isNotification(message)) { - onNotification(session, message); - } else { - super.onMessage(session, message); - } - } - - /** - * Method intended to customize notification processing. - * - * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - */ - public abstract void onNotification(NetconfClientSession session, NetconfMessage message); - - private boolean isNotification(NetconfMessage message) { - XmlElement xmle = XmlElement.fromDomDocument(message.getDocument()); - return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName()) ; - } -} diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java deleted file mode 100644 index 4cdca208bc..0000000000 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.client; - -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GlobalEventExecutor; - -import java.io.Closeable; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Set; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.TimedReconnectStrategy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Preconditions; -import com.google.common.base.Stopwatch; -import com.google.common.collect.Sets; - -/** - * @deprecated Use {@link NetconfClientDispatcher.createClient()} or {@link NetconfClientDispatcher.createReconnectingClient()} instead. - */ -@Deprecated -public class NetconfClient implements Closeable { - - private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class); - - public static final int DEFAULT_CONNECT_TIMEOUT = 5000; - private final NetconfClientDispatcher dispatch; - private final String label; - private final NetconfClientSession clientSession; - private final NetconfClientSessionListener sessionListener; - private final long sessionId; - private final InetSocketAddress address; - - // TODO test reconnecting constructor - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectionAttempts, - int attemptMsTimeout, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout), - netconfClientDispatcher); - } - - private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this.label = clientLabelForLogging; - dispatch = netconfClientDispatcher; - sessionListener = new SimpleNetconfClientSessionListener(); - Future clientFuture = dispatch.createClient(address, sessionListener, strat); - this.address = address; - clientSession = get(clientFuture); - this.sessionId = clientSession.getSessionId(); - } - - private NetconfClientSession get(Future clientFuture) throws InterruptedException { - try { - return clientFuture.get(); - } catch (CancellationException e) { - throw new RuntimeException("Cancelling " + this, e); - } catch (ExecutionException e) { - throw new IllegalStateException("Unable to create " + this, e); - } - } - - public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher); - } - - public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, - ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException { - return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher,listener); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs, - NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), netconfClientDispatcher); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, - NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, - DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, - NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException{ - this.label = clientLabelForLogging; - dispatch = netconfClientDispatcher; - sessionListener = listener; - Future clientFuture = dispatch.createClient(address, sessionListener, strategy); - this.address = address; - clientSession = get(clientFuture); - this.sessionId = clientSession.getSessionId(); - } - - public Future sendRequest(NetconfMessage message) { - return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message); - } - - /** - * @deprecated Use {@link sendRequest} instead - */ - @Deprecated - public NetconfMessage sendMessage(NetconfMessage message) throws ExecutionException, InterruptedException, TimeoutException { - return sendMessage(message, 5, 1000); - } - - /** - * @deprecated Use {@link sendRequest} instead - */ - @Deprecated - public NetconfMessage sendMessage(NetconfMessage message, int attempts, int attemptMsDelay) throws ExecutionException, InterruptedException, TimeoutException { - //logger.debug("Sending message: {}",XmlUtil.toString(message.getDocument())); - final Stopwatch stopwatch = new Stopwatch().start(); - - try { - return sendRequest(message).get(attempts * attemptMsDelay, TimeUnit.MILLISECONDS); - } finally { - stopwatch.stop(); - logger.debug("Total time spent waiting for response from {}: {} ms", address, stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } - - @Override - public void close() throws IOException { - clientSession.close(); - } - - public NetconfClientDispatcher getNetconfClientDispatcher() { - return dispatch; - } - - private static ReconnectStrategy getReconnectStrategy(int connectionAttempts, int attemptMsTimeout) { - return new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, attemptMsTimeout, 1000, 1.0, null, - Long.valueOf(connectionAttempts), null); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("NetconfClient{"); - sb.append("label=").append(label); - sb.append(", sessionId=").append(sessionId); - sb.append('}'); - return sb.toString(); - } - - public long getSessionId() { - return sessionId; - } - - public Set getCapabilities() { - Preconditions.checkState(clientSession != null, "Client was not initialized successfully"); - return Sets.newHashSet(clientSession.getServerCapabilities()); - } - - public NetconfClientSession getClientSession() { - return clientSession; - } -} diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java index bb372b3aff..cff214401c 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java @@ -58,8 +58,9 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF if(this.additionalHeader.isPresent()) { helloMessage = new NetconfHelloMessage(helloMessage.getDocument(), additionalHeader.get()); - } else + } else { helloMessage = new NetconfHelloMessage(helloMessage.getDocument()); + } NetconfSessionPreferences proposal = new NetconfSessionPreferences(helloMessage); return new NetconfClientSessionNegotiator(proposal, promise, channel, timer, diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java index e96161c29a..504e4c9949 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java @@ -101,7 +101,7 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL } } - final synchronized Future sendRequest(NetconfMessage message) { + public final synchronized Future sendRequest(NetconfMessage message) { final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.newPromise(), message); requests.add(req); diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java deleted file mode 100644 index 1357201f57..0000000000 --- a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.client; - -import io.netty.channel.nio.NioEventLoopGroup; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -@Ignore -public class SSHNetconfClientLiveTest { - private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class); - - NioEventLoopGroup nettyThreadgroup; - NetconfSshClientDispatcher netconfClientDispatcher; - InetSocketAddress address; - final int connectionAttempts = 10, attemptMsTimeout = 1000; - final int connectionTimeoutMillis = 20000; - - @Before - public void setUp() { - nettyThreadgroup = new NioEventLoopGroup(); - - netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword( - System.getProperty("username"), System.getProperty("password")), - nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis); - - address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port"))); - } - - @Ignore - @Test - public void test() throws Exception { - //runnable.run(); - } - - @Test - public void testInExecutor() throws Exception { - int threads = 4; - ExecutorService executorService = Executors.newFixedThreadPool(threads); - try { - for (int i= 0;i< threads;i++) { - InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), - Integer.parseInt(System.getProperty("port"))); - NetconfRunnable runnable = new NetconfRunnable(address); - executorService.execute(runnable); - } - executorService.shutdown(); - executorService.awaitTermination(1, TimeUnit.MINUTES); - - - } finally { - executorService.shutdownNow(); - } - } - - class NetconfRunnable implements Runnable { - private final InetSocketAddress address; - - NetconfRunnable(InetSocketAddress address) { - this.address = address; - } - - @Override - public void run() { - try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts, - attemptMsTimeout, netconfClientDispatcher);) { - logger.info("OK {}", address); - } catch (InterruptedException | IOException e) { - logger.error("Failed {}", address, e); - } - } - }; -} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java new file mode 100644 index 0000000000..32c6ea85d6 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.client.test; + +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GlobalEventExecutor; + +import java.io.Closeable; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Set; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.NetconfClientSession; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategy; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; + + +/** + * Synchronous netconf client suitable for testing + */ +public class TestingNetconfClient implements Closeable { + + public static final int DEFAULT_CONNECT_TIMEOUT = 5000; + + private final String label; + private final NetconfClientSession clientSession; + private final NetconfClientSessionListener sessionListener; + private final long sessionId; + + private TestingNetconfClient(String clientLabel, InetSocketAddress address, ReconnectStrategy strat, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this.label = clientLabel; + sessionListener = new SimpleNetconfClientSessionListener(); + Future clientFuture = netconfClientDispatcher.createClient(address, sessionListener, strat); + clientSession = get(clientFuture); + this.sessionId = clientSession.getSessionId(); + } + + private NetconfClientSession get(Future clientFuture) throws InterruptedException { + try { + return clientFuture.get(); + } catch (CancellationException e) { + throw new RuntimeException("Cancelling " + this, e); + } catch (ExecutionException e) { + throw new IllegalStateException("Unable to create " + this, e); + } + } + + public TestingNetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this(clientLabelForLogging, address, + new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), netconfClientDispatcher); + } + + public TestingNetconfClient(String clientLabelForLogging, InetSocketAddress address, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, + DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher); + } + + public Future sendRequest(NetconfMessage message) { + return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message); + } + + public NetconfMessage sendMessage(NetconfMessage message, int attemptMsDelay) throws ExecutionException, + InterruptedException, TimeoutException { + return sendRequest(message).get(attemptMsDelay, TimeUnit.MILLISECONDS); + } + + public NetconfMessage sendMessage(NetconfMessage message) throws ExecutionException, + InterruptedException, TimeoutException { + return sendMessage(message, DEFAULT_CONNECT_TIMEOUT); + } + + @Override + public void close() throws IOException { + clientSession.close(); + } + + @Override + public String toString() { + final StringBuffer sb = new StringBuffer("TestingNetconfClient{"); + sb.append("label=").append(label); + sb.append(", sessionId=").append(sessionId); + sb.append('}'); + return sb.toString(); + } + + public long getSessionId() { + return sessionId; + } + + public Set getCapabilities() { + Preconditions.checkState(clientSession != null, "Client was not initialized successfully"); + return Sets.newHashSet(clientSession.getServerCapabilities()); + } +} \ No newline at end of file diff --git a/opendaylight/netconf/netconf-impl/pom.xml b/opendaylight/netconf/netconf-impl/pom.xml index 76a0bd9908..b8b3028708 100644 --- a/opendaylight/netconf/netconf-impl/pom.xml +++ b/opendaylight/netconf/netconf-impl/pom.xml @@ -88,6 +88,13 @@ netconf-client test + + ${project.groupId} + netconf-client + ${project.version} + test-jar + test + org.opendaylight.controller commons.logback_settings diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index c1a7b1478b..82e8caef3a 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClient; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; @@ -259,13 +259,13 @@ public class ConcurrentClientsTest { @Override public void run() { try { - final NetconfClient netconfClient = new NetconfClient(clientId, netconfAddress, netconfClientDispatcher); + final TestingNetconfClient netconfClient = new TestingNetconfClient(clientId, netconfAddress, netconfClientDispatcher); long sessionId = netconfClient.getSessionId(); logger.info("Client with sessionid {} hello exchanged", sessionId); final NetconfMessage getMessage = XmlFileLoader .xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - NetconfMessage result = netconfClient.sendMessage(getMessage); + NetconfMessage result = netconfClient.sendRequest(getMessage).get(); logger.info("Client with sessionid {} got result {}", sessionId, result); netconfClient.close(); logger.info("Client with session id {} ended", sessionId); diff --git a/opendaylight/netconf/netconf-it/pom.xml b/opendaylight/netconf/netconf-it/pom.xml index aab939e8d9..68fd34e135 100644 --- a/opendaylight/netconf/netconf-it/pom.xml +++ b/opendaylight/netconf/netconf-it/pom.xml @@ -1,6 +1,9 @@ 4.0.0 + + 2.0.0 + netconf-subsystem @@ -33,11 +36,23 @@ netconf-client test + + ${project.groupId} + netconf-client + ${project.version} + test-jar + test + ${project.groupId} config-netconf-connector test + + ${project.groupId} + netty-config-api + test + ${project.groupId} config-manager @@ -114,6 +129,12 @@ org.opendaylight.controller commons.logback_settings + + org.ops4j.pax.tinybundles + tinybundles + ${tinybundles.version} + test + diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java index 997cae0f7c..78933e4b0b 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java @@ -25,8 +25,8 @@ import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.client.NetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; @@ -121,12 +121,12 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { VerifyingNotificationListener notificationVerifier = createCommitNotificationListener(); VerifyingPersister mockedAggregator = mockAggregator(); - try (NetconfClient persisterClient = new NetconfClient("persister", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient persisterClient = new TestingNetconfClient("persister", tcpAddress, 4000, clientDispatcher)) { try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler( platformMBeanServer, mockedAggregator)) { - try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, 4000, clientDispatcher)) { NetconfMessage response = netconfClient.sendMessage(loadGetConfigMessage()); assertResponse(response, " capabilitiesFromNetconfServer = netconfClient.getCapabilities(); long sessionId = netconfClient.getSessionId(); @@ -191,8 +191,8 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testTwoSessions() throws Exception { - try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 10000, clientDispatcher)) { - try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 10000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("1", tcpAddress, 10000, clientDispatcher)) { + try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("2", tcpAddress, 10000, clientDispatcher)) { } } } @@ -208,7 +208,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void rpcReplyContainsAllAttributesTest() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String rpc = "" + "" + ""; final Document doc = XmlUtil.readXmlToDocument(rpc); @@ -236,7 +236,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void rpcReplyErrorContainsAllAttributesTest() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String rpc = "" + "" + ""; final Document doc = XmlUtil.readXmlToDocument(rpc); @@ -260,7 +260,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { transaction.commit(); - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String expectedNamespace = "urn:opendaylight:params:xml:ns:yang:controller:test:impl"; final String rpc = "" @@ -284,7 +284,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { /* @Test public void testStartExi() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { Document rpcReply = netconfClient.sendMessage(this.startExi) @@ -311,7 +311,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testCloseSession() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // edit config Document rpcReply = netconfClient.sendMessage(this.editConfig) @@ -327,7 +327,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testEditConfig() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // send edit_config.xml final Document rpcReply = netconfClient.sendMessage(this.editConfig).getDocument(); assertIsOK(rpcReply); @@ -336,7 +336,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testValidate() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // begin transaction Document rpcReply = netconfClient.sendMessage(getConfigCandidate).getDocument(); assertEquals("data", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); @@ -353,11 +353,11 @@ public class NetconfITTest extends AbstractNetconfConfigTest { assertEquals("ok", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); } - private Document assertGetConfigWorks(final NetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException { + private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException { return assertGetConfigWorks(netconfClient, this.getConfig); } - private Document assertGetConfigWorks(final NetconfClient netconfClient, final NetconfMessage getConfigMessage) + private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage) throws InterruptedException, ExecutionException, TimeoutException { final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage); assertNotNull(rpcReply); @@ -367,14 +367,14 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testGetConfig() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { assertGetConfigWorks(netconfClient); } } @Test public void createYangTestBasedOnYuma() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { Document rpcReply = netconfClient.sendMessage( XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_yang-test.xml")) .getDocument(); @@ -392,8 +392,8 @@ public class NetconfITTest extends AbstractNetconfConfigTest { } } - private NetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { - final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, clientDispatcher); + private TestingNetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { + final TestingNetconfClient netconfClient = new TestingNetconfClient("test " + address.toString(), address, 5000, clientDispatcher); assertEquals(expected, Long.toString(netconfClient.getSessionId())); return netconfClient; } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java index 4af66532a1..01b66ab0cf 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java @@ -33,7 +33,7 @@ import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.client.NetconfClient; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; @@ -120,8 +120,8 @@ public class NetconfMonitoringITTest extends AbstractNetconfConfigTest { @Test public void testGetResponseFromMonitoring() throws Exception { - try (NetconfClient netconfClient = new NetconfClient("client-monitoring", tcpAddress, 4000, clientDispatcher)) { - try (NetconfClient netconfClient2 = new NetconfClient("client-monitoring2", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client-monitoring", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("client-monitoring2", tcpAddress, 4000, clientDispatcher)) { NetconfMessage response = netconfClient.sendMessage(loadGetMessage()); assertSessionElementsInResponse(response.getDocument(), 2); } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java index c75adbba8d..18275ad78b 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java @@ -7,6 +7,22 @@ */ package org.opendaylight.controller.netconf.it.pax; +import static org.junit.Assert.fail; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.streamBundle; +import static org.ops4j.pax.exam.CoreOptions.systemPackages; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +import javax.inject.Inject; +import javax.xml.parsers.ParserConfigurationException; + import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import io.netty.channel.nio.NioEventLoopGroup; @@ -16,8 +32,9 @@ import org.junit.Test; import org.junit.matchers.JUnitMatchers; import org.junit.runner.RunWith; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.ops4j.pax.exam.Configuration; @@ -25,29 +42,15 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.options.DefaultCompositeOption; import org.ops4j.pax.exam.util.Filter; -import org.w3c.dom.Document; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Constants; import org.xml.sax.SAXException; -import javax.inject.Inject; -import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; -import java.io.InputStream; import java.net.InetSocketAddress; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.fail; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.options; -import static org.ops4j.pax.exam.CoreOptions.systemPackages; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; - @Ignore @RunWith(PaxExam.class) public class IdentityRefNetconfTest { @@ -71,7 +74,24 @@ public class IdentityRefNetconfTest { loggingModules(), mdSalCoreBundles(), bindingAwareSalBundles(), configMinumumBundles(), baseModelBundles(), flowCapableModelBundles(), - junitAndMockitoBundles()); + junitAndMockitoBundles(), + + // Classes from test-jars bundled for pax-exam test + streamBundle(TinyBundles.bundle() + .add(TestingNetconfClient.class) + .add(XmlFileLoader.class) + + .add("/netconfMessages/editConfig_identities.xml", + XmlFileLoader.class.getResource("/netconfMessages/editConfig_identities.xml")) + .add("/netconfMessages/commit.xml", + XmlFileLoader.class.getResource("/netconfMessages/commit.xml")) + .add("/netconfMessages/getConfig.xml", + XmlFileLoader.class.getResource("/netconfMessages/getConfig.xml")) + + .set(Constants.BUNDLE_SYMBOLICNAME, "TestingClient_bundle") + .set(Constants.EXPORT_PACKAGE, "org.opendaylight.controller.netconf.client.test, " + + "org.opendaylight.controller.netconf.util.test") + .build(TinyBundles.withBnd()))); } private Option loggingModules() { @@ -89,29 +109,26 @@ public class IdentityRefNetconfTest { private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 18383); - @Test public void testIdRef() throws Exception { - try { - Preconditions.checkNotNull(broker, "Controller not initialized"); - - NioEventLoopGroup nettyThreadgroup = new NioEventLoopGroup(); - NetconfClientDispatcher clientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, - CLIENT_CONNECTION_TIMEOUT_MILLIS); - - NetconfMessage edit = xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml"); - NetconfMessage commit = xmlFileToNetconfMessage("netconfMessages/commit.xml"); - NetconfMessage getConfig = xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - - try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, CLIENT_CONNECTION_TIMEOUT_MILLIS, clientDispatcher)) { - sendMessage(edit, netconfClient); - sendMessage(commit, netconfClient); - sendMessage(getConfig, netconfClient, "id-test", - "prefix:test-identity1", - "prefix:test-identity2", - "prefix:test-identity2", - "prefix:test-identity1"); - } + Preconditions.checkNotNull(broker, "Controller not initialized"); + + NioEventLoopGroup nettyThreadgroup = new NioEventLoopGroup(); + NetconfClientDispatcher clientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, + CLIENT_CONNECTION_TIMEOUT_MILLIS); + + NetconfMessage edit = xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml"); + NetconfMessage commit = xmlFileToNetconfMessage("netconfMessages/commit.xml"); + NetconfMessage getConfig = xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); + + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, CLIENT_CONNECTION_TIMEOUT_MILLIS, clientDispatcher)) { + sendMessage(edit, netconfClient); + sendMessage(commit, netconfClient); + sendMessage(getConfig, netconfClient, "id-test", + "prefix:test-identity1", + "prefix:test-identity2", + "prefix:test-identity2", + "prefix:test-identity1"); clientDispatcher.close(); } catch (Exception e) { @@ -119,8 +136,7 @@ public class IdentityRefNetconfTest { } } - - private void sendMessage(NetconfMessage edit, NetconfClient netconfClient, String... containingResponse) + private void sendMessage(NetconfMessage edit, TestingNetconfClient netconfClient, String... containingResponse) throws ExecutionException, InterruptedException, TimeoutException { NetconfMessage response = netconfClient.sendRequest(edit).get(); if (containingResponse == null) { @@ -134,16 +150,6 @@ public class IdentityRefNetconfTest { public static NetconfMessage xmlFileToNetconfMessage(final String fileName) throws IOException, SAXException, ParserConfigurationException { - return new NetconfMessage(xmlFileToDocument(fileName)); - } - - public static Document xmlFileToDocument(final String fileName) throws IOException, SAXException, - ParserConfigurationException { - // TODO xml messages from netconf-util test-jar cannot be loaded here(in OSGi), since test jar is not a bundle - try (InputStream resourceAsStream = IdentityRefNetconfTest.class.getClassLoader().getResourceAsStream(fileName)) { - Preconditions.checkNotNull(resourceAsStream); - final Document doc = XmlUtil.readXmlToDocument(resourceAsStream); - return doc; - } + return XmlFileLoader.xmlFileToNetconfMessage(fileName); } }