@Test(description = "Test openapi gen-service for successful service generation", enabled = false) public void testSuccessfulServiceGeneration() throws IOException { Path petstoreYaml = RES_DIR.resolve(Paths.get("petstore.yaml")); String[] args = {"-i", petstoreYaml.toString(), "-o", resourcePath.toString()}; OpenApiCmd cmd = new OpenApiCmd(printStream); new CommandLine(cmd).parseArgs(args); String output = ""; try { cmd.execute(); } catch (BLauncherException e) { output = e.getDetailedMessages().get(0); } Path expectedServiceFile = RES_DIR.resolve(Paths.get("expected_gen", "petstore_gen.bal")); Path expectedSchemaFile = RES_DIR.resolve(Paths.get("expected_gen", "petstore_schema.bal")); Stream<String> expectedServiceLines = Files.lines(expectedServiceFile); String expectedServiceContent = expectedServiceLines.collect(Collectors.joining("\n")); expectedServiceLines.close(); Stream<String> expectedSchemaLines = Files.lines(expectedSchemaFile); String expectedSchemaContent = expectedSchemaLines.collect(Collectors.joining("\n")); expectedSchemaLines.close(); if (Files.exists(resourcePath.resolve("petstoreClient.bal")) && Files.exists(resourcePath.resolve("petstoreService.bal")) && Files.exists(resourcePath.resolve("schema.bal"))) { Stream<String> schemaLines = Files.lines(resourcePath.resolve("schema.bal")); String generatedSchema = schemaLines.collect(Collectors.joining("\n")); schemaLines.close(); if (expectedSchemaContent.trim().equals(generatedSchema.trim())) { Assert.assertTrue(true); } else { Assert.fail("Expected content and actual generated content is mismatched for: " + petstoreYaml.toString()); } } else { Assert.fail("Service generation failed."); } }
@Override public void execute() { outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE); if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } if (inputPath) { if (argList == null) { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } String fileName = argList.get(0); if (fileName.endsWith(".yaml") || fileName.endsWith(".json")) { List<String> tag = new ArrayList<>(); List<String> operation = new ArrayList<>(); if (tags != null) { tag.addAll(Arrays.asList(tags.split(","))); } if (operations != null) { operation.addAll(Arrays.asList(operations.split(","))); } Filter filter = new Filter(tag, operation); openApiToBallerina(fileName, filter); } else if (fileName.endsWith(".bal")) { ballerinaToOpenApi(fileName); } else { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } } else { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } }
OpenApiCmd implements BLauncherCmd { @Override public void execute() { outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE); if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } if (inputPath) { if (argList == null) { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } String fileName = argList.get(0); if (fileName.endsWith(".yaml") || fileName.endsWith(".json")) { List<String> tag = new ArrayList<>(); List<String> operation = new ArrayList<>(); if (tags != null) { tag.addAll(Arrays.asList(tags.split(","))); } if (operations != null) { operation.addAll(Arrays.asList(operations.split(","))); } Filter filter = new Filter(tag, operation); openApiToBallerina(fileName, filter); } else if (fileName.endsWith(".bal")) { ballerinaToOpenApi(fileName); } else { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } } else { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } } }
OpenApiCmd implements BLauncherCmd { @Override public void execute() { outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE); if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } if (inputPath) { if (argList == null) { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } String fileName = argList.get(0); if (fileName.endsWith(".yaml") || fileName.endsWith(".json")) { List<String> tag = new ArrayList<>(); List<String> operation = new ArrayList<>(); if (tags != null) { tag.addAll(Arrays.asList(tags.split(","))); } if (operations != null) { operation.addAll(Arrays.asList(operations.split(","))); } Filter filter = new Filter(tag, operation); openApiToBallerina(fileName, filter); } else if (fileName.endsWith(".bal")) { ballerinaToOpenApi(fileName); } else { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } } else { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } } OpenApiCmd();  OpenApiCmd(PrintStream outStream); }
OpenApiCmd implements BLauncherCmd { @Override public void execute() { outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE); if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } if (inputPath) { if (argList == null) { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } String fileName = argList.get(0); if (fileName.endsWith(".yaml") || fileName.endsWith(".json")) { List<String> tag = new ArrayList<>(); List<String> operation = new ArrayList<>(); if (tags != null) { tag.addAll(Arrays.asList(tags.split(","))); } if (operations != null) { operation.addAll(Arrays.asList(operations.split(","))); } Filter filter = new Filter(tag, operation); openApiToBallerina(fileName, filter); } else if (fileName.endsWith(".bal")) { ballerinaToOpenApi(fileName); } else { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } } else { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } } OpenApiCmd();  OpenApiCmd(PrintStream outStream); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder stringBuilder); @Override void setParentCmdParser(CommandLine parentCmdParser); }
OpenApiCmd implements BLauncherCmd { @Override public void execute() { outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE); if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } if (inputPath) { if (argList == null) { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } String fileName = argList.get(0); if (fileName.endsWith(".yaml") || fileName.endsWith(".json")) { List<String> tag = new ArrayList<>(); List<String> operation = new ArrayList<>(); if (tags != null) { tag.addAll(Arrays.asList(tags.split(","))); } if (operations != null) { operation.addAll(Arrays.asList(operations.split(","))); } Filter filter = new Filter(tag, operation); openApiToBallerina(fileName, filter); } else if (fileName.endsWith(".bal")) { ballerinaToOpenApi(fileName); } else { throw LauncherUtils.createLauncherException(OpenApiMesseges.MESSAGE_FOR_MISSING_INPUT); } } else { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName()); outStream.println(commandUsageInfo); return; } } OpenApiCmd();  OpenApiCmd(PrintStream outStream); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder stringBuilder); @Override void setParentCmdParser(CommandLine parentCmdParser);  }