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.MalformedURLException;
18 import java.util.concurrent.ExecutionException;
19 import org.junit.jupiter.api.Test;
20 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
23 public class LibrarySchemaYangSourceProviderTest {
24 private final SourceIdentifier workingSid = new SourceIdentifier("abc");
25 private final LibrarySchemaSourceProvider yangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
26 Map.of(workingSid, LibrarySchemaYangSourceProviderTest.class.getResource("/schemas/config-test-rpc.yang")));
29 void testGetSource() throws Exception {
30 var source = yangLibrarySchemaYangSourceProvider.getSource(workingSid);
31 assertThat(source.get().read(), startsWith("module config-test-rpc"));
35 void testGetSourceFailure() throws InterruptedException, MalformedURLException {
36 final var sourceIdentifierURLMap = Map.of(workingSid, new URL("http://non-existing-entity.yang"));
37 final var failingYangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
38 sourceIdentifierURLMap);
40 final var future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
41 final var ex = assertThrows(ExecutionException.class, () -> future.get());
42 assertInstanceOf(SchemaSourceException.class, ex.getCause());
46 void testGetSourceNotAvailable() {
47 assertThrows(IllegalArgumentException.class,
48 () -> yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa")));