Modernize sal-rest-docgen tests a bit
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / SwaggerObjectTest.java
index 6de33841206ca864fdbe399787d9febfb85dea97..45287530e403dfd9196d21bb3391d6e50275978f 100644 (file)
@@ -5,67 +5,43 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.sal.rest.doc.impl;
 
+import static org.junit.Assert.assertNotNull;
+
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Preconditions;
-import java.sql.Date;
-import org.junit.Assert;
-import org.junit.Before;
+import java.io.IOException;
 import org.junit.Test;
 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl;
 import org.opendaylight.netconf.sal.rest.doc.impl.DefinitionGenerator;
 import org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
-
-public class SwaggerObjectTest {
+import org.opendaylight.yangtools.yang.common.Revision;
 
-    private static final String NAMESPACE = "urn:opendaylight:groupbasedpolicy:opflex";
-    private static final String STRING_DATE = "2014-05-28";
-    private static final Date REVISION = Date.valueOf(STRING_DATE);
-    private DocGenTestHelper helper;
-    private SchemaContext schemaContext;
-
-    @Before
-    public void setUp() throws Exception {
-        this.helper = new DocGenTestHelper();
-        this.helper.setUp();
-        this.schemaContext = this.helper.getSchemaContext();
+public final class SwaggerObjectTest extends AbstractApiDocTest {
+    @Test
+    public void testConvertToJsonSchema() throws IOException {
+        final var module = CONTEXT.findModule("opflex", Revision.of("2014-05-28")).orElseThrow();
+        final DefinitionGenerator generator = new DefinitionGenerator();
+        final ObjectNode jsonObject = generator.convertToJsonSchema(module, CONTEXT, new DefinitionNames(),
+            ApiDocServiceImpl.OAversion.V2_0, true);
+        assertNotNull(jsonObject);
     }
 
     @Test
-    public void testConvertToJsonSchema() throws Exception {
-
-        Preconditions.checkArgument(this.helper.getModules() != null, "No modules found");
-
+    public void testActionTypes() throws IOException {
+        final var module = CONTEXT.findModule("action-types").orElseThrow();
         final DefinitionGenerator generator = new DefinitionGenerator();
-
-        for (final Module m : this.helper.getModules()) {
-            if (m.getQNameModule().getNamespace().toString().equals(NAMESPACE)
-                    && m.getQNameModule().getRevision().equals(REVISION)) {
-
-                final ObjectNode jsonObject = generator.convertToJsonSchema(m, this.schemaContext,
-                        new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
-                Assert.assertNotNull(jsonObject);
-            }
-        }
+        final ObjectNode jsonObject = generator.convertToJsonSchema(module, CONTEXT, new DefinitionNames(),
+            ApiDocServiceImpl.OAversion.V2_0, true);
+        assertNotNull(jsonObject);
     }
 
     @Test
-    public void testStringTypes() throws Exception {
-        Preconditions.checkArgument(this.helper.getModules() != null, "No modules found");
-        Module strTypes = this.helper.getModules().stream()
-                .filter(module -> module.getName().equals("string-types"))
-                .findFirst()
-                .orElseThrow(() -> new IllegalArgumentException("String types module not found"));
-
+    public void testStringTypes() throws IOException {
+        final var module = CONTEXT.findModule("string-types").orElseThrow();
         final DefinitionGenerator generator = new DefinitionGenerator();
-        final ObjectNode jsonObject = generator.convertToJsonSchema(strTypes, this.schemaContext, new DefinitionNames(),
-                ApiDocServiceImpl.OAversion.V2_0, true);
-
-        Assert.assertNotNull(jsonObject);
+        final ObjectNode jsonObject = generator.convertToJsonSchema(module, CONTEXT, new DefinitionNames(),
+            ApiDocServiceImpl.OAversion.V2_0, true);
+        assertNotNull(jsonObject);
     }
 }