1 package org.opendaylight.controller.sal.rest.doc.impl;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
5 import com.google.common.base.Preconditions;
6 import junit.framework.Assert;
8 import org.junit.Before;
9 import org.junit.After;
10 import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration;
11 import org.opendaylight.yangtools.yang.model.api.Module;
12 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
13 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
16 import java.io.FileNotFoundException;
18 import java.net.URISyntaxException;
19 import java.util.ArrayList;
20 import java.util.List;
26 public class DocGeneratorTest {
28 private Set<Module> modules;
29 private ObjectMapper mapper;
31 public Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException, URISyntaxException {
33 URI resourceDirUri = getClass().getResource(resourceDirectory).toURI();
34 final YangModelParser parser = new YangParserImpl();
35 final File testDir = new File(resourceDirUri);
36 final String[] fileList = testDir.list();
37 final List<File> testFiles = new ArrayList<>();
38 if (fileList == null) {
39 throw new FileNotFoundException(resourceDirectory.toString());
41 for (String fileName : fileList) {
43 testFiles.add(new File(testDir, fileName));
45 return parser.parseYangModels(testFiles);
49 public void before() throws Exception {
50 modules = loadModules("/yang");
51 mapper = new ObjectMapper();
52 mapper.registerModule(new JsonOrgModule());
56 public void after() throws Exception {
60 * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo)
63 public void testGetModuleDoc() throws Exception {
64 Preconditions.checkArgument(modules != null, "No modules found");
66 for (Module m : modules){
67 ApiDeclaration doc = ApiDocGenerator.getInstance().getSwaggerDocSpec(m, "http://localhost:8080/restconf");
68 Assert.assertNotNull(doc);