1 package org.opendaylight.netconf.sal.connect.netconf.schema;
3 import com.google.common.base.Optional;
4 import com.google.common.io.ByteStreams;
5 import com.google.common.util.concurrent.CheckedFuture;
6 import java.net.InetSocketAddress;
8 import java.util.Collections;
10 import org.hamcrest.CoreMatchers;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
15 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
16 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
20 public class YangLibrarySchemaYangSourceProviderTest {
22 private SourceIdentifier workingSid;
23 private YangLibrarySchemaYangSourceProvider yangLibrarySchemaYangSourceProvider;
26 public void setUp() throws Exception {
27 final URL url = getClass().getResource("/schemas/config-test-rpc.yang");
28 workingSid = RevisionSourceIdentifier.create("abc", Optional.<String>absent());
29 final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
30 final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
31 yangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
35 public void testGetSource() throws Exception {
36 CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
37 yangLibrarySchemaYangSourceProvider.getSource(workingSid);
38 final String x = new String(ByteStreams.toByteArray(source.checkedGet().openStream()));
39 Assert.assertThat(x, CoreMatchers.containsString("module config-test-rpc"));
42 @Test(expected = SchemaSourceException.class)
43 public void testGetSourceFailure() throws Exception {
44 final URL url = new URL("http://non-existing-entity.yang");
45 final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
46 final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
47 final YangLibrarySchemaYangSourceProvider failingYangLibrarySchemaYangSourceProvider =
48 new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
50 CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
51 failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
55 @Test(expected = IllegalArgumentException.class)
56 public void testGetSourceNotAvailable() throws Exception {
57 yangLibrarySchemaYangSourceProvider.getSource(RevisionSourceIdentifier.create("aaaaa", "0000-00-00"));