Fix of build breakage caused by changes in Yangtools
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / YangLibrarySchemaYangSourceProviderTest.java
1 package org.opendaylight.netconf.sal.connect.netconf.schema;
2
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;
7 import java.net.URL;
8 import java.util.Collections;
9 import java.util.Map;
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;
19
20 public class YangLibrarySchemaYangSourceProviderTest {
21
22     private SourceIdentifier workingSid;
23     private YangLibrarySchemaYangSourceProvider yangLibrarySchemaYangSourceProvider;
24
25     @Before
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);
32     }
33
34     @Test
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"));
40     }
41
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);
49
50         CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
51                 failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
52         source.checkedGet();
53     }
54
55     @Test(expected = IllegalArgumentException.class)
56     public void testGetSourceNotAvailable() throws Exception {
57         yangLibrarySchemaYangSourceProvider.getSource(RevisionSourceIdentifier.create("aaaaa", "0000-00-00"));
58     }
59 }