summaryrefslogtreecommitdiffstats
path: root/it/api-test
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-03-27 14:11:08 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-03-28 08:36:01 +0000
commit539dafd91d6c58400ff2623d85df28f40a11ffe5 (patch)
tree7c814f59e7d55e0486da1dd6ec4bfc22e1b89ac9 /it/api-test
parenta9d4e3929a09b8c44b5a371845d4db123aa876e0 (diff)
HONEYCOMB-298 - LeafRefContext creation test
Verifies if all models in hc2vpp are compatible with LeafRefContext(runtime check of leaf-ref references) Change-Id: Id589fb3dc167cd147c439a2598a9818c0f596c3b Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'it/api-test')
-rw-r--r--it/api-test/asciidoc/Readme.adoc21
-rw-r--r--it/api-test/pom.xml114
-rw-r--r--it/api-test/src/test/java/io/fd/hc2vpp/model/test/LeafRefContextTest.java101
3 files changed, 236 insertions, 0 deletions
diff --git a/it/api-test/asciidoc/Readme.adoc b/it/api-test/asciidoc/Readme.adoc
new file mode 100644
index 000000000..47756c379
--- /dev/null
+++ b/it/api-test/asciidoc/Readme.adoc
@@ -0,0 +1,21 @@
+= api-test
+
+Overview of api-test
+
+== LeafRefContextTest
+
+Provides test whether LeafRefContext is constructable from standard
+set of modules consisting of following modules models
+
+* v3po
+* lisp
+* routing
+* dhcp
+* nat
+* acl
+* nsh
+* iaom
+* l3
+* management
+* vpp-classifier
+
diff --git a/it/api-test/pom.xml b/it/api-test/pom.xml
new file mode 100644
index 000000000..b26c22f7d
--- /dev/null
+++ b/it/api-test/pom.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2017 Cisco and/or its affiliates.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at:
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>io.fd.hc2vpp.common</groupId>
+ <artifactId>hc2vpp-parent</artifactId>
+ <version>1.17.04-SNAPSHOT</version>
+ <relativePath>../../common/hc2vpp-parent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>api-test</artifactId>
+ <version>1.17.04-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.fd.hc2vpp.v3po</groupId>
+ <artifactId>v3po-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.lisp</groupId>
+ <artifactId>lisp-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.acl</groupId>
+ <artifactId>acl-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.routing</groupId>
+ <artifactId>routing-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.nat</groupId>
+ <artifactId>nat-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.dhcp</groupId>
+ <artifactId>dhcp-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.vpp.classifier</groupId>
+ <artifactId>vpp-classifier-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.management</groupId>
+ <artifactId>vpp-management-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.l3</groupId>
+ <artifactId>l3-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Open source plugins -->
+ <dependency>
+ <groupId>io.fd.hc2vpp.nsh</groupId>
+ <artifactId>vppnsh-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.hc2vpp.ioam</groupId>
+ <artifactId>vppioam-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding-generator-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/it/api-test/src/test/java/io/fd/hc2vpp/model/test/LeafRefContextTest.java b/it/api-test/src/test/java/io/fd/hc2vpp/model/test/LeafRefContextTest.java
new file mode 100644
index 000000000..8a49673c6
--- /dev/null
+++ b/it/api-test/src/test/java/io/fd/hc2vpp/model/test/LeafRefContextTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.model.test;
+
+import static com.google.common.base.Preconditions.checkState;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Strings;
+import com.google.common.io.Resources;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
+import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
+import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+/**
+ * Tests whether LeafRefContext in is constructable from standard set of models
+ */
+public class LeafRefContextTest {
+
+ private static final String YANG_BA_PROVIDER_PATH = "META-INF/services/" + YangModelBindingProvider.class.getName();
+
+ @Test
+ public void testLeafRefContextCreation() {
+ assertNotNull(LeafRefContext.create(context()));
+ }
+
+ private SchemaContext context() {
+
+ ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
+ final Set<YangModuleInfo> modules = modules();
+ checkState(!modules.isEmpty(), "No modules found");
+ ctx.addModuleInfos(modules);
+
+ return ctx.getSchemaContext();
+ }
+
+ private Set<YangModuleInfo> modules() {
+ try {
+ return Collections.list(getClass().getClassLoader().getResources(YANG_BA_PROVIDER_PATH))
+ .stream()
+ .map(LeafRefContextTest::urlToString)
+ .flatMap(content -> Arrays.stream(content.split("\n")))
+ .filter(line -> !Strings.isNullOrEmpty(line.trim()))
+ .map(LeafRefContextTest::loadClass)
+ .map(LeafRefContextTest::getInstance)
+ .map(YangModelBindingProvider.class::cast)
+ .map(YangModelBindingProvider::getModuleInfo)
+ .collect(Collectors.toSet());
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to load binding providers from path: " + YANG_BA_PROVIDER_PATH, e);
+ }
+ }
+
+ private static Object getInstance(@Nonnull final Class<?> aClass) {
+ try {
+ return aClass.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new IllegalStateException("Unable to create instance of " + aClass);
+ }
+ }
+
+ private static Class<?> loadClass(@Nonnull final String className) {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Unable to load class: " + className, e);
+ }
+ }
+
+ private static String urlToString(@Nonnull final URL url) {
+ try {
+ return Resources.toString(url, Charsets.UTF_8);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Unable to read resource from: " + url, e);
+ }
+ }
+}