Search in sources :

Example 1 with SimpleNetconfClientSessionListener

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

the class NotificationTest method getNotificationSchemaTest.

@Test
public void getNotificationSchemaTest() 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 schemaResponse = sendRequesttoDevice(sessionListener, GET_SCHEMAS_REQUEST_XML);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        assertTrue(schema.getLength() > 0);
        boolean notificationSchemaContained = 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 ("lighty-test-notifications".equals(schemaName) && "yang:lighty:test:notifications".equals(schemaNameSpace)) {
                    notificationSchemaContained = true;
                }
            }
        }
        assertTrue(notificationSchemaContained);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleNetconfClientSessionListener

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

the class DeviceTest method deviceRpcTest.

@Test
public void deviceRpcTest() throws ExecutionException, InterruptedException, IOException, URISyntaxException, SAXException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage createTopoResponse = sendRequestToDevice(CREATE_TOPOLOGY_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(createTopoResponse, xmlFileToInputStream(CREATE_TOPOLOGY_RPC_RESPONSE_XML));
        final NetconfMessage addNodeResponse = sendRequestToDevice(ADD_NODE_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(addNodeResponse, xmlFileToInputStream(EXCEPTED_ADD_NODE_RESPONSE));
        final NetconfMessage deleteTopoResponse = sendRequestToDevice(DELETE_TOPOLOGY_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(deleteTopoResponse, xmlFileToInputStream(DELETE_TOPOLOGY_RPC_RESPONSE_XML));
    }
}
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 3 with SimpleNetconfClientSessionListener

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

the class ToasterDeviceTest method getSchemaTest.

@Test
public void getSchemaTest() 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 schemaResponse = sentRequestToDevice(GET_SCHEMAS_REQUEST_XML, sessionListener);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        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;
                }
            }
        }
        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) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleNetconfClientSessionListener

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

the class ToasterDeviceTest method toasterRpcsTest.

@Test
public void toasterRpcsTest() throws ExecutionException, InterruptedException, URISyntaxException, SAXException, TimeoutException, IOException {
    final SimpleNetconfClientSessionListener sessionListenerSimple = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession sessionSimple = dispatcher.createClient(createSHHConfig(sessionListenerSimple)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage createToasterResponse = sentRequestToDevice(CREATE_TOASTER_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(createToasterResponse));
        final NetconfMessage toasterData = sentRequestToDevice(GET_TOASTER_DATA_REQUEST_XML, sessionListenerSimple);
        final String toasterDarknessFactor = toasterData.getDocument().getDocumentElement().getElementsByTagName("darknessFactor").item(0).getTextContent();
        assertEquals(EXPECTED_DARKNESS_FACTOR, toasterDarknessFactor);
        final NetconfMessage makeToastResponse = sentRequestToDevice(MAKE_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(makeToastResponse));
        final NetconfMessage restockToastResponse = sentRequestToDevice(RESTOCK_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(restockToastResponse));
    }
}
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 5 with SimpleNetconfClientSessionListener

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

the class DeviceTest method toasterRPCsTest.

@Test
public void toasterRPCsTest() throws ExecutionException, InterruptedException, URISyntaxException, SAXException, TimeoutException, IOException {
    for (SimpleNetconfClientSessionListener listener : SESSION_LISTENERS) {
        final NetconfMessage makeToastResponse = sendRequestToDevice(MAKE_TOAST_REQUEST_XML, listener);
        Assertions.assertTrue(containsOkElement(makeToastResponse));
    }
}
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