f8f855f997483555955ed943714a3af986df7959
[netconf.git] /
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.client.mdsal;
9
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;
14
15 import java.net.MalformedURLException;
16 import java.net.URL;
17 import java.util.Map;
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;
22
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")));
27
28     @Test
29     void testGetSource() throws Exception {
30         var source = yangLibrarySchemaYangSourceProvider.getSource(workingSid);
31         assertThat(source.get().read(), startsWith("module config-test-rpc"));
32     }
33
34     @Test
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);
39
40         final var future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
41         final var ex = assertThrows(ExecutionException.class, () -> future.get());
42         assertInstanceOf(SchemaSourceException.class, ex.getCause());
43     }
44
45     @Test
46     void testGetSourceNotAvailable() {
47         assertThrows(IllegalArgumentException.class,
48             () -> yangLibrarySchemaYangSourceProvider.getSource(new SourceIdentifier("aaaaa")));
49     }
50 }