X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fschema%2FYangLibrarySchemaYangSourceProviderTest.java;h=ef0ba925255d99f4d00b2938ff6cd98a157735e1;hb=refs%2Fchanges%2F30%2F101630%2F7;hp=15f0ab3c6c60030751a2f215dde6fc677db8e7f8;hpb=7213604d967f62f62fd7dd5d9301899a4bad38c1;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/YangLibrarySchemaYangSourceProviderTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/YangLibrarySchemaYangSourceProviderTest.java index 15f0ab3c6c..ef0ba92525 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/YangLibrarySchemaYangSourceProviderTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/YangLibrarySchemaYangSourceProviderTest.java @@ -1,14 +1,25 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.netconf.sal.connect.netconf.schema; -import com.google.common.base.Optional; -import com.google.common.io.ByteStreams; -import com.google.common.util.concurrent.CheckedFuture; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThrows; + +import com.google.common.util.concurrent.ListenableFuture; import java.net.InetSocketAddress; +import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Map; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; +import java.util.concurrent.ExecutionException; import org.junit.Before; import org.junit.Test; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; @@ -17,14 +28,13 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; public class YangLibrarySchemaYangSourceProviderTest { - private SourceIdentifier workingSid; private YangLibrarySchemaYangSourceProvider yangLibrarySchemaYangSourceProvider; @Before public void setUp() throws Exception { final URL url = getClass().getResource("/schemas/config-test-rpc.yang"); - workingSid = new SourceIdentifier("abc", Optional.absent()); + workingSid = new SourceIdentifier("abc"); final Map sourceIdentifierURLMap = Collections.singletonMap(workingSid, url); final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)); yangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap); @@ -32,27 +42,29 @@ public class YangLibrarySchemaYangSourceProviderTest { @Test public void testGetSource() throws Exception { - CheckedFuture source = - yangLibrarySchemaYangSourceProvider.getSource(workingSid); - final String x = new String(ByteStreams.toByteArray(source.checkedGet().openStream())); - Assert.assertThat(x, CoreMatchers.containsString("module config-test-rpc")); + ListenableFuture source = yangLibrarySchemaYangSourceProvider + .getSource(workingSid); + + final String x = source.get().asCharSource(StandardCharsets.UTF_8).read(); + assertThat(x, containsString("module config-test-rpc")); } - @Test(expected = SchemaSourceException.class) - public void testGetSourceFailure() throws Exception { + @Test + public void testGetSourceFailure() throws InterruptedException, MalformedURLException { final URL url = new URL("http://non-existing-entity.yang"); final Map sourceIdentifierURLMap = Collections.singletonMap(workingSid, url); final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)); final YangLibrarySchemaYangSourceProvider failingYangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap); - CheckedFuture source = - failingYangLibrarySchemaYangSourceProvider.getSource(workingSid); - source.checkedGet(); + final ListenableFuture future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid); + final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get()); + assertThat(ex.getCause(), instanceOf(SchemaSourceException.class)); } - @Test(expected = IllegalArgumentException.class) - public void testGetSourceNotAvailable() throws Exception { - yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa", "0000-00-00")); + @Test + public void testGetSourceNotAvailable() { + assertThrows(IllegalArgumentException.class, + () -> yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa"))); } -} \ No newline at end of file +}