@Test public void docTemplate() { String mountPoint = "/foo"; Utils.addTemplateValue(DocumentationRestApi.ID_TEMPLATE, "fooID"); Utils.addTemplateValue(DocumentationRestApi.MOUNT_TEMPLATE, mountPoint); processResource("ApiLevelTemplateDocs.java", "raml", "all"); Map.Entry<String, String> entry = output.entrySet().iterator().next(); entry.getKey(); AssertJUnit.assertTrue("expected file named AuthorizationScopes.raml", entry.getKey().endsWith("ApiLevelTemplateDocs-fooID.raml")); Raml raml = new RamlDocumentBuilder().build(entry.getValue(), "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); List<DocumentationItem> documentation = raml.getDocumentation(); AssertJUnit.assertEquals("RAML baseUri is incorrect", mountPoint, raml.getBaseUri()); Resource resource = raml.getResource(mountPoint); AssertJUnit.assertNotNull("Cannot find resource related to:" + mountPoint, resource); }
@Test public void testEnumsTypesInPathForRaml() { processResource("RestDocEndpoint.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/mount/api/v1/colors/{color}"); AssertJUnit.assertNotNull("Resource /mount/api/v1/colors/{color} not found", resource); UriParameter up = resource.getUriParameters().get("color"); AssertJUnit.assertNotNull("No color path param found on GET method of /mount/api/v1/colors/{color}", up); List<String> enums = up.getEnumeration(); AssertJUnit.assertNotNull("Color path param on GET method of /mount/api/v1/colors/{color} not enum", enums); AssertJUnit.assertEquals("Color path param on GET /mount/api/v1/colors/{color} is wrong size", 3, enums.size()); }
@Test public void assertNoRedundantUriParametersForResource() { processResource("RestDocEndpoint.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/mount/api/v1/widgets/{id1}/gizmos"); AssertJUnit.assertNotNull("Resource /mount/api/v1/widgets/{id1}/gizmos not found", resource); resource = resource.getResource("/{id2}"); AssertJUnit.assertNotNull("Resource /mount/api/v1/widgets/{id1}/gizmos/{id2} not found", resource); }
@Test public void assertUriParameterNormalization() { processResource("UriParameterNormalization.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/widgets/{id}"); AssertJUnit.assertNotNull("Resource /widgets/{id} not found", resource); UriParameter id = resource.getUriParameters().get("id"); AssertJUnit.assertNotNull("Resource /widgets/{id} has no id URI parameter", id); // Flakey test depends on order of resource processing // AssertJUnit.assertEquals("Resource /widgets/{id} id URI parameter description is wrong", // "The widget identifier documented in POST.", id.getDescription().trim()); resource = resource.getResource("/gadgets"); AssertJUnit.assertNotNull("Resource /widgets/{id}/gadgets not found", resource); id = resource.getUriParameters().get("id"); AssertJUnit.assertNull("Resource /widgets/{id}/gadgets has it's own id URI parameter when it should not", id); }
AssertJUnit.assertTrue("RAML expected to contain deprecated trait", traits.get(1).containsKey("deprecated")); Resource res = raml.getResource("/stable1"); AssertJUnit.assertNotNull("resource /stable1 not found", res); Action act = res.getAction(ActionType.GET); AssertJUnit.assertEquals("resource /stable1 should have empty \'is\'", 0, is.size()); res = raml.getResource("/deprecated2"); AssertJUnit.assertNotNull("resource /deprecated2 not found", res); act = res.getAction(ActionType.GET); AssertJUnit.assertEquals("resource /deprecated2 should be deprecated", "deprecated", is.iterator().next()); res = raml.getResource("/stable3"); AssertJUnit.assertNotNull("resource /stable3 not found", res); act = res.getAction(ActionType.GET); AssertJUnit.assertEquals("resource /stable3 should have empty \'is\'", 0, is.size()); res = raml.getResource("/deprecated3"); AssertJUnit.assertNotNull("resource /deprecated3 not found", res); act = res.getAction(ActionType.GET); res = raml.getResource("/experimentaldeprecated3"); AssertJUnit.assertNotNull("resource /experimentaldeprecated3 not found", res); act = res.getAction(ActionType.GET);
@Test public void testEnumsTypesQueryForRaml() { processResource("RestDocEndpoint.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/mount/api/v1/whirlygigs"); AssertJUnit.assertNotNull("Resource /mount/api/v1/whirlygigs not found", resource); Action action = resource.getAction(ActionType.GET); AssertJUnit.assertNotNull("Method GET not found on /mount/api/v1/whirlygigs", action); QueryParameter qp = action.getQueryParameters().get("color"); AssertJUnit.assertNotNull("No color query param found on GET method of /mount/api/v1/whirlygigs", qp); List<String> enums = qp.getEnumeration(); AssertJUnit.assertNotNull("Color query param on GET method of /mount/api/v1/whirlygigs not enum", enums); AssertJUnit.assertEquals("Color query param on GET /mount/api/v1/whirlygigs is wrong size", 3, enums.size()); }
AssertJUnit.assertNotNull("RAML not parseable", raml); List<DocumentationItem> documentation = raml.getDocumentation(); Resource resource = raml.getResource("/default/api/v1/default"); AssertJUnit.assertNotNull("RAML has no default controller", resource); Action action = resource.getAction(ActionType.GET); AssertJUnit.assertTrue("RAML default controller has a security reference", secRef.size() == 0); resource = raml.getResource("/twoscopes/api/v1/twoscope"); AssertJUnit.assertNotNull("RAML has no twoscope controller", resource); action = resource.getAction(ActionType.POST);