Merge branch 'master' of https://github.com/swagger-api/swagger-codegen into feature/node-promise-cleanup

This commit is contained in:
Kristof Vrolijkx
2016-05-19 20:08:34 +02:00
249 changed files with 12301 additions and 15799 deletions

View File

@@ -20,7 +20,8 @@ public abstract class AbstractIntegrationTest {
protected abstract Map<String, String> configProperties();
@Test
// @wing328: ignore for the time being until we fix the error with the integration test
@Test(enabled = false)
public void generatesCorrectDirectoryStructure() throws IOException {
DefaultGenerator codeGen = new DefaultGenerator();
IntegrationTestPathsConfig integrationTestPathsConfig = getIntegrationTestPathsConfig();

View File

@@ -0,0 +1,21 @@
package io.swagger.codegen.ignore;
import org.testng.annotations.Test;
public class CodegenIgnoreProcessorTest {
@Test
public void loadCodegenRules() throws Exception {
}
@Test
public void getInclusionRules() throws Exception {
}
@Test
public void getExclusionRules() throws Exception {
}
}

View File

@@ -0,0 +1,70 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
public class FileRuleTest {
@Test
public void testMatchComplex() throws Exception {
// Arrange
final String definition = "path/to/**/complex/*.txt";
final String relativePath = "path/to/some/nested/complex/xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ALL),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "complex"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new FileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchComplex() throws Exception {
// Arrange
final String definition = "path/to/**/complex/*.txt";
final String relativePath = "path/to/some/nested/invalid/xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ALL),
new Part(IgnoreLineParser.Token.TEXT, "complex"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new FileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
}

View File

@@ -0,0 +1,158 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import static org.testng.Assert.*;
public class IgnoreLineParserTest {
private IgnoreLineParser.Token verifyInputToSingleToken(final String input, IgnoreLineParser.Token token) throws ParserException {
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertNotNull(result);
assertEquals(result.size(), 1);
IgnoreLineParser.Token actual = result.get(0).getToken();
assertEquals(actual, token);
return actual;
}
@Test
public void parseMatchAll() throws Exception {
verifyInputToSingleToken("**", IgnoreLineParser.Token.MATCH_ALL);
}
@Test
public void parseMatchAny() throws Exception {
verifyInputToSingleToken("*", IgnoreLineParser.Token.MATCH_ANY);
}
@Test(expectedExceptions = ParserException.class,
expectedExceptionsMessageRegExp = "Negation with no negated pattern\\.")
public void parseNegate() throws Exception {
verifyInputToSingleToken("!", IgnoreLineParser.Token.NEGATE);
// Assert
fail("Expected simple pattern '!' to throw a ParserException.");
}
@Test
public void parseComment() throws Exception {
// Arrange
final String input = "# This is a comment";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 1);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.COMMENT);
assertEquals(actual.getValue(), input);
}
@Test
public void parseEscapedExclamation() throws Exception {
final String input = "\\!";
verifyInputToSingleToken(input, IgnoreLineParser.Token.ESCAPED_EXCLAMATION);
}
@Test
public void parseEscapedSpace() throws Exception {
final String input = "\\ ";
verifyInputToSingleToken(input, IgnoreLineParser.Token.ESCAPED_SPACE);
}
@Test
public void parseDirectoryMarker() throws Exception {
// Arrange
final String input = "foo/";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 2);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(actual.getValue(), "foo");
actual = result.get(1);
assertEquals(actual.getToken(), IgnoreLineParser.Token.DIRECTORY_MARKER);
}
@Test
public void parseRooted() throws Exception {
// Arrange
final String input = "/abcd";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 2);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.ROOTED_MARKER);
actual = result.get(1);
assertEquals(actual.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(actual.getValue(), "abcd");
}
@Test
public void parseComplex() throws Exception {
// Arrange
final String input = "**/abcd/**/foo/bar/sample.txt";
Part current = null;
// Act
Queue<Part> result = new LinkedList<>(IgnoreLineParser.parse(input));
// Assert
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.MATCH_ALL);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "abcd");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.MATCH_ALL);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "foo");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "bar");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "sample.txt");
}
@Test(expectedExceptions = ParserException.class,
expectedExceptionsMessageRegExp = "The pattern \\*\\*\\* is invalid\\.")
public void parseTripleStarPattern() throws Exception {
// Arrange
final String input = "should/throw/***/anywhere";
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
fail("Expected pattern containing '***' to throw a ParserException.");
}
}

