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.junit.jupiter.api.Assertions.assertEquals;
12 import java.net.MalformedURLException;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
18 class LibraryModulesSchemasTest {
21 void testCreate() throws Exception {
22 // test create from xml
23 LibraryModulesSchemas libraryModulesSchemas =
24 LibraryModulesSchemas.create(getClass().getResource("/yang-library.xml").toString());
26 verifySchemas(libraryModulesSchemas);
28 // test create from json
29 LibraryModulesSchemas libraryModuleSchemas =
30 LibraryModulesSchemas.create(getClass().getResource("/yang-library.json").toString());
32 verifySchemas(libraryModuleSchemas);
35 private static void verifySchemas(final LibraryModulesSchemas libraryModulesSchemas) throws MalformedURLException {
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/")),
44 libraryModulesSchemas.getAvailableModels());
48 void testCreateInvalidModulesEntries() throws Exception {
49 LibraryModulesSchemas libraryModulesSchemas =
50 LibraryModulesSchemas.create(getClass().getResource("/yang-library-fail.xml").toString());
52 assertEquals(Map.of(new SourceIdentifier("good-ol-module"), new URL("http://www.example.com")),
53 libraryModulesSchemas.getAvailableModels());
57 void testCreateFromInvalidAll() {
58 // test bad yang lib url
59 LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create("ObviouslyBadUrl");
60 assertEquals(Map.of(), libraryModulesSchemas.getAvailableModels());
62 // TODO test also fail on json and xml parsing. But can we fail not on runtime exceptions?