Search in sources :

Example 1 with SwaggerObject

use of org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject in project netconf by opendaylight.

the class ApiDocGeneratorDraftO2Test method testConfigPaths.

/**
 * Test that generated configuration paths allow to use operations: get, put, delete and post.
 */
@Test
public void testConfigPaths() {
    final List<String> configPaths = Arrays.asList("/restconf/config/toaster2:lst", "/restconf/config/toaster2:lst/cont1", "/restconf/config/toaster2:lst/cont1/cont11", "/restconf/config/toaster2:lst/cont1/lst11", "/restconf/config/toaster2:lst/lst1/{key1}/{key2}");
    final Optional<? extends Module> module = context.findModule(NAME, Revision.of(REVISION_DATE));
    assertTrue("Desired module not found", module.isPresent());
    final SwaggerObject doc = generator.getSwaggerDocSpec(module.get(), "http", "localhost:8181", "/", "", context, URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0);
    for (final String path : configPaths) {
        final JsonNode node = doc.getPaths().get(path);
        assertFalse(node.path("get").isMissingNode());
        assertFalse(node.path("put").isMissingNode());
        assertFalse(node.path("delete").isMissingNode());
        assertFalse(node.path("post").isMissingNode());
    }
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 2 with SwaggerObject

use of org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject in project netconf by opendaylight.

the class ApiDocGeneratorDraftO2Test method testDefinitions.

/**
 * Test that generated document contains the following definitions.
 */
@Test
public void testDefinitions() {
    final Optional<? extends Module> module = context.findModule(NAME, Revision.of(REVISION_DATE));
    assertTrue("Desired module not found", module.isPresent());
    final SwaggerObject doc = generator.getSwaggerDocSpec(module.get(), "http", "localhost:8181", "/", "", context, URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0);
    final ObjectNode definitions = doc.getDefinitions();
    assertNotNull(definitions);
    final JsonNode configLstTop = definitions.get("toaster2_config_lst_TOP");
    assertNotNull(configLstTop);
    DocGenTestHelper.containsReferences(configLstTop, "lst", "#/definitions/toaster2_config_lst");
    final JsonNode configLst = definitions.get("toaster2_config_lst");
    assertNotNull(configLst);
    DocGenTestHelper.containsReferences(configLst, "lst1", "#/definitions/toaster2_lst_config_lst1");
    DocGenTestHelper.containsReferences(configLst, "cont1", "#/definitions/toaster2_lst_config_cont1");
    final JsonNode configLst1Top = definitions.get("toaster2_lst_config_lst1_TOP");
    assertNotNull(configLst1Top);
    DocGenTestHelper.containsReferences(configLst1Top, "lst1", "#/definitions/toaster2_lst_config_lst1");
    final JsonNode configLst1 = definitions.get("toaster2_lst_config_lst1");
    assertNotNull(configLst1);
    final JsonNode configCont1Top = definitions.get("toaster2_lst_config_cont1_TOP");
    assertNotNull(configCont1Top);
    DocGenTestHelper.containsReferences(configCont1Top, "cont1", "#/definitions/toaster2_lst_config_cont1");
    final JsonNode configCont1 = definitions.get("toaster2_lst_config_cont1");
    assertNotNull(configCont1);
    DocGenTestHelper.containsReferences(configCont1, "cont11", "#/definitions/toaster2_lst_cont1_config_cont11");
    DocGenTestHelper.containsReferences(configCont1, "lst11", "#/definitions/toaster2_lst_cont1_config_lst11");
    final JsonNode configCont11Top = definitions.get("toaster2_lst_cont1_config_cont11_TOP");
    assertNotNull(configCont11Top);
    DocGenTestHelper.containsReferences(configCont11Top, "cont11", "#/definitions/toaster2_lst_cont1_config_cont11");
    final JsonNode configCont11 = definitions.get("toaster2_lst_cont1_config_cont11");
    assertNotNull(configCont11);
    final JsonNode configLst11Top = definitions.get("toaster2_lst_cont1_config_lst11_TOP");
    assertNotNull(configLst11Top);
    DocGenTestHelper.containsReferences(configLst11Top, "lst11", "#/definitions/toaster2_lst_cont1_config_lst11");
    final JsonNode configLst11 = definitions.get("toaster2_lst_cont1_config_lst11");
    assertNotNull(configLst11);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 3 with SwaggerObject

use of org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject in project netconf by opendaylight.

the class ApiDocGeneratorDraftO2Test method testRPC.

/**
 * Test that generated document contains RPC definition for "make-toast" with correct input.
 */
@Test
public void testRPC() {
    final Optional<? extends Module> module = context.findModule(NAME_2, Revision.of(REVISION_DATE_2));
    assertTrue("Desired module not found", module.isPresent());
    final SwaggerObject doc = generator.getSwaggerDocSpec(module.get(), "http", "localhost:8181", "/", "", context, URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0);
    assertNotNull(doc);
    final ObjectNode definitions = doc.getDefinitions();
    final JsonNode inputTop = definitions.get("toaster_make-toast_input_TOP");
    assertNotNull(inputTop);
    final String testString = "{\"input\":{\"$ref\":\"#/definitions/toaster_make-toast_input\"}}";
    assertEquals(testString, inputTop.get("properties").toString());
    final JsonNode input = definitions.get("toaster_make-toast_input");
    final JsonNode properties = input.get("properties");
    assertTrue(properties.has("toasterDoneness"));
    assertTrue(properties.has("toasterToastType"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 4 with SwaggerObject

use of org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject in project netconf by opendaylight.

the class ApiDocGeneratorDraftO2Test method testPaths.

/**
 * Test that paths are generated according to the model.
 */
@Test
public void testPaths() {
    final List<String> expectedPaths = Arrays.asList("/restconf/config", "/restconf/config/toaster2:toaster", "/restconf/config/toaster2:toaster/toasterSlot/{slotId}", "/restconf/config/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo", "/restconf/operational/toaster2:toaster", "/restconf/operational/toaster2:toaster/toasterSlot/{slotId}", "/restconf/operational/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo", "/restconf/config/toaster2:lst", "/restconf/config/toaster2:lst/cont1", "/restconf/config/toaster2:lst/cont1/cont11", "/restconf/config/toaster2:lst/cont1/lst11", "/restconf/config/toaster2:lst/lst1/{key1}/{key2}", "/restconf/operational/toaster2:lst", "/restconf/operational/toaster2:lst/cont1", "/restconf/operational/toaster2:lst/cont1/cont11", "/restconf/operational/toaster2:lst/cont1/lst11", "/restconf/operational/toaster2:lst/lst1/{key1}/{key2}", "/restconf/operations/toaster2:make-toast", "/restconf/operations/toaster2:cancel-toast", "/restconf/operations/toaster2:restock-toaster");
    final Optional<? extends Module> module = context.findModule(NAME, Revision.of(REVISION_DATE));
    assertTrue("Desired module not found", module.isPresent());
    final SwaggerObject doc = generator.getSwaggerDocSpec(module.get(), "http", "localhost:8181", "/", "", context, URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0);
    final List<String> actualPaths = new ArrayList<>();
    doc.getPaths().fieldNames().forEachRemaining(actualPaths::add);
    assertEquals(expectedPaths, actualPaths);
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with SwaggerObject

use of org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject in project netconf by opendaylight.

the class ApiDocGeneratorRFC8040Test method testRPC.

/**
 * Test that generated document contains RPC definition for "make-toast" with correct input.
 */
@Test
public void testRPC() {
    final Optional<? extends Module> module = context.findModule(NAME_2, Revision.of(REVISION_DATE_2));
    assertTrue("Desired module not found", module.isPresent());
    final SwaggerObject doc = generator.getSwaggerDocSpec(module.get(), "http", "localhost:8181", "/", "", context, URIType.RFC8040, ApiDocServiceImpl.OAversion.V2_0);
    assertNotNull(doc);
    final ObjectNode definitions = doc.getDefinitions();
    final JsonNode inputTop = definitions.get("toaster_make-toast_input_TOP");
    assertNotNull(inputTop);
    final String testString = "{\"input\":{\"$ref\":\"#/definitions/toaster_make-toast_input\"}}";
    assertEquals(testString, inputTop.get("properties").toString());
    final JsonNode input = definitions.get("toaster_make-toast_input");
    final JsonNode properties = input.get("properties");
    assertTrue(properties.has("toasterDoneness"));
    assertTrue(properties.has("toasterToastType"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

SwaggerObject (org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject)18 Test (org.junit.Test)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ArrayList (java.util.ArrayList)3 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 UriInfo (javax.ws.rs.core.UriInfo)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 Range (com.google.common.collect.Range)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 DefinitionNames (org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames)1 Info (org.opendaylight.netconf.sal.rest.doc.swagger.Info)1 Resource (org.opendaylight.netconf.sal.rest.doc.swagger.Resource)1 ResourceList (org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1