2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.connect.netconf.schema;
10 import com.google.common.base.Optional;
11 import com.google.common.io.ByteStreams;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import java.net.InetSocketAddress;
15 import java.util.Collections;
17 import org.hamcrest.CoreMatchers;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
22 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
23 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
24 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
25 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
27 public class YangLibrarySchemaYangSourceProviderTest {
29 private SourceIdentifier workingSid;
30 private YangLibrarySchemaYangSourceProvider yangLibrarySchemaYangSourceProvider;
33 public void setUp() throws Exception {
34 final URL url = getClass().getResource("/schemas/config-test-rpc.yang");
35 workingSid = RevisionSourceIdentifier.create("abc", Optional.<String>absent());
36 final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
37 final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
38 yangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
42 public void testGetSource() throws Exception {
43 CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
44 yangLibrarySchemaYangSourceProvider.getSource(workingSid);
45 final String x = new String(ByteStreams.toByteArray(source.checkedGet().openStream()));
46 Assert.assertThat(x, CoreMatchers.containsString("module config-test-rpc"));
49 @Test(expected = SchemaSourceException.class)
50 public void testGetSourceFailure() throws Exception {
51 final URL url = new URL("http://non-existing-entity.yang");
52 final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
53 final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
54 final YangLibrarySchemaYangSourceProvider failingYangLibrarySchemaYangSourceProvider =
55 new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
57 CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
58 failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
62 @Test(expected = IllegalArgumentException.class)
63 public void testGetSourceNotAvailable() throws Exception {
64 yangLibrarySchemaYangSourceProvider.getSource(RevisionSourceIdentifier.create("aaaaa"));