Bump MRI upstreams
[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
9 package org.opendaylight.controller.sal.rest.doc.impl;
10
11 import com.fasterxml.jackson.databind.node.ObjectNode;
12 import com.google.common.base.Preconditions;
13 import java.sql.Date;
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.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22
23
24 public class SwaggerObjectTest {
25
26     private static final String NAMESPACE = "urn:opendaylight:groupbasedpolicy:opflex";
27     private static final String STRING_DATE = "2014-05-28";
28     private static final Date REVISION = Date.valueOf(STRING_DATE);
29     private DocGenTestHelper helper;
30     private EffectiveModelContext schemaContext;
31
32     @Before
33     public void setUp() throws Exception {
34         this.helper = new DocGenTestHelper();
35         this.helper.setUp();
36         this.schemaContext = this.helper.getSchemaContext();
37     }
38
39     @Test
40     public void testConvertToJsonSchema() throws Exception {
41
42         Preconditions.checkArgument(this.helper.getModules() != null, "No modules found");
43
44         final DefinitionGenerator generator = new DefinitionGenerator();
45
46         for (final Module m : this.helper.getModules()) {
47             if (m.getQNameModule().getNamespace().toString().equals(NAMESPACE)
48                     && m.getQNameModule().getRevision().equals(REVISION)) {
49
50                 final ObjectNode jsonObject = generator.convertToJsonSchema(m, this.schemaContext,
51                         new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
52                 Assert.assertNotNull(jsonObject);
53             }
54         }
55     }
56
57     @Test
58     public void testStringTypes() throws Exception {
59         Preconditions.checkArgument(this.helper.getModules() != null, "No modules found");
60         Module strTypes = this.helper.getModules().stream()
61                 .filter(module -> module.getName().equals("string-types"))
62                 .findFirst()
63                 .orElseThrow(() -> new IllegalArgumentException("String types module not found"));
64
65         final DefinitionGenerator generator = new DefinitionGenerator();
66         final ObjectNode jsonObject = generator.convertToJsonSchema(strTypes, this.schemaContext, new DefinitionNames(),
67                 ApiDocServiceImpl.OAversion.V2_0, true);
68
69         Assert.assertNotNull(jsonObject);
70     }
71 }