Skip to content

Commit

Permalink
Rename CLI class
Browse files Browse the repository at this point in the history
  • Loading branch information
aneeshafedo committed Jul 11, 2023
1 parent ed28359 commit 77c1e74
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
name = "test_openapi",
description = "Generate the Ballerina sources for a given OpenAPI definition and vice versa."
)
public class OpenApiCmd implements BLauncherCmd {
public class TestOpenApiCmd implements BLauncherCmd {
private static final String CMD_NAME = "test_openapi";
private PrintStream outStream;
private Path executionPath = Paths.get(System.getProperty("user.dir"));
Expand Down Expand Up @@ -121,17 +121,17 @@ public class OpenApiCmd implements BLauncherCmd {
@CommandLine.Parameters
private List<String> argList;

public OpenApiCmd() {
public TestOpenApiCmd() {
this.outStream = System.err;
this.executionPath = Paths.get(System.getProperty("user.dir"));
this.exitWhenFinish = true;
}

public OpenApiCmd(PrintStream outStream, Path executionDir) {
new OpenApiCmd(outStream, executionDir, true);
public TestOpenApiCmd(PrintStream outStream, Path executionDir) {
new TestOpenApiCmd(outStream, executionDir, true);
}

public OpenApiCmd(PrintStream outStream, Path executionDir, boolean exitWhenFinish) {
public TestOpenApiCmd(PrintStream outStream, Path executionDir, boolean exitWhenFinish) {
this.outStream = outStream;
this.executionPath = executionDir;
this.exitWhenFinish = exitWhenFinish;
Expand Down Expand Up @@ -425,7 +425,9 @@ public String getName() {

@Override
public void printLongDesc(StringBuilder out) {
InputStream inputStream = ClassLoader.getSystemResourceAsStream("ballerina-openapi.help");
Class<?> clazz = TestOpenApiCmd.class;
ClassLoader classLoader = clazz.getClassLoader();
InputStream inputStream = classLoader.getSystemResourceAsStream("ballerina-openapi.help");
try (InputStreamReader inputStreamREader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(inputStreamREader)) {
String content = br.readLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.ballerina.openapi.cmd.OpenApiCmd
io.ballerina.openapi.cmd.TestOpenApiCmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setupBallerinaProject() throws IOException {
public void testClientGeneration() throws IOException {
Path petstoreYaml = resourceDir.resolve(Paths.get("petstore.yaml"));
String[] args = {"--input", petstoreYaml.toString(), "-o", this.tmpDir.toString(), "--mode", "client"};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);
cmd.execute();

Expand All @@ -72,7 +72,7 @@ public void testClientGeneration() throws IOException {
public void testServiceTypeGeneration() throws IOException {
Path petstoreYaml = resourceDir.resolve(Paths.get("petstore.yaml"));
String[] args = {"--input", petstoreYaml.toString(), "-o", this.tmpDir.toString(), "--with-service-type"};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);
cmd.execute();

Expand All @@ -99,7 +99,7 @@ public void testServiceGeneration() throws IOException {
Path petstoreYaml = resourceDir.resolve(Paths.get("petstore.yaml"));
String[] args = {"--input", petstoreYaml.toString(), "-o", this.tmpDir.toString(), "--with-service-type",
"--mode", "service"};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);
cmd.execute();

Expand All @@ -123,7 +123,7 @@ public void testServiceGeneration() throws IOException {
public void testBothClientServiceGeneration() throws IOException {
Path petstoreYaml = resourceDir.resolve(Paths.get("petstore.yaml"));
String[] args = {"--input", petstoreYaml.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);
cmd.execute();

Expand Down Expand Up @@ -151,7 +151,7 @@ public void testUserGivenLicenseHeader() throws IOException {
Path licenseHeader = resourceDir.resolve(Paths.get("expected_gen/licenses/license.txt"));
String[] args = {"--input", petstoreYaml.toString(), "-o", this.tmpDir.toString(), "--license",
licenseHeader.toString(), "--with-service-type"};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);
cmd.execute();
if (Files.exists(this.tmpDir.resolve("client.bal")) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setupBallerinaProject() throws IOException {
public void testBallerinaToOpenAPIGeneration() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/ballerina-file.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -65,7 +65,7 @@ public void testBallerinaToOpenAPIGeneration() {
public void testDefaultMethod() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/default_method.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -85,7 +85,7 @@ public void testDefaultMethod() {
public void testDefaultMethod02() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/default_method_02.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -104,7 +104,7 @@ public void testDefaultMethod02() {
public void testHttpResponse() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/http_response.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -128,7 +128,7 @@ public void testHttpResponse() {
public void testHttpRequest() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/http_request.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -146,7 +146,7 @@ public void testHttpRequest() {
public void openapiAnnotationWithContract() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/project_1/service.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -170,7 +170,7 @@ public void openapiAnnotationWithContract() {
public void openapiAnnotationWithOutContract() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/project_2/service.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand All @@ -193,7 +193,7 @@ public void openapiAnnotationWithOutContract() {
public void openapiAnnotationWithoutFields() {
Path filePath = resourceDir.resolve(Paths.get("cmd/ballerina-to-openapi/project_3/service.bal"));
String[] args = {"--input", filePath.toString(), "-o", this.tmpDir.toString()};
OpenApiCmd cmd = new OpenApiCmd(printStream, tmpDir, false);
TestOpenApiCmd cmd = new TestOpenApiCmd(printStream, tmpDir, false);
new CommandLine(cmd).parseArgs(args);

String output = "";
Expand Down
Loading

0 comments on commit 77c1e74

Please sign in to comment.