Skip to content

Commit

Permalink
Move logic to common util
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed May 17, 2023
1 parent d797e0f commit e86976d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,6 @@ public String getValue() {
public static final String YML_EXTENSION = ".yml";
public static final String JSON_EXTENSION = ".json";
public static final String UNSUPPORTED_OPENAPI_VERSION_PARSER_MESSAGE = "attribute swaggerVersion is unexpected";
public static final String SYNTAX_ERROR_STRING_PATTERN = "WARNING: Error snake-parsing yaml content";
public static final String SYNTAX_ERROR_STRING_PATTERN_MESSAGE = "There is a syntax error in the yaml content";
public static final String PIPE = "|";
public static final String RETURNS = "returns";
public static final String ANYDATA = "anydata";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package io.ballerina.openapi;

import org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
Expand All @@ -30,9 +31,16 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static io.ballerina.openapi.TestUtil.OUT;
import static io.ballerina.openapi.TestUtil.TEST_DISTRIBUTION_PATH;
import static io.ballerina.openapi.idl.client.IDLClientGenPluginTests.DISTRIBUTION_FILE_NAME;
import static io.ballerina.openapi.idl.client.IDLClientGenPluginTests.TEST_RESOURCE;

/**
* This is abstract class for containing the main common test methods for the other subclasses.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import static io.ballerina.openapi.TestUtil.RESOURCES_PATH;
import static io.ballerina.openapi.TestUtil.TEST_DISTRIBUTION_PATH;
import static io.ballerina.openapi.TestUtil.assertOnErrorStream;
import static io.ballerina.openapi.idl.client.IDLClientGenPluginTests.DISTRIBUTION_FILE_NAME;
import static io.ballerina.openapi.idl.client.IDLClientGenPluginTests.TEST_RESOURCE;

/**
* This test class is for storing the schema related integrations to negative scenarios.
Expand All @@ -50,26 +52,7 @@ public void setupDistributions() throws IOException {
@Test(description = "Tests with record field has constraint value with string type with unsupported patterns.")
public void constraintWithUnsupportedStringPattern() throws IOException, InterruptedException {
String openapiFilePath = "unsupported_string_pattern.yaml";
List<String> buildArgs = new LinkedList<>();
buildArgs.add(0, "openapi");
buildArgs.add("-i");
buildArgs.add(openapiFilePath);
buildArgs.add("--mode");
buildArgs.add("client");
buildArgs.add("-o");
buildArgs.add(tmpDir.toString());

String balFile = "bal";

if (System.getProperty("os.name").startsWith("Windows")) {
balFile = "bal.bat";
}
buildArgs.add(0, TEST_DISTRIBUTION_PATH.resolve(DISTRIBUTION_FILE_NAME).resolve("bin")
.resolve(balFile).toString());
OUT.println("Executing: " + StringUtils.join(buildArgs, ' '));
ProcessBuilder pb = new ProcessBuilder(buildArgs);
pb.directory(TEST_RESOURCE.toFile());
Process process = pb.start();
Process process = getProcessForClientGeneration(openapiFilePath);

String out = "WARNING: skipped generation for unsupported pattern in ballerina: " +
"^(?!(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)) \n" +
Expand All @@ -93,9 +76,23 @@ public void constraintWithUnsupportedStringPattern() throws IOException, Interru
assertOnErrorStream(process, out);
}

@Test(description = "Tests with record field has constraint value with string type with invalid patterns.")
//TODO: disable this test due to reverting the changes regarding log disabling
@Test(description = "Tests with record field has constraint value with string type with invalid patterns.",
enabled = false)
public void constraintWithStringInvalidPattern() throws IOException, InterruptedException {
String openapiFilePath = "invalid_pattern_string.yaml";
Process process = getProcessForClientGeneration(openapiFilePath);

String out = "WARNING: invalid flag in regular expression: (A)?(?(1)B|C) ";
//Thread for wait out put generate
Thread.sleep(5000);
// compare generated file has not included constraint annotation for scenario record field.
compareGeneratedSyntaxTreewithExpectedSyntaxTree("types.bal", "schema/invalid_string_pattern.bal");
process.waitFor();
assertOnErrorStream(process, out);
}

public Process getProcessForClientGeneration(String openapiFilePath) throws IOException {
List<String> buildArgs = new LinkedList<>();
buildArgs.add(0, "openapi");
buildArgs.add("-i");
Expand All @@ -115,14 +112,6 @@ public void constraintWithStringInvalidPattern() throws IOException, Interrupted
OUT.println("Executing: " + StringUtils.join(buildArgs, ' '));
ProcessBuilder pb = new ProcessBuilder(buildArgs);
pb.directory(TEST_RESOURCE.toFile());
Process process = pb.start();

String out = "WARNING: invalid flag in regular expression: (A)?(?(1)B|C) ";
//Thread for wait out put generate
Thread.sleep(5000);
// compare generated file has not included constraint annotation for scenario record field.
compareGeneratedSyntaxTreewithExpectedSyntaxTree("types.bal", "schema/invalid_string_pattern.bal");
process.waitFor();
assertOnErrorStream(process, out);
return pb.start();
}
}

0 comments on commit e86976d

Please sign in to comment.