Search in sources :

Example 6 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener in project lighty-netconf-simulator by PANTHEONtech.

the class DeviceTest method getSchemaTest.

@Test
public void getSchemaTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    for (SimpleNetconfClientSessionListener listener : SESSION_LISTENERS) {
        final NetconfMessage schemaResponse = sendRequestToDevice(GET_SCHEMAS_REQUEST_XML, listener);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        Assertions.assertTrue(schema.getLength() > 0);
        boolean toasterSchemaContained = false;
        for (int i = 0; i < schema.getLength(); i++) {
            if (schema.item(i).getNodeType() == Node.ELEMENT_NODE) {
                final Element item = (Element) schema.item(i);
                final String schemaName = item.getElementsByTagName("identifier").item(0).getTextContent();
                final String schemaNameSpace = item.getElementsByTagName("namespace").item(0).getTextContent();
                if ("toaster".equals(schemaName) && "http://netconfcentral.org/ns/toaster".equals(schemaNameSpace)) {
                    toasterSchemaContained = true;
                }
            }
        }
        Assertions.assertTrue(toasterSchemaContained);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Test(org.junit.jupiter.api.Test)

Example 7 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener in project lighty-netconf-simulator by PANTHEONtech.

the class ActionDeviceTest method actionsTest.

@Test
public void actionsTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage startActionResponse = sentRequesttoDevice(sessionListener, START_ACTION_REQUEST_XML);
        final String startResultTag = startActionResponse.getDocument().getDocumentElement().getElementsByTagName(START_TAG).item(0).getTextContent();
        assertEquals(startResultTag, START_ACTION_EXPECTED_VALUE);
        final NetconfMessage resetActionResponse = sentRequesttoDevice(sessionListener, RESET_ACTION_REQUEST_XML);
        final String resetResultTag = resetActionResponse.getDocument().getDocumentElement().getElementsByTagName(RESET_TAG).item(0).getTextContent();
        assertEquals(resetResultTag, RESET_ACTION_EXPECTED_VALUE);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 8 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener in project netconf by opendaylight.

the class TestToolTest method invokeRpc.

private Document invokeRpc(final Configuration simulatorConfig, final String xmlRequest) throws Exception {
    // GIVEN
    int localPort = launchSimulator(simulatorConfig);
    SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    NetconfClientConfiguration clientConfig = getClientConfig("localhost", localPort, simulatorConfig, sessionListener);
    Document docRequest = XmlUtil.readXmlToDocument(xmlRequest);
    NetconfMessage request = new NetconfMessage(docRequest);
    // WHEN
    NetconfMessage response;
    try (NetconfClientSession ignored = dispatcher.createClient(clientConfig).get()) {
        response = sessionListener.sendRequest(request).get(RECEIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    }
    // THEN
    assertNotNull(response);
    return response.getDocument();
}
Also used : NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) Document(org.w3c.dom.Document) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession)

Example 9 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener in project lighty-netconf-simulator by PANTHEONtech.

the class ToasterDeviceTest method toasterNotificationTest.

@Test
public void toasterNotificationTest() throws ExecutionException, InterruptedException, URISyntaxException, SAXException, TimeoutException, IOException {
    final CountDownLatch notificationReceivedLatch = new CountDownLatch(1);
    final NotificationNetconfSessionListener sessionListenerNotification = new NotificationNetconfSessionListener(notificationReceivedLatch);
    final SimpleNetconfClientSessionListener sessionListenerSimple = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession sessionNotification = dispatcher.createClient(createSHHConfig(sessionListenerNotification)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        NetconfClientSession sessionSimple = dispatcher.createClient(createSHHConfig(sessionListenerSimple)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage subscribeResponse = sentRequestToDevice(SUBSCRIBE_TO_NOTIFICATIONS_REQUEST_XML, sessionListenerNotification);
        assertTrue(containsOkElement(subscribeResponse));
        final NetconfMessage restockToastResponse = sentRequestToDevice(RESTOCK_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(restockToastResponse));
        final boolean await = notificationReceivedLatch.await(REQUEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        assertTrue(await);
        NetconfMessage restockToastNotification = sessionListenerNotification.getReceivedNotificationMessage();
        assertNotNull(restockToastNotification);
        assertTrue(containsNotificationElement(restockToastNotification));
        final String amountOfBreadExpected = XmlUtil.readXmlToDocument(xmlFileToInputStream(RESTOCK_TOAST_REQUEST_XML)).getElementsByTagName("amountOfBreadToStock").item(0).getTextContent();
        final String amountOfBread = restockToastNotification.getDocument().getElementsByTagName("amountOfBread").item(0).getTextContent();
        assertEquals(amountOfBreadExpected, amountOfBread);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) CountDownLatch(java.util.concurrent.CountDownLatch) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 10 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener in project lighty-netconf-simulator by PANTHEONtech.

the class DeviceTest method sharedDatastoreTest.

@Test
public void sharedDatastoreTest() throws InterruptedException, ExecutionException, TimeoutException, SAXException, IOException, URISyntaxException {
    final SimpleNetconfClientSessionListener sessionListener = SESSION_LISTENERS.get(0);
    final NetconfMessage createToasterResponse = sendRequestToDevice(CREATE_TOASTER_REQUEST_XML, sessionListener);
    assertTrue(containsOkElement(createToasterResponse));
    for (SimpleNetconfClientSessionListener listener : SESSION_LISTENERS) {
        final NetconfMessage toasterData = sendRequestToDevice(GET_TOASTER_DATA_REQUEST_XML, listener);
        final String toasterDarknessFactor = toasterData.getDocument().getDocumentElement().getElementsByTagName("darknessFactor").item(0).getTextContent();
        Assertions.assertEquals(EXPECTED_DARKNESS_FACTOR, toasterDarknessFactor);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)14 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)13 Test (org.junit.jupiter.api.Test)12 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)11 NodeList (org.w3c.dom.NodeList)6 Element (org.w3c.dom.Element)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)1 Document (org.w3c.dom.Document)1