Migrate netconf-client-mdsal tests to JUnit5
[netconf.git] / plugins / netconf-client-mdsal / src / test / java / org / opendaylight / netconf / client / mdsal / LibraryModulesSchemasTest.java
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.junit.jupiter.api.Assertions.assertEquals;
11
12 import java.net.MalformedURLException;
13 import java.net.URL;
14 import java.util.Map;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
17
18 class LibraryModulesSchemasTest {
19
20     @Test
21     void testCreate() throws Exception {
22         // test create from xml
23         LibraryModulesSchemas libraryModulesSchemas =
24                 LibraryModulesSchemas.create(getClass().getResource("/yang-library.xml").toString());
25
26         verifySchemas(libraryModulesSchemas);
27
28         // test create from json
29         LibraryModulesSchemas libraryModuleSchemas =
30                 LibraryModulesSchemas.create(getClass().getResource("/yang-library.json").toString());
31
32         verifySchemas(libraryModuleSchemas);
33     }
34
35     private static void verifySchemas(final LibraryModulesSchemas libraryModulesSchemas) throws MalformedURLException {
36         assertEquals(Map.of(
37             new SourceIdentifier("module-with-revision", "2014-04-08"),
38             new URL("http://localhost:8181/yanglib/schemas/module-with-revision/2014-04-08"),
39             new SourceIdentifier("another-module-with-revision", "2013-10-21"),
40             new URL("http://localhost:8181/yanglib/schemas/another-module-with-revision/2013-10-21"),
41             new SourceIdentifier("module-without-revision"),
42             new URL("http://localhost:8181/yanglib/schemas/module-without-revision/")),
43
44             libraryModulesSchemas.getAvailableModels());
45     }
46
47     @Test
48     void testCreateInvalidModulesEntries() throws Exception {
49         LibraryModulesSchemas libraryModulesSchemas =
50                 LibraryModulesSchemas.create(getClass().getResource("/yang-library-fail.xml").toString());
51
52         assertEquals(Map.of(new SourceIdentifier("good-ol-module"), new URL("http://www.example.com")),
53             libraryModulesSchemas.getAvailableModels());
54     }
55
56     @Test
57     void testCreateFromInvalidAll() {
58         // test bad yang lib url
59         LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create("ObviouslyBadUrl");
60         assertEquals(Map.of(), libraryModulesSchemas.getAvailableModels());
61
62         // TODO test also fail on json and xml parsing. But can we fail not on runtime exceptions?
63     }
64 }