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.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import static org.junit.jupiter.api.Assertions.assertThrows;
15 import java.net.InetSocketAddress;
16 import java.net.MalformedURLException;
19 import java.util.concurrent.ExecutionException;
20 import org.junit.jupiter.api.Test;
21 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
22 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
23 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
25 public class LibrarySchemaYangSourceProviderTest {
26 private final SourceIdentifier workingSid = new SourceIdentifier("abc");
27 private final LibrarySchemaSourceProvider yangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
28 new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)),
29 Map.of(workingSid, LibrarySchemaYangSourceProviderTest.class.getResource("/schemas/config-test-rpc.yang")));
32 void testGetSource() throws Exception {
33 var source = yangLibrarySchemaYangSourceProvider.getSource(workingSid);
34 assertThat(source.get().read(), startsWith("module config-test-rpc"));
38 void testGetSourceFailure() throws InterruptedException, MalformedURLException {
39 final var sourceIdentifierURLMap = Map.of(workingSid, new URL("http://non-existing-entity.yang"));
40 final var failingYangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
41 new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)), sourceIdentifierURLMap);
43 final var future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
44 final var ex = assertThrows(ExecutionException.class, () -> future.get());
45 assertInstanceOf(SchemaSourceException.class, ex.getCause());
49 void testGetSourceNotAvailable() {
50 assertThrows(IllegalArgumentException.class,
51 () -> yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa")));