View File

@@ -0,0 +1,285 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
public class RootedFileRuleTest {
@Test
public void testMatchFilenameOnly() throws Exception {
// Arrange
final String definition = "/foo";
final String relativePath = "foo";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameOnly() throws Exception {
// Arrange
final String definition = "/foo";
final String relativePath = "bar";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtension() throws Exception {
// Arrange
final String definition = "/foo.txt";
final String relativePath = "foo.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtension() throws Exception {
// Arrange
final String definition = "/foo.txt";
final String relativePath = "bar.baz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameWithGlob() throws Exception {
// Arrange
final String definition = "/foo*";
final String relativePath = "foobarbaz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameWithGlob() throws Exception {
// Arrange
final String definition = "/foo*";
final String relativePath = "boobarbaz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtensionWithFilenameGlob() throws Exception {
// Arrange
final String definition = "/foo*.txt";
final String relativePath = "foobarbaz.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtensionWithFilenameGlob() throws Exception {
// Arrange
final String definition = "/foo*qux.txt";
final String relativePath = "foobarbaz.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, "qux.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtensionWithExtensionGlob() throws Exception {
// Arrange
final String definition = "/foo.*";
final String relativePath = "foo.bak";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo."),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testMatchFilenameAndExtensionWithMultiplePeriods() throws Exception {
// Arrange
final String definition = "/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtensionWithMultiplePeriods() throws Exception {
// Arrange
final String definition = "/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.qux.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchWithoutLeadingForwardSlash() throws Exception {
// Arrange
final String definition = "foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testMatchesOnlyRooted() throws Exception {
// Arrange
final String definition = "/path/to/some/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "some"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "oo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
}

View File

@@ -18,6 +18,8 @@ public class PhpClientOptionsProvider implements OptionsProvider {
public static final String SRC_BASE_PATH_VALUE = "libPhp";
public static final String COMPOSER_VENDOR_NAME_VALUE = "swaggerPhp";
public static final String COMPOSER_PROJECT_NAME_VALUE = "swagger-client-php";
public static final String GIT_USER_ID_VALUE = "gitSwaggerPhp";
public static final String GIT_REPO_ID_VALUE = "git-swagger-client-php";
public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT";
@Override
@@ -37,7 +39,9 @@ public class PhpClientOptionsProvider implements OptionsProvider {
.put(PhpClientCodegen.PACKAGE_PATH, PACKAGE_PATH_VALUE)
.put(PhpClientCodegen.SRC_BASE_PATH, SRC_BASE_PATH_VALUE)
.put(PhpClientCodegen.COMPOSER_VENDOR_NAME, COMPOSER_VENDOR_NAME_VALUE)
.put(CodegenConstants.GIT_USER_ID, GIT_USER_ID_VALUE)
.put(PhpClientCodegen.COMPOSER_PROJECT_NAME, COMPOSER_PROJECT_NAME_VALUE)
.put(CodegenConstants.GIT_REPO_ID, GIT_REPO_ID_VALUE)
.put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE)
.build();
}

View File

@@ -42,8 +42,12 @@ public class PhpClientOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setComposerVendorName(PhpClientOptionsProvider.COMPOSER_VENDOR_NAME_VALUE);
times = 1;
clientCodegen.setGitUserId(PhpClientOptionsProvider.GIT_USER_ID_VALUE);
times = 1;
clientCodegen.setComposerProjectName(PhpClientOptionsProvider.COMPOSER_PROJECT_NAME_VALUE);
times = 1;
clientCodegen.setGitRepoId(PhpClientOptionsProvider.GIT_REPO_ID_VALUE);
times = 1;
clientCodegen.setArtifactVersion(PhpClientOptionsProvider.ARTIFACT_VERSION_VALUE);
times = 1;
}};