X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-docgen%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fdoc%2Fimpl%2FDocGeneratorTest.java;fp=opendaylight%2Fmd-sal%2Fsal-rest-docgen%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fdoc%2Fimpl%2FDocGeneratorTest.java;h=127529a3c68135ae22d8668225c910c39ee8128d;hb=2e8e671a52614978de6940919fc677625dc25def;hp=0000000000000000000000000000000000000000;hpb=61bad4207cc91cd14d8d38a255ad6549c20ff54e;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGeneratorTest.java b/opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGeneratorTest.java new file mode 100644 index 0000000000..127529a3c6 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGeneratorTest.java @@ -0,0 +1,72 @@ +package org.opendaylight.controller.sal.rest.doc.impl; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule; +import com.google.common.base.Preconditions; +import junit.framework.Assert; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * + */ +public class DocGeneratorTest { + + private Set modules; + private ObjectMapper mapper; + + public Set loadModules(String resourceDirectory) throws FileNotFoundException, URISyntaxException { + + URI resourceDirUri = getClass().getResource(resourceDirectory).toURI(); + final YangModelParser parser = new YangParserImpl(); + final File testDir = new File(resourceDirUri); + final String[] fileList = testDir.list(); + final List testFiles = new ArrayList<>(); + if (fileList == null) { + throw new FileNotFoundException(resourceDirectory.toString()); + } + for (String fileName : fileList) { + + testFiles.add(new File(testDir, fileName)); + } + return parser.parseYangModels(testFiles); + } + + @Before + public void before() throws Exception { + modules = loadModules("/yang"); + mapper = new ObjectMapper(); + mapper.registerModule(new JsonOrgModule()); + } + + @After + public void after() throws Exception { + } + + /** + * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo) + */ + @Test + public void testGetModuleDoc() throws Exception { + Preconditions.checkArgument(modules != null, "No modules found"); + + for (Module m : modules){ + ApiDeclaration doc = ApiDocGenerator.getInstance().getSwaggerDocSpec(m, "http://localhost:8080/restconf"); + Assert.assertNotNull(doc); + } + } + +}