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);
}
}
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);
}
}
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();
}
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);
}
}
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);
}
}
Aggregations