+
+ @Ignore
+ @Test
+ public void testCreate2() throws Exception {
+ final ContainerNode netconfState = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfState.QNAME))
+ .withChild(compositeNodeSchemas)
+ .build();
+ final ContainerNode data = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier
+ .NodeIdentifier(NetconfMessageTransformUtil.NETCONF_DATA_QNAME))
+ .withChild(netconfState)
+ .build();
+ final ContainerNode rpcReply = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier
+ .NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME))
+ .withChild(data)
+ .build();
+ when(rpc.invokeRpc(eq(toPath(NETCONF_GET_QNAME)), any()))
+ .thenReturn(immediateFluentFuture(new DefaultDOMRpcResult(rpcReply)));
+ final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, CAPS, deviceId, schemaContext);
+ final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
+ assertEquals(numberOfLegalSchemas, availableYangSchemasQNames.size());
+
+ assertThat(availableYangSchemasQNames,
+ hasItem(QName.create("urn:TBD:params:xml:ns:yang:network-topology", "2013-07-12", "network-topology")));
+ }
+
+ @Test
+ public void testCreateMonitoringNotSupported() throws Exception {
+ final NetconfSessionPreferences caps = NetconfSessionPreferences.fromStrings(Collections.emptySet());
+ final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, caps, deviceId, schemaContext);
+ final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
+ Assert.assertTrue(availableYangSchemasQNames.isEmpty());
+ }
+
+ @Test
+ public void testCreateFail() throws Exception {
+ when(rpc.invokeRpc(eq(toPath(NETCONF_GET_QNAME)), any())).thenReturn(
+ immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException("not available")));
+ final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, CAPS, deviceId, schemaContext);
+ final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
+ Assert.assertTrue(availableYangSchemasQNames.isEmpty());
+ }
+
+ @Test
+ public void testCreateRpcError() throws Exception {
+ final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "fail", "fail");
+ when(rpc.invokeRpc(eq(toPath(NETCONF_GET_QNAME)), any()))
+ .thenReturn(immediateFluentFuture(new DefaultDOMRpcResult(rpcError)));
+ final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, CAPS, deviceId, schemaContext);
+ final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
+ Assert.assertTrue(availableYangSchemasQNames.isEmpty());
+ }
+
+ @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
+ @Test(expected = RuntimeException.class)
+ public void testCreateInterrupted() throws Throwable {
+ //NetconfStateSchemas.create calls Thread.currentThread().interrupt(), so it must run in its own thread
+ final Future<?> testFuture = Executors.newSingleThreadExecutor().submit(() -> {
+ final ListenableFuture<DOMRpcResult> interruptedFuture = mock(ListenableFuture.class);
+ try {
+ when(interruptedFuture.get()).thenThrow(new InterruptedException("interrupted"));
+ when(rpc.invokeRpc(eq(toPath(NETCONF_GET_QNAME)), any())).thenReturn(
+ FluentFuture.from(interruptedFuture));
+ NetconfStateSchemas.create(rpc, CAPS, deviceId, schemaContext);
+ } catch (final InterruptedException | ExecutionException e) {
+ LOG.info("Operation failed.", e);
+ }
+
+ });
+ try {
+ testFuture.get(3, TimeUnit.SECONDS);
+ } catch (final ExecutionException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Test
+ public void testRemoteYangSchemaEquals() throws Exception {
+ final NetconfStateSchemas.RemoteYangSchema schema1 =
+ new NetconfStateSchemas.RemoteYangSchema(NetconfState.QNAME);
+ final NetconfStateSchemas.RemoteYangSchema schema2 =
+ new NetconfStateSchemas.RemoteYangSchema(NetconfState.QNAME);
+ final NetconfStateSchemas.RemoteYangSchema schema3 =
+ new NetconfStateSchemas.RemoteYangSchema(Schemas.QNAME);
+ Assert.assertEquals(schema1, schema2);
+ Assert.assertEquals(schema2, schema1);
+ Assert.assertNotEquals(schema1, schema3);
+ Assert.assertNotEquals(schema2, schema3);
+
+ }