889606d7e6fe1777ee149fef15f70c820a1f2e80
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / SwaggerObjectTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.rest.doc.impl;
9
10 import static org.junit.Assert.assertTrue;
11
12 import com.fasterxml.jackson.databind.node.ObjectNode;
13 import java.util.Optional;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl;
18 import org.opendaylight.netconf.sal.rest.doc.impl.DefinitionGenerator;
19 import org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames;
20 import org.opendaylight.yangtools.yang.common.Revision;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 public final class SwaggerObjectTest {
26     private EffectiveModelContext context;
27
28     @Before
29     public void setUp() {
30         context = YangParserTestUtils.parseYangResourceDirectory("/yang");
31     }
32
33     @Test
34     public void testConvertToJsonSchema() throws Exception {
35         final Optional<? extends Module> module = context.findModule("opflex", Revision.of("2014-05-28"));
36         assertTrue("Desired module not found", module.isPresent());
37         final DefinitionGenerator generator = new DefinitionGenerator();
38         final ObjectNode jsonObject = generator.convertToJsonSchema(module.get(), context,
39                 new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
40         Assert.assertNotNull(jsonObject);
41     }
42
43     @Test
44     public void testStringTypes() throws Exception {
45         final Optional<? extends Module> module = context.findModule("string-types");
46         assertTrue("Desired module not found", module.isPresent());
47         final DefinitionGenerator generator = new DefinitionGenerator();
48         final ObjectNode jsonObject = generator.convertToJsonSchema(module.get(), context, new DefinitionNames(),
49                 ApiDocServiceImpl.OAversion.V2_0, true);
50
51         Assert.assertNotNull(jsonObject);
52     }
53 }