Organize Imports for Checkstyle compliance.
Checkstyle compliance: line length.
Checkstyle compliance: various types of small changes.
Checkstyle compliant Exception handling.
Checkstyle final clean up & enforcement.
Add the fail on violation flag into the pom.xml .
Change-Id: If4a4a3b17f8a0b93433fb41813f2560b334fd45c
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Response getRootDoc(@Context javax.ws.rs.core.UriInfo uriInfo);
+ Response getRootDoc(@Context javax.ws.rs.core.UriInfo uriInfo);
/**
* Generates Swagger compliant document listing APIs for module.
@GET
@Path("/{module}({revision})")
@Produces(MediaType.APPLICATION_JSON)
- public Response getDocByModule(@PathParam("module") String module,
+ Response getDocByModule(@PathParam("module") String module,
@PathParam("revision") String revision, @Context javax.ws.rs.core.UriInfo uriInfo);
/**
@GET
@Path("/ui")
@Produces(MediaType.TEXT_HTML)
- public Response getApiExplorer(@Context javax.ws.rs.core.UriInfo uriInfo);
+ Response getApiExplorer(@Context javax.ws.rs.core.UriInfo uriInfo);
/**
* Generates index document for Swagger UI. This document lists out all
@GET
@Path("/mounts")
@Produces(MediaType.APPLICATION_JSON)
- public Response getListOfMounts(@Context javax.ws.rs.core.UriInfo uriInfo);
+ Response getListOfMounts(@Context javax.ws.rs.core.UriInfo uriInfo);
@GET
@Path("/mounts/{instance}")
@Produces(MediaType.APPLICATION_JSON)
- public Response getMountRootDoc(@PathParam("instance") String instanceNum,
+ Response getMountRootDoc(@PathParam("instance") String instanceNum,
@Context javax.ws.rs.core.UriInfo uriInfo);
/**
@GET
@Path("/mounts/{instance}/{module}({revision})")
@Produces(MediaType.APPLICATION_JSON)
- public Response getMountDocByModule(@PathParam("instance") String instanceNum,
+ Response getMountDocByModule(@PathParam("instance") String instanceNum,
@PathParam("module") String module, @PathParam("revision") String revision,
@Context javax.ws.rs.core.UriInfo uriInfo);
return Response.seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build()).build();
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public synchronized Response getListOfMounts(final UriInfo uriInfo) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
return basePath;
}
- public ApiDeclaration getSwaggerDocSpec(final Module m, final String basePath, final String context,
- final SchemaContext schemaContext) {
+ public ApiDeclaration getSwaggerDocSpec(final Module module, final String basePath, final String context,
+ final SchemaContext schemaContext) {
final ApiDeclaration doc = createApiDeclaration(basePath);
final List<Api> apis = new ArrayList<>();
boolean hasAddRootPostLink = false;
- final Collection<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
+ final Collection<DataSchemaNode> dataSchemaNodes = module.getChildNodes();
LOG.debug("child nodes size [{}]", dataSchemaNodes.size());
for (final DataSchemaNode node : dataSchemaNodes) {
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
* only one root post link is added for this module.
*/
if (!hasAddRootPostLink) {
- LOG.debug("Has added root post link for module {}", m.getName());
- addRootPostLink(m, (DataNodeContainer) node, pathParams, resourcePath, "config", apis);
+ LOG.debug("Has added root post link for module {}", module.getName());
+ addRootPostLink(module, (DataNodeContainer) node, pathParams, resourcePath, "config", apis);
hasAddRootPostLink = true;
}
- addApis(node, apis, resourcePath, pathParams, schemaContext, true, m.getName(), "config");
+ addApis(node, apis, resourcePath, pathParams, schemaContext, true, module.getName(), "config");
}
pathParams = new ArrayList<>();
resourcePath = getDataStorePath("operational", context);
- addApis(node, apis, resourcePath, pathParams, schemaContext, false, m.getName(), "operational");
+ addApis(node, apis, resourcePath, pathParams, schemaContext, false, module.getName(), "operational");
}
}
- final Set<RpcDefinition> rpcs = m.getRpcs();
+ final Set<RpcDefinition> rpcs = module.getRpcs();
for (final RpcDefinition rpcDefinition : rpcs) {
final String resourcePath;
resourcePath = getDataStorePath("operations", context);
JSONObject models = null;
try {
- models = this.jsonConverter.convertToJsonSchema(m, schemaContext);
+ models = this.jsonConverter.convertToJsonSchema(module, schemaContext);
doc.setModels(models);
if (LOG.isDebugEnabled()) {
LOG.debug(this.mapper.writeValueAsString(doc));
LOG.debug("Adding path: [{}]", resourcePath);
api.setPath(resourcePath.concat(getContent(dataStore)));
- Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode> emptySet();
+ Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode>emptySet();
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
final DataNodeContainer dataNodeContainer = (DataNodeContainer) node;
childSchemaNodes = dataNodeContainer.getChildNodes();
}
/**
- * Creates Json models from provided module according to swagger spec
+ * Creates Json models from provided module according to swagger spec.
*
* @param module - Yang module to be converted
* @param schemaContext - SchemaContext of all Yang files used by Api Doc
* @return JSONObject containing data used for creating examples and models in Api Doc
- * @throws IOException
- * @throws JSONException
+ * @throws IOException if I/O operation fails
+ * @throws JSONException when things are amiss
*/
- public JSONObject convertToJsonSchema(final Module module, final SchemaContext schemaContext) throws IOException, JSONException {
+ public JSONObject convertToJsonSchema(final Module module,
+ final SchemaContext schemaContext) throws IOException, JSONException {
final JSONObject models = new JSONObject();
models.put(UNIQUE_EMPTY_IDENTIFIER, new JSONObject());
topLevelModule = module;
return models;
}
- private void processModules(final Module module, final JSONObject models, final SchemaContext schemaContext) throws JSONException {
+ private void processModules(final Module module, final JSONObject models,
+ final SchemaContext schemaContext) throws JSONException {
createConcreteModelForPost(models, module.getName() + BaseYangSwaggerGenerator.MODULE_NAME_SUFFIX,
createPropertiesForPost(module, schemaContext, module.getName()));
}
- private void processContainersAndLists(final Module module, final JSONObject models, final SchemaContext schemaContext)
- throws IOException, JSONException {
+ private void processContainersAndLists(final Module module, final JSONObject models,
+ final SchemaContext schemaContext) throws IOException, JSONException {
final String moduleName = module.getName();
for (final DataSchemaNode childNode : module.getChildNodes()) {
}
/**
- * Process the RPCs for a Module Spits out a file each of the name <rpcName>-input.json and <rpcName>-output.json
- * for each RPC that contains input & output elements
+ * Process the RPCs for a Module Spits out a file each of the name
+ * {@code <rpcName>-input.json and <rpcName>-output.json}
+ * for each RPC that contains input & output elements.
*
- * @param module
- * @throws JSONException
- * @throws IOException
+ * @param module module
+ * @throws JSONException when things are amiss
+ * @throws IOException if I/O operation fails
*/
- private void processRPCs(final Module module, final JSONObject models, final SchemaContext schemaContext) throws JSONException,
+ private void processRPCs(final Module module, final JSONObject models,
+ final SchemaContext schemaContext) throws JSONException,
IOException {
final Set<RpcDefinition> rpcs = module.getRpcs();
final String moduleName = module.getName();
for (final RpcDefinition rpc : rpcs) {
final ContainerSchemaNode input = rpc.getInput();
if (!input.getChildNodes().isEmpty()) {
- final JSONObject properties = processChildren(input.getChildNodes(), moduleName, models, true, schemaContext);
+ final JSONObject properties =
+ processChildren(input.getChildNodes(), moduleName, models, true, schemaContext);
final String filename = "(" + rpc.getQName().getLocalName() + ")input";
final JSONObject childSchema = getSchemaTemplate();
final ContainerSchemaNode output = rpc.getOutput();
if (!output.getChildNodes().isEmpty()) {
- final JSONObject properties = processChildren(output.getChildNodes(), moduleName, models, true, schemaContext);
+ final JSONObject properties =
+ processChildren(output.getChildNodes(), moduleName, models, true, schemaContext);
final String filename = "(" + rpc.getQName().getLocalName() + ")output";
final JSONObject childSchema = getSchemaTemplate();
childSchema.put(TYPE_KEY, OBJECT_TYPE);
}
}
- private JSONObject processDataNodeContainer(final DataNodeContainer dataNode, final String parentName, final JSONObject models,
- final boolean isConfig, final SchemaContext schemaContext) throws JSONException, IOException {
+ private JSONObject processDataNodeContainer(
+ final DataNodeContainer dataNode, final String parentName, final JSONObject models, final boolean isConfig,
+ final SchemaContext schemaContext) throws JSONException, IOException {
if (dataNode instanceof ListSchemaNode || dataNode instanceof ContainerSchemaNode) {
final Iterable<DataSchemaNode> containerChildren = dataNode.getChildNodes();
final String localName = ((SchemaNode) dataNode).getQName().getLocalName();
- final JSONObject properties = processChildren(containerChildren, parentName + "/" + localName, models, isConfig, schemaContext);
+ final JSONObject properties =
+ processChildren(containerChildren, parentName + "/" + localName, models, isConfig, schemaContext);
final String nodeName = parentName + (isConfig ? OperationBuilder.CONFIG : OperationBuilder.OPERATIONAL)
+ localName;
models.put(nodePostName, postSchema);
}
- private JSONObject createPropertiesForPost(final DataNodeContainer dataNodeContainer, final SchemaContext schemaContext, final String parentName)
+ private JSONObject createPropertiesForPost(final DataNodeContainer dataNodeContainer,
+ final SchemaContext schemaContext, final String parentName)
throws JSONException {
final JSONObject properties = new JSONObject();
for (final DataSchemaNode childNode : dataNodeContainer.getChildNodes()) {
/**
* Processes the nodes.
*/
- private JSONObject processChildren(final Iterable<DataSchemaNode> nodes, final String parentName, final JSONObject models,
- final boolean isConfig, final SchemaContext schemaContext)
+ private JSONObject processChildren(
+ final Iterable<DataSchemaNode> nodes, final String parentName, final JSONObject models,
+ final boolean isConfig, final SchemaContext schemaContext)
throws JSONException, IOException {
final JSONObject properties = new JSONObject();
for (final DataSchemaNode node : nodes) {
return properties;
}
- private JSONObject processLeafListNode(final LeafListSchemaNode listNode, final SchemaContext schemaContext) throws JSONException {
+ private JSONObject processLeafListNode(final LeafListSchemaNode listNode,
+ final SchemaContext schemaContext) throws JSONException {
final JSONObject props = new JSONObject();
props.put(TYPE_KEY, ARRAY_TYPE);
return props;
}
- private void processChoiceNode(final Iterable<DataSchemaNode> nodes, final String moduleName, final JSONObject models,
- final SchemaContext schemaContext, final boolean isConfig, final JSONObject properties)
+ private void processChoiceNode(
+ final Iterable<DataSchemaNode> nodes, final String moduleName, final JSONObject models,
+ final SchemaContext schemaContext, final boolean isConfig, final JSONObject properties)
throws JSONException, IOException {
for (final DataSchemaNode node : nodes) {
final String name = resolveNodesName(node, topLevelModule, schemaContext);
property = processLeafListNode((LeafListSchemaNode) node, schemaContext);
} else if (node instanceof ChoiceSchemaNode) {
- if (((ChoiceSchemaNode) node).getCases().iterator().hasNext())
+ if (((ChoiceSchemaNode) node).getCases().iterator().hasNext()) {
processChoiceNode(((ChoiceSchemaNode) node).getCases().iterator().next().getChildNodes(),
moduleName, models, schemaContext, isConfig, properties);
+ }
continue;
} else if (node instanceof AnyXmlSchemaNode) {
}
}
- private static void processConstraints(final ConstraintDefinition constraints, final JSONObject props) throws JSONException {
+ private static void processConstraints(final ConstraintDefinition constraints,
+ final JSONObject props) throws JSONException {
final boolean isMandatory = constraints.isMandatory();
props.put(REQUIRED_KEY, isMandatory);
}
}
- private JSONObject processLeafNode(final LeafSchemaNode leafNode, final SchemaContext schemaContext) throws JSONException {
+ private JSONObject processLeafNode(final LeafSchemaNode leafNode,
+ final SchemaContext schemaContext) throws JSONException {
final JSONObject property = new JSONObject();
final String leafDescription = leafNode.getDescription();
} else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
final String name = topLevelModule.getName();
- jsonType = name + ":" + ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName();
+ jsonType =
+ name + ":" + ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName();
} else if (leafTypeDef instanceof StringTypeDefinition) {
jsonType = processStringType(leafTypeDef, property, node.getQName().getLocalName());
return jsonType;
}
- private String processLeafRef(final DataSchemaNode node, final JSONObject property, final SchemaContext schemaContext,
- final TypeDefinition<?> leafTypeDef) {
- RevisionAwareXPath xPath = ((LeafrefTypeDefinition) leafTypeDef).getPathStatement();
+ private String processLeafRef(final DataSchemaNode node, final JSONObject property,
+ final SchemaContext schemaContext, final TypeDefinition<?> leafTypeDef) {
+ RevisionAwareXPath xpath = ((LeafrefTypeDefinition) leafTypeDef).getPathStatement();
final SchemaNode schemaNode;
- final String xPathString = STRIP_PATTERN.matcher(xPath.toString()).replaceAll("");
- xPath = new RevisionAwareXPathImpl(xPathString, xPath.isAbsolute());
+ final String xPathString = STRIP_PATTERN.matcher(xpath.toString()).replaceAll("");
+ xpath = new RevisionAwareXPathImpl(xPathString, xpath.isAbsolute());
final Module module;
- if (xPath.isAbsolute()) {
+ if (xpath.isAbsolute()) {
module = findModule(schemaContext, leafTypeDef.getQName());
- schemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xPath);
+ schemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xpath);
} else {
module = findModule(schemaContext, node.getQName());
- schemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, node, xPath);
+ schemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, node, xpath);
}
- return processTypeDef(((TypedSchemaNode) schemaNode).getType(), (DataSchemaNode) schemaNode, property, schemaContext);
+ return processTypeDef(((TypedSchemaNode) schemaNode).getType(), (DataSchemaNode) schemaNode,
+ property, schemaContext);
}
- private static Module findModule(final SchemaContext schemaContext, final QName qName) {
- return schemaContext.findModuleByNamespaceAndRevision(qName.getNamespace(), qName.getRevision());
+ private static Module findModule(final SchemaContext schemaContext, final QName qualifiedName) {
+ return schemaContext
+ .findModuleByNamespaceAndRevision(qualifiedName.getNamespace(), qualifiedName.getRevision());
}
private static String processBinaryType(final JSONObject property) throws JSONException {
return "bin1 bin2";
}
- private static String processEnumType(final EnumTypeDefinition enumLeafType, final JSONObject property) throws JSONException {
+ private static String processEnumType(final EnumTypeDefinition enumLeafType,
+ final JSONObject property) throws JSONException {
final List<EnumPair> enumPairs = enumLeafType.getValues();
final List<String> enumNames = new ArrayList<>();
for (final EnumPair enumPair : enumPairs) {
return enumLeafType.getValues().iterator().next().getName();
}
- private static String processBitsType(final BitsTypeDefinition bitsType, final JSONObject property) throws JSONException {
+ private static String processBitsType(final BitsTypeDefinition bitsType,
+ final JSONObject property) throws JSONException {
property.put(MIN_ITEMS, 0);
property.put(UNIQUE_ITEMS_KEY, true);
final List<String> enumNames = new ArrayList<>();
return enumNames.iterator().next() + " " + enumNames.get(enumNames.size() - 1);
}
- private static String processStringType(final TypeDefinition<?> stringType, final JSONObject property, final String nodeName)
+ private static String processStringType(final TypeDefinition<?> stringType,
+ final JSONObject property, final String nodeName)
throws JSONException {
StringTypeDefinition type = (StringTypeDefinition) stringType;
List<LengthConstraint> lengthConstraints = ((StringTypeDefinition) stringType).getLengthConstraints();
public static final String METHOD_NAME = "POST";
private final DataNodeContainer dataNodeContainer;
- public Post(final String nodeName, final String parentName, final String description, final DataNodeContainer dataNodeContainer) {
+ public Post(final String nodeName, final String parentName, final String description,
+ final DataNodeContainer dataNodeContainer) {
super(nodeName, description, parentName.replace("_module", ""));
this.dataNodeContainer = dataNodeContainer;
spec.setType(CONFIG + nodeName + METHOD_NAME);
private static final String DATASTORES_REVISION = "-";
private static final String DATASTORES_LABEL = "Datastores";
private static final String RESTCONF_DRAFT = "18";
+ private static final AtomicReference<MountPointSwagger> SELF_REF = new AtomicReference<>();
private DOMMountPointService mountService;
private final Map<YangInstanceIdentifier, Long> instanceIdToLongId =
new TreeMap<>((o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
private final Map<Long, YangInstanceIdentifier> longIdToInstanceId = new HashMap<>();
+
private final Object lock = new Object();
private final AtomicLong idKey = new AtomicLong(0);
-
- private static final AtomicReference<MountPointSwagger> selfRef = new AtomicReference<>();
private SchemaService globalSchema;
private static boolean newDraft;
}
public static MountPointSwagger getInstance() {
- MountPointSwagger swagger = selfRef.get();
+ MountPointSwagger swagger = SELF_REF.get();
if (swagger == null) {
- selfRef.compareAndSet(null, new MountPointSwagger());
- swagger = selfRef.get();
+ SELF_REF.compareAndSet(null, new MountPointSwagger());
+ swagger = SELF_REF.get();
}
newDraft = false;
return swagger;
}
public static MountPointSwagger getInstanceDraft18() {
- MountPointSwagger swagger = selfRef.get();
+ MountPointSwagger swagger = SELF_REF.get();
if (swagger == null) {
- selfRef.compareAndSet(null, new MountPointSwagger());
- swagger = selfRef.get();
+ SELF_REF.compareAndSet(null, new MountPointSwagger());
+ swagger = SELF_REF.get();
}
newDraft = true;
return swagger;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#522-api-object"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#522-api
- * -object</a>)
+ * -object</a>).
*/
public class Api {
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-declaration"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-
- * declaration</a>)
+ * declaration</a>).
*/
public class ApiDeclaration {
private String apiVersion;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#523-operation-object"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#523-
- * operation-object</a>)
+ * operation-object</a>).
*/
public class Operation {
private String method;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-parameter-object"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-
- * parameter-object</a>)
+ * parameter-object</a>).
*/
public class Parameter {
private String name;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512-resource-object"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512-
- * resource-object</a>)
+ * resource-object</a>).
*/
public class Resource {
private String path;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-resource-listing"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-
- * resource-listing</a>)
+ * resource-listing</a>).
*/
public class ResourceList {
private String apiVersion;
* Implementation of swagger spec (see <a href=
* "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#525-response-message-object"
* > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#525-
- * response-message-object</a>)
+ * response-message-object</a>).
*/
public class ResponseMessage {
private int code;
private RestDocgenUtil() {
}
- private static final Map<URI, Map<Date, Module>> namespaceAndRevisionToModule = new HashMap<>();
+ private static final Map<URI, Map<Date, Module>> NAMESPACE_AND_REVISION_TO_MODULE = new HashMap<>();
/**
* Resolve path argument name for {@code node}.
final URI namespace = node.getQName().getNamespace();
final Date revision = node.getQName().getRevision();
- Map<Date, Module> revisionToModule = namespaceAndRevisionToModule.get(namespace);
+ Map<Date, Module> revisionToModule = NAMESPACE_AND_REVISION_TO_MODULE.get(namespace);
if (revisionToModule == null) {
revisionToModule = new HashMap<>();
- namespaceAndRevisionToModule.put(namespace, revisionToModule);
+ NAMESPACE_AND_REVISION_TO_MODULE.put(namespace, revisionToModule);
}
Module module = revisionToModule.get(revision);
if (module == null) {
}
/**
- * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo)
+ * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo).
*/
@Test
public void testGetModuleDoc() throws Exception {
final Api cont1Api = findApi("/config/toaster2:lst/cont1", doc);
assertNotNull("Api /config/toaster2:lst/cont1 wasn't found", cont1Api);
assertTrue("POST for cont11 in cont1 is missing",
- findOperation(cont1Api.getOperations(), "POST", "(config)cont1POST", "toaster2/lst/cont1(config)cont11-TOP",
- "toaster2/lst/cont1(config)lst11-TOP"));
+ findOperation(cont1Api.getOperations(), "POST", "(config)cont1POST", "toaster2/lst/cont1(config)cont11-TOP",
+ "toaster2/lst/cont1(config)lst11-TOP"));
// no POST URI
final Api cont11Api = findApi("/config/toaster2:lst/cont1/cont11", doc);
}
/**
- * Tries to find operation with name {@code operationName} and with summary {@code summary}
+ * Tries to find operation with name {@code operationName} and with summary {@code summary}.
*/
private boolean findOperation(final List<Operation> operations, final String operationName, final String type,
final String... searchedParameters) {
}
/**
- * Tries to find {@code Api} with path {@code path}
+ * Tries to find {@code Api} with path {@code path}.
*/
private Api findApi(final String path, final ApiDeclaration doc) {
for (final Api api : doc.getApis()) {
// testing bugs.opendaylight.org bug 1290. UnionType model type.
final String jsonString = doc.getModels().toString();
- assertTrue(jsonString.contains(
- "testUnion\":{\"type\":\"-2147483648\",\"required\":false,\"enum\":[\"-2147483648\",\"Some testUnion\"]}"));
+ assertTrue(jsonString.contains("testUnion\":{\"type\":\"-2147483648\",\"required\":false,"
+ + "\"enum\":[\"-2147483648\",\"Some testUnion\"]}"));
}
}
}
final JSONObject models = doc.getModels();
final JSONObject inputTop = models.getJSONObject("(make-toast)input-TOP");
- final String testString = "{\"toaster:input\":{\"type\":\"object\",\"items\":{\"$ref\":\"(make-toast)input\"}}}";
+ final String testString =
+ "{\"toaster:input\":{\"type\":\"object\",\"items\":{\"$ref\":\"(make-toast)input\"}}}";
assertEquals(testString, inputTop.getJSONObject("properties").toString());
final JSONObject input = models.getJSONObject("(make-toast)input");
final JSONObject properties = input.getJSONObject("properties");
/**
* Tests whether from yang files are generated all required paths for HTTP operations (GET, DELETE, PUT, POST)
*
+ * <p>
* If container | list is augmented then in path there should be specified module name followed with collon (e. g.
* "/config/module1:element1/element2/module2:element3")
*
- * @param doc
- * @throws Exception
+ * @param doc Api declaration
+ * @throws Exception if operation fails
*/
private void validateToaster(final ApiDeclaration doc) throws Exception {
final Set<String> expectedUrls = new TreeSet<>(Arrays.asList(new String[]{"/config/toaster2:toaster",
- "/operational/toaster2:toaster", "/operations/toaster2:cancel-toast",
- "/operations/toaster2:make-toast", "/operations/toaster2:restock-toaster",
- "/config/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo"}));
+ "/operational/toaster2:toaster", "/operations/toaster2:cancel-toast",
+ "/operations/toaster2:make-toast", "/operations/toaster2:restock-toaster",
+ "/config/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo"}));
final Set<String> actualUrls = new TreeSet<>();
public class MountPointSwaggerTest {
private static final String HTTP_URL = "http://localhost/path";
- private static final YangInstanceIdentifier instanceId = YangInstanceIdentifier.builder()
+ private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
.node(QName.create("nodes"))
.node(QName.create("node"))
.nodeWithKey(QName.create("node"), QName.create("id"), "123").build();
final UriInfo mockInfo = setUpSwaggerForDocGeneration();
assertEquals(0, this.swagger.getInstanceIdentifiers().size());
- this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+ this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
// mount points
assertEquals(1, this.swagger.getInstanceIdentifiers().size());
assertEquals((Long) 1L, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
.getValue());
assertEquals(INSTANCE_URL, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
.getKey());
- this.swagger.onMountPointRemoved(instanceId); // remove ID from list of mount
+ this.swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount
// points
assertEquals(0, this.swagger.getInstanceIdentifiers().size());
}
@Test
public void testGetResourceListGoodId() throws Exception {
final UriInfo mockInfo = setUpSwaggerForDocGeneration();
- this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+ this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
// mount points
final ResourceList resourceList = this.swagger.getResourceList(mockInfo, 1L);
@Test
public void testGetDataStoreApi() throws Exception {
final UriInfo mockInfo = setUpSwaggerForDocGeneration();
- this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+ this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
// mount points
final ApiDeclaration mountPointApi = this.swagger.getMountPointApi(mockInfo, 1L, "Datastores", "-");
.getNotes());
}
final Set<String> expectedApis = new TreeSet<>(Arrays.asList(new String[] {
- "/config" + INSTANCE_URL + "yang-ext:mount",
- "/operational" + INSTANCE_URL + "yang-ext:mount",
- "/operations" + INSTANCE_URL + "yang-ext:mount",}));
+ "/config" + INSTANCE_URL + "yang-ext:mount",
+ "/operational" + INSTANCE_URL + "yang-ext:mount",
+ "/operations" + INSTANCE_URL + "yang-ext:mount",}));
assertEquals(expectedApis, actualApis);
}
when(mountPoint.getSchemaContext()).thenReturn(context);
final DOMMountPointService service = mock(DOMMountPointService.class);
- when(service.getMountPoint(instanceId)).thenReturn(Optional.of(mountPoint));
+ when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
this.swagger.setMountService(service);
this.swagger.setGlobalSchema(schemaService);