forked from loafle/openapi-generator-original
[ci] Update gitattributes and allow skipping docs generation for Windows CI workflows (#7273)
This commit is contained in:
parent
da84d8e3bf
commit
0e9c6dd9a8
29
.gitattributes
vendored
29
.gitattributes
vendored
@ -1 +1,28 @@
|
||||
**/*.mustache linguist-vendored=true
|
||||
* text=auto
|
||||
|
||||
## Windows Specific stuff
|
||||
*.vcproj text eol=crlf
|
||||
*.bat text eol=crlf
|
||||
*.cmd text eol=crlf
|
||||
|
||||
*.txt text eol=lf
|
||||
*.yaml text eol=lf
|
||||
*.yml text eol=lf
|
||||
*.json text eol=lf
|
||||
*.md text eol=lf
|
||||
*.xml text eol=lf
|
||||
gradlew text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.properties text eol=lf
|
||||
*.java text eol=lf
|
||||
.gitignore text eol=lf
|
||||
.gradle text eol=lf
|
||||
.sbt text eol=lf
|
||||
.scala text eol=lf
|
||||
.ts text eol=lf
|
||||
.adoc text eol=lf
|
||||
.svg text eol=lf
|
||||
|
||||
*.mustache text eol=lf linguist-vendored=true
|
||||
*.hbs text eol=lf linguist-vendored=true
|
||||
*.handlebars text eol=lf linguist-vendored=true
|
||||
|
@ -65,7 +65,10 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
os: [ubuntu-latest]
|
||||
include:
|
||||
- os: windows-latest
|
||||
flags: --skip-docs
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
@ -79,4 +82,4 @@ jobs:
|
||||
git config core.fileMode false
|
||||
mkdir -p modules/openapi-generator-cli/target/
|
||||
mv artifact/openapi-generator-cli.jar modules/openapi-generator-cli/target/
|
||||
./bin/utils/ensure-up-to-date
|
||||
./bin/utils/ensure-up-to-date ${{ matrix.flags }}
|
||||
|
@ -19,6 +19,13 @@ if [ $status -ne 0 ]; then
|
||||
exit $status
|
||||
fi
|
||||
|
||||
if [[ "--skip-docs" == "${1}" ]]; then
|
||||
# We export here rather than modify our iterable so that:
|
||||
# - the scripts can show they ran and echo meaningfully
|
||||
# - the scripts can do cleanup (if necessary) when skipped
|
||||
export SKIP_EXPORT_DOCS=true
|
||||
fi
|
||||
|
||||
# Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath)
|
||||
# Docs should always be run, regardless of batch or operation.
|
||||
declare -a always_iterate=(
|
||||
|
@ -5,6 +5,11 @@ echo "# START SCRIPT: ${SCRIPT}"
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [[ "true" == "${SKIP_EXPORT_DOCS}" ]]; then
|
||||
echo "Skipping doc exports. Note that docs generated by Windows may break paths as they have not yet been normalized to OS-specific paths."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for GENERATOR in $(java -jar ${executable} list --short --include all | sed -e 's/,/\'$'\n''/g')
|
||||
do
|
||||
./bin/utils/export_generator.sh ${GENERATOR}
|
||||
|
@ -110,9 +110,6 @@ hs_err_pid*
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
|
168
modules/openapi-generator-gradle-plugin/gradlew.bat
vendored
168
modules/openapi-generator-gradle-plugin/gradlew.bat
vendored
@ -1,84 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
@ -1,100 +1,100 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
@ -1352,7 +1352,9 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
});
|
||||
|
||||
String relativeMeta = METADATA_DIR + File.separator + "VERSION";
|
||||
// NOTE: Don't use File.separator here as we write linux-style paths to FILES, and File.separator will
|
||||
// result in incorrect match on Windows machines.
|
||||
String relativeMeta = METADATA_DIR + "/VERSION";
|
||||
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
|
||||
filesToSort.forEach(f -> {
|
||||
String tmp = outDir.toPath().relativize(f.toPath()).normalize().toString();
|
||||
|
@ -1,152 +1,152 @@
|
||||
package org.openapitools.codegen.asciidoc;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.MockDefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
|
||||
/** unit test asciidoc markup generation against ping.yaml openapi spec. */
|
||||
public class AsciidocGeneratorTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AsciidocGeneratorTest.class);
|
||||
|
||||
@Test
|
||||
public void testPingSpecTitle() throws Exception {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||
|
||||
AsciidocDocumentationCodegen codeGen = new AsciidocDocumentationCodegen();
|
||||
codeGen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(openAPI.getInfo().getTitle(), "ping test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateIndexAsciidocMarkupFileWithAsciidocGenerator() throws Exception {
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY-SNIPPET-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "MY-SPEC-DIR");
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.setGenerateMetadata(false);
|
||||
List<File> generatedFiles = generator.opts(clientOptInput).generate();
|
||||
TestUtils.ensureContainsFile(generatedFiles, output, "index.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateIndexAsciidocMarkupContent() throws Exception {
|
||||
final File output = Files.createTempDirectory("test").toFile();
|
||||
output.mkdirs();
|
||||
output.deleteOnExit();
|
||||
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||
CodegenConfig codegenConfig = new AsciidocDocumentationCodegen();
|
||||
codegenConfig.setOutputDir(output.getAbsolutePath());
|
||||
ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig);
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(clientOptInput).generate();
|
||||
boolean markupFileGenerated = false;
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
// check on some basic asciidoc markup content
|
||||
Assert.assertTrue(markupContent.contains("= ping test"),
|
||||
"expected = header in: " + markupContent.substring(0, 50));
|
||||
Assert.assertTrue(markupContent.contains(":toc: "),
|
||||
"expected = :toc: " + markupContent.substring(0, 50));
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "Default api file is not generated!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdditionalDirectoriesGeneratedIntoHeaderAttributes() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||
|
||||
Map<String, Object> props = new TreeMap<String, Object>();
|
||||
props.put("specDir", "spec");
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
boolean markupFileGenerated = false;
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
Assert.assertTrue(markupContent.contains(":specDir: SPEC-DIR"),
|
||||
"expected :specDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertTrue(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||
"expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeaderAttributesFlagRemovesAttributesFromMarkupHeaderSection() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||
|
||||
Map<String, Object> props = new TreeMap<String, Object>();
|
||||
props.put("specDir", "spec");
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml")
|
||||
.setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.HEADER_ATTRIBUTES_FLAG, "false") // option avoids generation of attributes
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
boolean markupFileGenerated = false;
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
Assert.assertFalse(markupContent.contains(":specDir: SPEC-DIR"),
|
||||
"not expected :specDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||
"not expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":toc:"),
|
||||
"not expected :toc: in: " + markupContent.substring(0, 250)); // typical attributes not found in markup.
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
}
|
||||
|
||||
}
|
||||
package org.openapitools.codegen.asciidoc;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.MockDefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
|
||||
/** unit test asciidoc markup generation against ping.yaml openapi spec. */
|
||||
public class AsciidocGeneratorTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AsciidocGeneratorTest.class);
|
||||
|
||||
@Test
|
||||
public void testPingSpecTitle() throws Exception {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||
|
||||
AsciidocDocumentationCodegen codeGen = new AsciidocDocumentationCodegen();
|
||||
codeGen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(openAPI.getInfo().getTitle(), "ping test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateIndexAsciidocMarkupFileWithAsciidocGenerator() throws Exception {
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY-SNIPPET-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "MY-SPEC-DIR");
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.setGenerateMetadata(false);
|
||||
List<File> generatedFiles = generator.opts(clientOptInput).generate();
|
||||
TestUtils.ensureContainsFile(generatedFiles, output, "index.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateIndexAsciidocMarkupContent() throws Exception {
|
||||
final File output = Files.createTempDirectory("test").toFile();
|
||||
output.mkdirs();
|
||||
output.deleteOnExit();
|
||||
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||
CodegenConfig codegenConfig = new AsciidocDocumentationCodegen();
|
||||
codegenConfig.setOutputDir(output.getAbsolutePath());
|
||||
ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig);
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(clientOptInput).generate();
|
||||
boolean markupFileGenerated = false;
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
// check on some basic asciidoc markup content
|
||||
Assert.assertTrue(markupContent.contains("= ping test"),
|
||||
"expected = header in: " + markupContent.substring(0, 50));
|
||||
Assert.assertTrue(markupContent.contains(":toc: "),
|
||||
"expected = :toc: " + markupContent.substring(0, 50));
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "Default api file is not generated!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdditionalDirectoriesGeneratedIntoHeaderAttributes() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||
|
||||
Map<String, Object> props = new TreeMap<String, Object>();
|
||||
props.put("specDir", "spec");
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
boolean markupFileGenerated = false;
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
Assert.assertTrue(markupContent.contains(":specDir: SPEC-DIR"),
|
||||
"expected :specDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertTrue(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||
"expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeaderAttributesFlagRemovesAttributesFromMarkupHeaderSection() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||
|
||||
Map<String, Object> props = new TreeMap<String, Object>();
|
||||
props.put("specDir", "spec");
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml")
|
||||
.setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.HEADER_ATTRIBUTES_FLAG, "false") // option avoids generation of attributes
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
boolean markupFileGenerated = false;
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
Assert.assertFalse(markupContent.contains(":specDir: SPEC-DIR"),
|
||||
"not expected :specDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||
"not expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":toc:"),
|
||||
"not expected :toc: in: " + markupContent.substring(0, 250)); // typical attributes not found in markup.
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
package org.openapitools.codegen.asciidoc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||
import org.openapitools.codegen.templating.mustache.LambdaTest;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.testng.Assert;
|
||||
|
||||
public class LinkMarkupFilterTest extends LambdaTest {
|
||||
|
||||
@BeforeMethod
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkMarkupFilterDoesNotLinkMissingFile() {
|
||||
|
||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||
final Map<String, Object> ctx = context("link", generator.new LinkMarkupLambda("DOES_NOT_EXIST"));
|
||||
|
||||
final String result = execute("{{#link}}not.an.existing.file.adoc{{/link}}", ctx);
|
||||
Assert.assertTrue(result.contains("// file not found, no"), "unexpected filtered: " + result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkMarkupFilterLinksFoundFileOk() throws IOException {
|
||||
|
||||
File tempFile = File.createTempFile("LinkMarkupFilterTestDummyfile", ".adoc");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||
final Map<String, Object> ctx = context("linkIntoMarkup", generator.new LinkMarkupLambda(tempFile.getParent()));
|
||||
|
||||
final String result = execute("{{#linkIntoMarkup}}my link text, " + tempFile.getName() + "{{/linkIntoMarkup}}",
|
||||
ctx);
|
||||
Assert.assertTrue(result.contains("link:"), "unexpected filtered: " + result);
|
||||
Assert.assertTrue(result.contains(tempFile.getName() + "[]"), "unexpected filtered: " + result);
|
||||
}
|
||||
|
||||
}
|
||||
package org.openapitools.codegen.asciidoc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||
import org.openapitools.codegen.templating.mustache.LambdaTest;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.testng.Assert;
|
||||
|
||||
public class LinkMarkupFilterTest extends LambdaTest {
|
||||
|
||||
@BeforeMethod
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkMarkupFilterDoesNotLinkMissingFile() {
|
||||
|
||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||
final Map<String, Object> ctx = context("link", generator.new LinkMarkupLambda("DOES_NOT_EXIST"));
|
||||
|
||||
final String result = execute("{{#link}}not.an.existing.file.adoc{{/link}}", ctx);
|
||||
Assert.assertTrue(result.contains("// file not found, no"), "unexpected filtered: " + result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkMarkupFilterLinksFoundFileOk() throws IOException {
|
||||
|
||||
File tempFile = File.createTempFile("LinkMarkupFilterTestDummyfile", ".adoc");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||
final Map<String, Object> ctx = context("linkIntoMarkup", generator.new LinkMarkupLambda(tempFile.getParent()));
|
||||
|
||||
final String result = execute("{{#linkIntoMarkup}}my link text, " + tempFile.getName() + "{{/linkIntoMarkup}}",
|
||||
ctx);
|
||||
Assert.assertTrue(result.contains("link:"), "unexpected filtered: " + result);
|
||||
Assert.assertTrue(result.contains(tempFile.getName() + "[]"), "unexpected filtered: " + result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,314 +1,314 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.mysql;
|
||||
|
||||
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class MysqlSchemaCodegenTest {
|
||||
|
||||
@Test
|
||||
public void testGetMysqlMatchedIntegerDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(null, null, null), "INT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-128L, 127L, false), "TINYINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 255L, true), "TINYINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, null), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, true), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, false), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-32768L, 32767L, false), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 65535L, true), "SMALLINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-8388608L, 8388607L, false), "MEDIUMINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 16777215L, true), "MEDIUMINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483648L, 2147483647L, false), "INT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(Long.parseLong(String.valueOf(Integer.MIN_VALUE)), Long.parseLong(String.valueOf(Integer.MAX_VALUE)), false), "INT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967295L, true), "INT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483649L, 2147483648L, false), "BIGINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967296L, true), "BIGINT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMysqlMatchedStringDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(6, 6), "CHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(0, 0), "CHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, 255), "CHAR");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 100), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 255), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(50, 255), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 20), "VARCHAR");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 256), "TEXT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, null), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, 100), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777215), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777215), "MEDIUMTEXT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, null), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, Integer.MAX_VALUE), "LONGTEXT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCodegenMysqlDataTypeArgument() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
String strArgument = "HelloWorld";
|
||||
HashMap<String, Object> strProp = codegen.toCodegenMysqlDataTypeArgument(strArgument, true);
|
||||
Assert.assertTrue((Boolean) strProp.get("isString"));
|
||||
Assert.assertTrue((Boolean) strProp.get("hasMore"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isFloat"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isInteger"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isNumeric"));
|
||||
Assert.assertSame((String) strProp.get("argumentValue"), strArgument);
|
||||
|
||||
Integer intArgument = 10;
|
||||
HashMap<String, Object> intProp = codegen.toCodegenMysqlDataTypeArgument(intArgument, true);
|
||||
Assert.assertFalse((Boolean) intProp.get("isString"));
|
||||
Assert.assertTrue((Boolean) intProp.get("hasMore"));
|
||||
Assert.assertFalse((Boolean) intProp.get("isFloat"));
|
||||
Assert.assertTrue((Boolean) intProp.get("isInteger"));
|
||||
Assert.assertTrue((Boolean) intProp.get("isNumeric"));
|
||||
Assert.assertSame((Integer) intProp.get("argumentValue"), intArgument);
|
||||
|
||||
Double floatArgument = 3.14;
|
||||
HashMap<String, Object> floatProp = codegen.toCodegenMysqlDataTypeArgument(floatArgument, false);
|
||||
Assert.assertFalse((Boolean) floatProp.get("isString"));
|
||||
Assert.assertFalse((Boolean) floatProp.get("hasMore"));
|
||||
Assert.assertTrue((Boolean) floatProp.get("isFloat"));
|
||||
Assert.assertFalse((Boolean) floatProp.get("isInteger"));
|
||||
Assert.assertTrue((Boolean) floatProp.get("isNumeric"));
|
||||
Assert.assertSame((Double) floatProp.get("argumentValue"), floatArgument);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCodegenMysqlDataTypeDefault() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
HashMap<String, Object> defaultMap = null;
|
||||
ArrayList<String> intFixture = new ArrayList<String>(Arrays.asList(
|
||||
"TINYINT", "SmallInt", "Mediumint", "INT", "bigint"
|
||||
));
|
||||
for(String intType : intFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("150", intType);
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "150");
|
||||
}
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("SERIAL DEFAULT VALUE", "TINYINT");
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "SERIAL DEFAULT VALUE");
|
||||
|
||||
ArrayList<String> dateFixture = new ArrayList<String>(Arrays.asList(
|
||||
"Timestamp", "DateTime"
|
||||
));
|
||||
for(String dateType : dateFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", dateType);
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "2018-08-12");
|
||||
}
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("CURRENT_TIMESTAMP", "Timestamp");
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "CURRENT_TIMESTAMP");
|
||||
|
||||
ArrayList<String> restFixture = new ArrayList<String>(Arrays.asList(
|
||||
"VARCHAR", "CHAR", "ENUM", "UNKNOWN"
|
||||
));
|
||||
for(String restType : restFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("sometext", restType);
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "sometext");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testToCodegenMysqlDataTypeDefaultWithExceptionalColumnType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
HashMap<String, Object> defaultMap = null;
|
||||
ArrayList<String> specialFixture = new ArrayList<String>(Arrays.asList(
|
||||
"TINYBLOB", "Blob", "MEDIUMBLOB", "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "GEOMETRY", "JSON"
|
||||
));
|
||||
for(String specialType : specialFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", specialType);
|
||||
Assert.assertNull(defaultMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMysqlDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
ArrayList<String> trueFixture = new ArrayList<String>(Arrays.asList(
|
||||
"INTEGER", "integer", "Integer", "DATETIME", "datetime", "DateTime", "VARCHAR", "varchar", "VarChar", "POINT", "Point", "point", "JSON", "json", "Json"
|
||||
));
|
||||
ArrayList<String> falseFixture = new ArrayList<String>(Arrays.asList(
|
||||
"unknown", "HashMap", "HASHMAP", "hashmap"
|
||||
));
|
||||
for(String trueValue : trueFixture) {
|
||||
Assert.assertTrue(codegen.isMysqlDataType(trueValue), "'" + trueValue + "' isn't MySQL data type");
|
||||
}
|
||||
for(String falseValue : falseFixture) {
|
||||
Assert.assertFalse(codegen.isMysqlDataType(falseValue), "'" + falseValue + "' is MySQL data type");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToMysqlIdentifier() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name", "tbl_", ""), "table_name");
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name ", "tbl_", ""), "table_name");
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("12345678", "tbl_", ""), "tbl_12345678");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testToMysqlIdentifierWithEmptyString() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
codegen.toMysqlIdentifier(" ", "tbl_", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeMysqlUnquotedIdentifier() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_"), "table1Z$_");
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_!#%~&?()*+-./"), "table1Z$_");
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_русскийтекст"), "table1Z$_русскийтекст");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table𐀀"), "table");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name!'()<29>"), "table_name!'()<29>");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name𐌅𐌌 |