use of org.opendaylight.netconf.api.NetconfMessage 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);
}
}
use of org.opendaylight.netconf.api.NetconfMessage in project lighty-netconf-simulator by PANTHEONtech.
the class NotificationTest method triggerNotificationRpcTest.
@Test
public void triggerNotificationRpcTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final NotificationNetconfSessionListener sessionListener = new NotificationNetconfSessionListener(countDownLatch, EXPECTED_NOTIFICATION_PAYLOAD);
try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
final NetconfMessage subscribeResponse = sendRequesttoDevice(sessionListener, SUBCRIBE_TO_NOTIFICATIONS_REQUEST_XML);
final boolean okPresent = subscribeResponse.getDocument().getDocumentElement().getElementsByTagName("ok").getLength() > 0;
assertTrue(okPresent);
final boolean msgIdMatches = subscribeResponse.getDocument().getDocumentElement().getAttribute("message-id").equals(SUBSCRIBE_MSG_TAG);
assertTrue(msgIdMatches);
sendRequesttoDevice(sessionListener, TRIGGER_DATA_NOTIFICATION_REQUEST_XML);
final boolean isNotificationPublished = countDownLatch.await(REQUEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
assertTrue(isNotificationPublished);
}
}
use of org.opendaylight.netconf.api.NetconfMessage 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));
}
}
use of org.opendaylight.netconf.api.NetconfMessage 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);
}
}
use of org.opendaylight.netconf.api.NetconfMessage 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));
}
}
Aggregations