Add message to update the schema context of the InMemoryDOMDataStore
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / DocGeneratorTest.java
1 package org.opendaylight.controller.sal.rest.doc.impl;
2
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;
7 import org.junit.Test;
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;
14
15 import java.io.File;
16 import java.io.FileNotFoundException;
17 import java.net.URI;
18 import java.net.URISyntaxException;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Set;
22
23 /**
24  *
25  */
26 public class DocGeneratorTest {
27
28   private Set<Module> modules;
29   private ObjectMapper mapper;
30
31   public Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException, URISyntaxException {
32
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());
40     }
41     for (String fileName : fileList) {
42
43       testFiles.add(new File(testDir, fileName));
44     }
45     return parser.parseYangModels(testFiles);
46   }
47
48   @Before
49   public void before() throws Exception {
50     modules = loadModules("/yang");
51     mapper = new ObjectMapper();
52     mapper.registerModule(new JsonOrgModule());
53   }
54
55   @After
56   public void after() throws Exception {
57   }
58
59   /**
60    * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo)
61    */
62   @Test
63   public void testGetModuleDoc() throws Exception {
64     Preconditions.checkArgument(modules != null, "No modules found");
65
66     for (Module m : modules){
67       ApiDeclaration doc = ApiDocGenerator.getInstance().getSwaggerDocSpec(m, "http://localhost:8080/restconf");
68       Assert.assertNotNull(doc);
69     }
70   }
71
72 }