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.client.mdsal;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.instanceOf;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertThrows;
15 import java.net.InetSocketAddress;
16 import java.net.MalformedURLException;
19 import java.util.concurrent.ExecutionException;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
23 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
24 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
26 public class LibrarySchemaYangSourceProviderTest {
27 private SourceIdentifier workingSid;
28 private LibrarySchemaSourceProvider yangLibrarySchemaYangSourceProvider;
31 public void setUp() throws Exception {
32 workingSid = new SourceIdentifier("abc");
33 yangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
34 new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)),
35 Map.of(workingSid, getClass().getResource("/schemas/config-test-rpc.yang")));
39 public void testGetSource() throws Exception {
40 var source = yangLibrarySchemaYangSourceProvider.getSource(workingSid);
41 final String x = source.get().read();
42 assertThat(x, containsString("module config-test-rpc"));
46 public void testGetSourceFailure() throws InterruptedException, MalformedURLException {
47 final var sourceIdentifierURLMap = Map.of(workingSid, new URL("http://non-existing-entity.yang"));
48 final var failingYangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
49 new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)), sourceIdentifierURLMap);
51 final var future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
52 final var ex = assertThrows(ExecutionException.class, () -> future.get());
53 assertThat(ex.getCause(), instanceOf(SchemaSourceException.class));
57 public void testGetSourceNotAvailable() {
58 assertThrows(IllegalArgumentException.class,
59 () -> yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa")));