import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
import org.opendaylight.controller.netconf.StubUserManager;
+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.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;
import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
import java.util.concurrent.TimeoutException;
import static java.util.Collections.emptyList;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
-import static org.mockito.Matchers.anyLong;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
}
static NetconfMonitoringServiceImpl getNetconfMonitoringListenerService() {
- NetconfOperationServiceFactoryListener factoriesListener = mock(NetconfOperationServiceFactoryListener.class);
- NetconfOperationServiceSnapshot snap = mock(NetconfOperationServiceSnapshot.class);
+ NetconfOperationProvider netconfOperationProvider = mock(NetconfOperationProvider.class);
+ NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class);
doReturn(Collections.<NetconfOperationService>emptySet()).when(snap).getServices();
- doReturn(snap).when(factoriesListener).getSnapshot(anyLong());
- return new NetconfMonitoringServiceImpl(factoriesListener);
+ doReturn(snap).when(netconfOperationProvider).openSnapshot(anyString());
+ return new NetconfMonitoringServiceImpl(netconfOperationProvider);
}
@After
}
static Collection<InputStream> getBasicYangs() throws IOException {
+
List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
"/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
"/META-INF/yang/ietf-inet-types.yang");
@Test
public void testNetconfClientDemonstration() throws Exception {
- try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
+ try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
Set<String> capabilitiesFromNetconfServer = netconfClient.getCapabilities();
long sessionId = netconfClient.getSessionId();
@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)) {
}
}
}
@Test
public void rpcReplyContainsAllAttributesTest() throws Exception {
- try (NetconfClient netconfClient = createSession(tcpAddress, "1")) {
+ try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) {
final String rpc = "<rpc message-id=\"5\" a=\"a\" b=\"44\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+ "<get/>" + "</rpc>";
final Document doc = XmlUtil.readXmlToDocument(rpc);
@Test
public void rpcReplyErrorContainsAllAttributesTest() throws Exception {
- try (NetconfClient netconfClient = createSession(tcpAddress, "1")) {
+ try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) {
final String rpc = "<rpc message-id=\"1\" a=\"adada\" b=\"4\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+ "<commit/>" + "</rpc>";
final Document doc = XmlUtil.readXmlToDocument(rpc);
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 = "<rpc message-id=\"5\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
}
}
- /*
- @Test
- public void testStartExi() throws Exception {
- try (NetconfClient netconfClient = createSession(tcpAddress, "1")) {
-
-
- Document rpcReply = netconfClient.sendMessage(this.startExi)
- .getDocument();
- assertIsOK(rpcReply);
-
- ExiParameters exiParams = new ExiParameters();
- exiParams.setParametersFromXmlElement(XmlElement.fromDomDocument(this.startExi.getDocument()));
-
- netconfClient.getClientSession().addExiDecoder(ExiDecoderHandler.HANDLER_NAME, new ExiDecoderHandler(exiParams));
- netconfClient.getClientSession().addExiEncoder(ExiEncoderHandler.HANDLER_NAME, new ExiEncoderHandler(exiParams));
-
- rpcReply = netconfClient.sendMessage(this.editConfig)
- .getDocument();
- assertIsOK(rpcReply);
-
- rpcReply = netconfClient.sendMessage(this.stopExi)
- .getDocument();
- assertIsOK(rpcReply);
-
- }
- }
- */
-
@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)
@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);
@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());
}
}
- private void assertIsOK(final Document rpcReply) {
+ private void assertIsOK(final Document rpcReply) throws NetconfDocumentedException {
assertEquals("rpc-reply", rpcReply.getDocumentElement().getLocalName());
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, NetconfDocumentedException {
return assertGetConfigWorks(netconfClient, this.getConfig);
}
- private Document assertGetConfigWorks(final NetconfClient netconfClient, final NetconfMessage getConfigMessage)
- throws InterruptedException, ExecutionException, TimeoutException {
+ private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage)
+ throws InterruptedException, ExecutionException, TimeoutException, NetconfDocumentedException {
final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage);
assertNotNull(rpcReply);
assertEquals("data", XmlElement.fromDomDocument(rpcReply.getDocument()).getOnlyChildElement().getName());
@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();
}
}
- 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;
}
}.join();
}
-
}