2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.sal.rest.doc.impl;
11 import com.fasterxml.jackson.databind.node.ObjectNode;
12 import com.google.common.base.Preconditions;
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;
24 public class SwaggerObjectTest {
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;
33 public void setUp() throws Exception {
34 this.helper = new DocGenTestHelper();
36 this.schemaContext = this.helper.getSchemaContext();
40 public void testConvertToJsonSchema() throws Exception {
42 Preconditions.checkArgument(this.helper.getModules() != null, "No modules found");
44 final DefinitionGenerator generator = new DefinitionGenerator();
46 for (final Module m : this.helper.getModules()) {
47 if (m.getQNameModule().getNamespace().toString().equals(NAMESPACE)
48 && m.getQNameModule().getRevision().equals(REVISION)) {
50 final ObjectNode jsonObject = generator.convertToJsonSchema(m, this.schemaContext,
51 new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
52 Assert.assertNotNull(jsonObject);
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"))
63 .orElseThrow(() -> new IllegalArgumentException("String types module not found"));
65 final DefinitionGenerator generator = new DefinitionGenerator();
66 final ObjectNode jsonObject = generator.convertToJsonSchema(strTypes, this.schemaContext, new DefinitionNames(),
67 ApiDocServiceImpl.OAversion.V2_0, true);
69 Assert.assertNotNull(jsonObject);