forked from loafle/openapi-generator-original
Improve build time (#15566)
* remove java helidon client, server tests (covered in sample tests)
* add new workflow to test java helidon samples
* trigger build
* test jdk 17 only
* Revert "trigger build"
This reverts commit b9528a6588.
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
name: Java Helidon Functional tests
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/**
|
||||
pull_request:
|
||||
paths:
|
||||
- modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/**
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Java Helidon Functional tests
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [11, 17]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: ${{ matrix.java-version }}
|
||||
distribution: 'temurin'
|
||||
- name: Cache maven dependencies
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-maven-repository
|
||||
with:
|
||||
path: |
|
||||
~/.m2/repository
|
||||
~/.gradle
|
||||
!~/.gradle/caches/*/plugin-resolution/
|
||||
!~/.m2/repository/org/openapitools/
|
||||
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
- name: Run unit tests
|
||||
run: cd modules/openapi-generator && mvn --no-snapshot-updates --batch-mode -Dtest="**/functional/*Test" test -Dorg.slf4j.simpleLogger.defaultLogLevel=error
|
||||
env:
|
||||
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
|
||||
- name: Publish unit test reports
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: surefire-test-results
|
||||
path: '**/surefire-reports/TEST-*.xml'
|
||||
41
.github/workflows/samples-java-helidon.yaml
vendored
Normal file
41
.github/workflows/samples-java-helidon.yaml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Samples Java Helidon
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- samples/client/petstore/java-helidon-client/**
|
||||
- samples/server/petstore/java-helidon-server/**
|
||||
pull_request:
|
||||
paths:
|
||||
- samples/client/petstore/java-helidon-client/**
|
||||
- samples/server/petstore/java-helidon-server/**
|
||||
jobs:
|
||||
build:
|
||||
name: Build Java Helidon
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
sample:
|
||||
- samples/client/petstore/java-helidon-client/mp
|
||||
- samples/client/petstore/java-helidon-client/se
|
||||
- samples/server/petstore/java-helidon-server/mp
|
||||
- samples/server/petstore/java-helidon-server/se
|
||||
version: [17]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.version }}
|
||||
- name: Cache maven dependencies
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: maven-repository
|
||||
with:
|
||||
path: |
|
||||
~/.m2
|
||||
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
|
||||
- name: Build
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: mvn clean package
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.openapitools.codegen.java.assertions.JavaFileAssert.assertThat;
|
||||
|
||||
public class JavaHelidonMpClientCodegenTest {
|
||||
|
||||
private String outputPath;
|
||||
private List<File> generatedFiles;
|
||||
|
||||
@BeforeClass
|
||||
public void setup() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
System.out.println("Generating java-helidon-client MP project in " + outputPath);
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java-helidon-client")
|
||||
.setLibrary("mp")
|
||||
.setInputSpec("src/test/resources/3_0/helidon/petstore-no-multipart-for-testing.yaml")
|
||||
.setOutputDir(outputPath);
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.opts(clientOptInput);
|
||||
generatedFiles = generator.generate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPom() {
|
||||
TestUtils.ensureContainsFile(generatedFiles, new File(outputPath), "pom.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPetApi() {
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/PetApi.java"))
|
||||
.assertMethod("addPet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("deletePet", "Long", "String", "Long", "String", "Integer",
|
||||
"List<Integer>", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByStatus", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByTags", "List<Integer>")
|
||||
.toFileAssert()
|
||||
.assertMethod("getPetById", "Long")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePetWithForm", "Long", "String", "String")
|
||||
.toFileAssert();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreApi() {
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/StoreApi.java"))
|
||||
.assertMethod("deleteOrder", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("getInventory")
|
||||
.toFileAssert()
|
||||
.assertMethod("getOrderById", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("placeOrder", "Order")
|
||||
.toFileAssert();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserApi() {
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/UserApi.java"))
|
||||
.assertMethod("createUser", "User")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithArrayInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithListInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("getUserByName", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("loginUser", "String", "String", "String", "Long", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("updateUser", "String", "User")
|
||||
.toFileAssert();
|
||||
}
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon;
|
||||
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
|
||||
|
||||
public class JavaHelidonMpServerCodegenTest {
|
||||
|
||||
private DefaultGenerator generator;
|
||||
private String outputPath;
|
||||
private String apiPackage;
|
||||
private String modelPackage;
|
||||
|
||||
@BeforeMethod
|
||||
public void setup() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
apiPackage = outputPath + "/src/main/java/org/openapitools/server/api";
|
||||
modelPackage = outputPath + "/src/main/java/org/openapitools/server/model";
|
||||
generator = new DefaultGenerator();
|
||||
}
|
||||
|
||||
private CodegenConfigurator createConfigurator() {
|
||||
return new CodegenConfigurator()
|
||||
.setGeneratorName("java-helidon-server")
|
||||
.setLibrary("mp")
|
||||
.setInputSpec("src/test/resources/3_0/helidon/petstore-for-testing.yaml")
|
||||
.setOutputDir(outputPath);
|
||||
}
|
||||
|
||||
private void generate(CodegenConfigurator config) {
|
||||
generator.opts(config.toClientOptInput());
|
||||
generator.setGenerateMetadata(false);
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
generate(createConfigurator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestApiFilesOnly() {
|
||||
generate(createConfigurator().addAdditionalProperty("fullProject", "false"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService");
|
||||
|
||||
File outputFile = Paths.get(outputPath).toFile();
|
||||
assertThat(Objects.requireNonNull(outputFile.listFiles()).length, is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJackson() {
|
||||
generate(createConfigurator().addAdditionalProperty(SERIALIZATION_LIBRARY, "jackson"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(modelPackage + "/Color.java"))
|
||||
.fileContains("com.fasterxml.jackson.annotation.JsonCreator")
|
||||
.fileContains("com.fasterxml.jackson.annotation.JsonValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonb() {
|
||||
generate(createConfigurator().addAdditionalProperty(SERIALIZATION_LIBRARY, "jsonb"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(modelPackage + "/Color.java"))
|
||||
.fileContains(".json.bind.annotation.JsonbCreator");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbstractClass() {
|
||||
generate(createConfigurator().addAdditionalProperty("useAbstractClass", "true"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public abstract class PetService")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.doesNotHaveImplementation();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreService.java"))
|
||||
.fileContains("public abstract class StoreService")
|
||||
.assertMethod("placeOrder", "Order")
|
||||
.doesNotHaveImplementation()
|
||||
.hasReturnType("Order");
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreServiceImpl.java"))
|
||||
.fileContains("public class StoreServiceImpl extends StoreService")
|
||||
.assertMethod("placeOrder", "Order")
|
||||
.hasReturnType("Order")
|
||||
.bodyContainsLines("Order result = null; // Replace with correct business logic.", "return result;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullProject() {
|
||||
generate(createConfigurator().addAdditionalProperty("fullProject", "true"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService")
|
||||
.assertMethod("addPet", "Pet");
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreService.java"))
|
||||
.fileContains("public interface StoreService")
|
||||
.assertMethod("placeOrder", "Order")
|
||||
.hasReturnType("Order");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatePetApi() {
|
||||
generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("org.openapitools.server.model.Pet")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("addPets", "String", "InputStream", "InputStream", "List<String>", "List<Long>", "Integer")
|
||||
.toFileAssert()
|
||||
.assertMethod("deletePet", "Long", "String", "Long", "String", "Integer", "List<Integer>", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByStatus", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByTags", "List<Integer>")
|
||||
.toFileAssert()
|
||||
.assertMethod("getPetById", "Long")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePetWithForm", "Long", "String", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("uploadFile", "Long", "Long", "String", "InputStream");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateStoreApi() {
|
||||
generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreService.java"))
|
||||
.fileContains("org.openapitools.server.model.Order")
|
||||
.assertMethod("deleteOrder", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("getInventory")
|
||||
.toFileAssert()
|
||||
.assertMethod("getOrderById", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("placeOrder", "Order");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateUserApi() {
|
||||
generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/UserService.java"))
|
||||
.fileContains("org.openapitools.server.model.User")
|
||||
.assertMethod("createUser", "User")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithArrayInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithListInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("deleteUser", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("getUserByName", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("loginUser", "String", "String", "String", "Long", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("logoutUser")
|
||||
.toFileAssert()
|
||||
.assertMethod("updateUser", "String", "User");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateGradleProject() {
|
||||
generate(createConfigurator().addAdditionalProperty("gradleProject", "true"));
|
||||
|
||||
assertThat(Paths.get(outputPath + "/build.gradle").toFile().exists(), is(true));
|
||||
assertThat(Paths.get(outputPath + "/settings.gradle").toFile().exists(), is(true));
|
||||
TestUtils.assertFileNotExists(Paths.get(outputPath + "/pom.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnResponse() {
|
||||
generate(createConfigurator().addAdditionalProperty("returnResponse", "true"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.hasReturnType("Response");
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService")
|
||||
.assertMethod("deletePet", "Long", "String", "Long", "String", "Integer", "List<Integer>", "List<String>")
|
||||
.hasReturnType("Response");
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetServiceImpl.java"))
|
||||
.fileContains("public class PetServiceImpl implements PetService")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.hasReturnType("Response")
|
||||
.bodyContainsLines("return Response.ok(/* Pass Pet entity payload */).build(); "
|
||||
+ "// Replace with correct business logic.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportAsync() {
|
||||
generate(createConfigurator().addAdditionalProperty("supportAsync", "true"));
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.hasReturnType("CompletionStage<Pet>");
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java"))
|
||||
.fileContains("public interface PetService")
|
||||
.assertMethod("deletePet", "Long", "String", "Long", "String", "Integer", "List<Integer>", "List<String>")
|
||||
.hasReturnType("CompletionStage<Void>");
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetServiceImpl.java"))
|
||||
.fileContains("public class PetServiceImpl implements PetService")
|
||||
.assertMethod("addPet", "Pet")
|
||||
.hasReturnType("CompletionStage<Pet>")
|
||||
.bodyContainsLines("Pet result = null; // Replace with correct business logic.",
|
||||
"return CompletableFuture.supplyAsync(() -> result);");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022, 2023 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon;
|
||||
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||
import static org.openapitools.codegen.java.assertions.JavaFileAssert.assertThat;
|
||||
|
||||
public class JavaHelidonSeClientCodegenTest {
|
||||
|
||||
private String outputPath;
|
||||
private List<File> generatedFiles;
|
||||
private DefaultGenerator generator;
|
||||
|
||||
@BeforeMethod
|
||||
public void setup() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
System.out.println("Generating java-helidon-client SE project in " + outputPath);
|
||||
|
||||
final CodegenConfigurator configurator = codegenConfigurator(new HashMap<>());
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
generator = new DefaultGenerator();
|
||||
generator.opts(clientOptInput);
|
||||
}
|
||||
|
||||
private CodegenConfigurator codegenConfigurator(Map<String, Object> additionalProperties) {
|
||||
return new CodegenConfigurator()
|
||||
.setGeneratorName("java-helidon-client")
|
||||
.setLibrary("se")
|
||||
.setAdditionalProperties(additionalProperties)
|
||||
.setInputSpec("src/test/resources/3_0/helidon/petstore-no-multipart-for-testing.yaml")
|
||||
.setOutputDir(outputPath);
|
||||
}
|
||||
|
||||
@DataProvider(name = "fileSuffix")
|
||||
public Object[][] fileSuffixes() {
|
||||
return new Object[][] {
|
||||
{""},
|
||||
{"Impl"}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPom() {
|
||||
generatedFiles = generator.generate();
|
||||
TestUtils.ensureContainsFile(generatedFiles, new File(outputPath), "pom.xml");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fileSuffix")
|
||||
public void testPetApi(String fileSuffix) {
|
||||
generatedFiles = generator.generate();
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/PetApi" + fileSuffix + ".java"))
|
||||
.assertMethod("addPet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("deletePet", "Long", "String", "Long", "String", "Integer",
|
||||
"List<Integer>", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByStatus", "List<String>")
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByTags", "List<Integer>")
|
||||
.toFileAssert()
|
||||
.assertMethod("getPetById", "Long")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePet", "Pet")
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePetWithForm", "Long", "String", "String")
|
||||
.toFileAssert();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fileSuffix")
|
||||
public void testStoreApi(String fileSuffix) {
|
||||
generatedFiles = generator.generate();
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/StoreApi" + fileSuffix + ".java"))
|
||||
.assertMethod("deleteOrder", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("getInventory")
|
||||
.toFileAssert()
|
||||
.assertMethod("getOrderById", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("placeOrder", "Order")
|
||||
.toFileAssert();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fileSuffix")
|
||||
public void testUserApi(String fileSuffix) {
|
||||
generatedFiles = generator.generate();
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/api/UserApi" + fileSuffix + ".java"))
|
||||
.assertMethod("createUser", "User")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithArrayInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithListInput", "List<User>")
|
||||
.toFileAssert()
|
||||
.assertMethod("getUserByName", "String")
|
||||
.toFileAssert()
|
||||
.assertMethod("loginUser", "String", "String", "String", "Long", "BigDecimal")
|
||||
.toFileAssert()
|
||||
.assertMethod("updateUser", "String", "User")
|
||||
.toFileAssert();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonbSupport() {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("serializationLibrary", "jsonb");
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/client/ApiClient.java"))
|
||||
.fileContains("JsonbSupport.create(JsonbBuilder.create(jsonbConfig))");
|
||||
assertFileContains(Paths.get(outputPath ,"pom.xml"), "<artifactId>helidon-media-jsonb</artifactId>");
|
||||
}
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.Generator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
public class JavaHelidonSeServerCodegenTest {
|
||||
|
||||
private DefaultGenerator generator;
|
||||
private String outputPath;
|
||||
|
||||
@BeforeMethod
|
||||
public void setup() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
final CodegenConfigurator configurator = codegenConfigurator(new HashMap<>());
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
generator = new DefaultGenerator();
|
||||
generator.opts(clientOptInput);
|
||||
}
|
||||
|
||||
private CodegenConfigurator codegenConfigurator(Map<String, Object> additionalProperties) {
|
||||
return new CodegenConfigurator()
|
||||
.setGeneratorName("java-helidon-server")
|
||||
.setLibrary("se")
|
||||
.setAdditionalProperties(additionalProperties)
|
||||
.setInputSpec("src/test/resources/3_0/helidon/petstore-for-testing.yaml")
|
||||
.setOutputDir(outputPath);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateFullProject() {
|
||||
generator.generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetServiceImpl.java"))
|
||||
.fileContains(
|
||||
"public class PetServiceImpl",
|
||||
"response.status(HTTP_CODE_NOT_IMPLEMENTED).send();"
|
||||
);
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/Main.java"))
|
||||
.fileContains(
|
||||
"import org.openapitools.server.api.PetServiceImpl;",
|
||||
".register(\"/\", new PetServiceImpl())"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateProjectByDefault() {
|
||||
generator.generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.fileContains(
|
||||
"public interface PetService extends Service {",
|
||||
"default void update(Routing.Rules rules) {",
|
||||
"void addPet(ServerRequest request, ServerResponse response, Pet pet);",
|
||||
"void deletePet(ServerRequest request, ServerResponse response);"
|
||||
);
|
||||
TestUtils.assertFileNotExists(Paths.get(outputPath + "/build.gradle"));
|
||||
TestUtils.assertFileNotExists(Paths.get(outputPath + "/settings.gradle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateGradleProject() {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("gradleProject", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
assertTrue(Paths.get(outputPath + "/build.gradle").toFile().exists());
|
||||
assertTrue(Paths.get(outputPath + "/settings.gradle").toFile().exists());
|
||||
TestUtils.assertFileNotExists(Paths.get(outputPath + "/pom.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratePathParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
|
||||
.bodyContainsLines(
|
||||
"Long petId = Optional.ofNullable(request.path().param(\"petId\")).map(Long::valueOf).orElse" +
|
||||
"(null);",
|
||||
"ValidatorUtils.checkNonNull(petId);"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("getPetById")
|
||||
.bodyContainsLines(
|
||||
"Long petId = Optional.ofNullable(request.path().param(\"petId\")).map(Long::valueOf).orElse" +
|
||||
"(null);",
|
||||
"ValidatorUtils.checkNonNull(petId);"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateQueryParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.fileContains("import java.util.List;")
|
||||
.assertMethod("findPetsByTags")
|
||||
.bodyContainsLines(
|
||||
"List<String> tags = Optional.ofNullable(request.queryParams().toMap().get(\"tags\"))" +
|
||||
".orElse(null);",
|
||||
"ValidatorUtils.checkNonNull(tags);"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByStatus")
|
||||
.bodyContainsLines(
|
||||
"List<String> status = Optional.ofNullable(request.queryParams().toMap().get(\"status\")).orElse" +
|
||||
"(null);",
|
||||
"ValidatorUtils.checkNonNull(status);"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateBodyParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("update")
|
||||
.bodyContainsLines(
|
||||
"rules.post(\"/pet\", Handler.create(Pet.class, this::addPet));",
|
||||
"rules.put(\"/pet\", Handler.create(Pet.class, this::updatePet));"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("addPet", "ServerRequest", "ServerResponse", "Pet")
|
||||
.bodyContainsLines(
|
||||
"ValidatorUtils.checkNonNull(pet);",
|
||||
"handleAddPet(request, response, pet);"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("updatePet", "ServerRequest", "ServerResponse", "Pet")
|
||||
.bodyContainsLines(
|
||||
"ValidatorUtils.checkNonNull(pet);",
|
||||
"handleUpdatePet(request, response, pet);"
|
||||
);
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/UserService.java"))
|
||||
.assertMethod("update")
|
||||
.bodyContainsLines(
|
||||
"rules.post(\"/user\", Handler.create(User.class, this::createUser));",
|
||||
"rules.post(\"/user/createWithArray\", this::createUsersWithArrayInput);",
|
||||
"rules.post(\"/user/createWithList\", this::createUsersWithListInput);",
|
||||
"rules.put(\"/user/{username}\", Handler.create(User.class, this::updateUser));"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("createUser", "ServerRequest", "ServerResponse", "User")
|
||||
.bodyContainsLines(
|
||||
"ValidatorUtils.checkNonNull(user);",
|
||||
"handleCreateUser(request, response, user);"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("createUsersWithArrayInput", "ServerRequest", "ServerResponse")
|
||||
.bodyContainsLines(
|
||||
"Single.create(request.content().as(new GenericType<List<User>>() { }))",
|
||||
".thenAccept(user -> {",
|
||||
"ValidatorUtils.checkNonNull(user);",
|
||||
"handleCreateUsersWithArrayInput(request, response, user);",
|
||||
".exceptionally(throwable -> handleError(request, response, throwable));"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateHeaderParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
|
||||
.bodyContainsLines(
|
||||
"String apiKey = request.headers().value(\"api_key\").orElse(null);",
|
||||
"Long headerLong = request.headers().value(\"headerLong\").map(Long::valueOf).orElse(null);",
|
||||
"ValidatorUtils.checkNonNull(headerLong);"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateCookiesParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
|
||||
.bodyContainsLines(
|
||||
"String cookieString = request.headers().cookies().toMap().getOrDefault(\"cookieString\", List.of" +
|
||||
"()).stream().findFirst().orElse(null);",
|
||||
"ValidatorUtils.checkNonNull(cookieString);",
|
||||
"Integer cookieInt = request.headers().cookies().toMap().getOrDefault(\"cookieInt\", List.of())" +
|
||||
".stream().findFirst().map(Integer::valueOf).orElse(null);",
|
||||
"List<String> cookieIntArray = Optional.ofNullable(request.headers().cookies().toMap().get" +
|
||||
"(\"cookieIntArray\")).orElse(null);",
|
||||
"List<String> cookieStringArray = Optional.ofNullable(request.headers().cookies().toMap().get" +
|
||||
"(\"cookieStringArray\")).orElse(null);"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateFormParams() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("addPets", "ServerRequest", "ServerResponse")
|
||||
.bodyContainsLines(
|
||||
"Map<String, List<String>> nonFileFormContent = new HashMap<>();",
|
||||
"Map<String, List<InputStream>> fileFormContent = new HashMap<>();",
|
||||
" Single<Void> formSingle = request.content().asStream(ReadableBodyPart.class)",
|
||||
"if (\"images[]\".equals(name)) {",
|
||||
"processFileFormField(name, fileFormContent, part);",
|
||||
"if (\"image\".equals(name)) {",
|
||||
"if (\"titles[]\".equals(name)) {",
|
||||
"processNonFileFormField(name, nonFileFormContent, part);",
|
||||
"if (\"longArray\".equals(name)) {",
|
||||
"if (\"stringParam\".equals(name)) {",
|
||||
"if (\"intParam\".equals(name)) {",
|
||||
"List<InputStream> images = Optional.ofNullable(fileFormContent.get(\"images[]\")).orElse(null);",
|
||||
"InputStream image = Optional.ofNullable(fileFormContent.get(\"image\")).flatMap(list->list" +
|
||||
".stream().findFirst()).orElse(null);",
|
||||
"List<String> titles = Optional.ofNullable(nonFileFormContent.get(\"titles[]\")).orElse(null);",
|
||||
"List<String> longArray = Optional.ofNullable(nonFileFormContent.get(\"longArray\")).orElse(null);",
|
||||
"Integer intParam = Optional.ofNullable(nonFileFormContent.get(\"intParam\")).flatMap(list->list" +
|
||||
".stream().findFirst()).map(Integer::valueOf).orElse(null);"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateParamsValidation() throws IOException {
|
||||
Map<String, Object> additionalProperties = new HashMap<>();
|
||||
additionalProperties.put("useAbstractClass", true);
|
||||
final CodegenConfigurator configurator = codegenConfigurator(additionalProperties);
|
||||
generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
|
||||
.assertMethod("findPetsByStatus")
|
||||
.bodyContainsLines(
|
||||
"ValidatorUtils.checkNonNull(status);",
|
||||
"List<String> status = Optional.ofNullable(request.queryParams().toMap().get(\"status\")).orElse" +
|
||||
"(null);"
|
||||
)
|
||||
.toFileAssert()
|
||||
.assertMethod("findPetsByTags")
|
||||
.bodyContainsLines(
|
||||
"List<String> tags = Optional.ofNullable(request.queryParams().toMap().get(\"tags\")).orElse" +
|
||||
"(null);",
|
||||
"ValidatorUtils.checkNonNull(tags);"
|
||||
);
|
||||
|
||||
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/UserService.java"))
|
||||
.assertMethod("loginUser")
|
||||
.bodyContainsLines(
|
||||
"ValidatorUtils.validatePattern(username, \"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\" +
|
||||
".\\\\-_]*[a-zA-Z0-9]+$\");",
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon.functional;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.languages.JavaHelidonCommonCodegen;
|
||||
import org.testng.SkipException;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
abstract class FunctionalBase {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(FunctionalBase.class.getName());
|
||||
|
||||
private static final String MAVEN_SHIM_TARGET = "libexec/bin/mvn";
|
||||
private static final String MAVEN_HOME_VAR = "MAVEN_HOME";
|
||||
private static final String MVN_HOME_VAR = "MVN_HOME";
|
||||
private static final String PATH_VAR = "PATH";
|
||||
private static final String MAVEN_BINARY_NAME;
|
||||
private static final boolean IS_WINDOWS_OS;
|
||||
private static final List<Map.Entry<Integer, String>> DEFAULT_HELIDON_VERSIONS_FOR_JAVA_VERSIONS = new ArrayList<>();
|
||||
|
||||
protected static final String FULL_PROJECT = "fullProject";
|
||||
protected static final String USE_ABSTRACT_CLASS = "useAbstractClass";
|
||||
|
||||
static {
|
||||
/*
|
||||
The inferred Helidon version for tests is from the entry for which the Java major version does not exceed
|
||||
the current runtime Java major version.
|
||||
|
||||
For example, for Java 8 or 9 or 11: 2.5.3. For Java 13 or later: 3.0.1.
|
||||
*/
|
||||
DEFAULT_HELIDON_VERSIONS_FOR_JAVA_VERSIONS.add(new AbstractMap.SimpleEntry<>(11, "2.5.3"));
|
||||
DEFAULT_HELIDON_VERSIONS_FOR_JAVA_VERSIONS.add(new AbstractMap.SimpleEntry<>(13, "3.0.1"));
|
||||
}
|
||||
|
||||
private String library;
|
||||
private String generatorName;
|
||||
private String inputSpec;
|
||||
protected Path outputPath;
|
||||
|
||||
private Path mvn;
|
||||
|
||||
static {
|
||||
IS_WINDOWS_OS = System.getProperty("os.name", "unknown")
|
||||
.toLowerCase(Locale.ENGLISH)
|
||||
.contains("win");
|
||||
MAVEN_BINARY_NAME = IS_WINDOWS_OS ? "mvn.cmd" : "mvn";
|
||||
}
|
||||
|
||||
protected CodegenConfigurator createConfigurator() {
|
||||
try {
|
||||
return createConfigurator(Files.createTempDirectory("test"));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Can not create temp directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected CodegenConfigurator createConfigurator(Path outputPath) {
|
||||
Objects.requireNonNull(inputSpec);
|
||||
this.outputPath = outputPath;
|
||||
String sanitizedPath = outputPath.toFile()
|
||||
.getAbsolutePath()
|
||||
.replace('\\', '/');
|
||||
return new CodegenConfigurator()
|
||||
.setGeneratorName(generatorName)
|
||||
.setLibrary(library)
|
||||
.setInputSpec(inputSpec)
|
||||
.setOutputDir(sanitizedPath);
|
||||
|
||||
}
|
||||
|
||||
protected void generate(CodegenConfigurator config) {
|
||||
String helidonVersionToUse = chooseHelidonVersion(config);
|
||||
enforceJavaVersion(helidonVersionToUse);
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.opts(config.toClientOptInput());
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
protected void generate() {
|
||||
generate(createConfigurator());
|
||||
}
|
||||
|
||||
protected void generate(String inputSpec) {
|
||||
inputSpec(inputSpec);
|
||||
generate(createConfigurator());
|
||||
}
|
||||
|
||||
protected void generatorName(String generatorName) {
|
||||
this.generatorName = generatorName;
|
||||
}
|
||||
|
||||
protected void library(String library) {
|
||||
this.library = library;
|
||||
}
|
||||
|
||||
protected void inputSpec(String inputSpec) {
|
||||
this.inputSpec = inputSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run maven command with provided arguments.
|
||||
*
|
||||
* @param args maven command arguments
|
||||
* @return a {@link ProcessReader}
|
||||
*/
|
||||
protected ProcessReader runMavenProcess(String... args) {
|
||||
return runMavenProcess(outputPath.toFile(), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run maven command and causes the current thread to wait for {@link Process} to terminate.
|
||||
*
|
||||
* @param args maven command arguments
|
||||
* @return a {@link ProcessReader}
|
||||
*/
|
||||
protected ProcessReader runMavenProcessAndWait(String... args) {
|
||||
ProcessReader process = runMavenProcess(args);
|
||||
process.waitFor(10, TimeUnit.MINUTES);
|
||||
return process;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run maven command in the provided directory.
|
||||
*
|
||||
* @param directory from where the command is executed
|
||||
* @param args maven command arguments
|
||||
* @return a {@link ProcessReader}
|
||||
*/
|
||||
protected ProcessReader runMavenProcess(File directory, String... args) {
|
||||
List<String> command = new ArrayList<>(Collections.singleton(mavenExecutable()));
|
||||
Collections.addAll(command, args);
|
||||
try {
|
||||
Process process = new ProcessBuilder()
|
||||
.directory(directory)
|
||||
.command(command)
|
||||
.start();
|
||||
return new ProcessReader(process);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the {@code mvn} executable. Searches using the following, in order:
|
||||
* <ol>
|
||||
* <li>The {@code MAVEN_HOME} environment variable</li>
|
||||
* <li>The {@code MVN_HOME} environment variable</li>
|
||||
* <li>The {@code PATH} environment variable</li>
|
||||
* </ol>
|
||||
*
|
||||
* @return The path.
|
||||
*/
|
||||
public String mavenExecutable() {
|
||||
if (mvn == null) {
|
||||
Path maven;
|
||||
Optional<Path> path = findExecutableInPath();
|
||||
if (path.isPresent()) {
|
||||
maven = path.get();
|
||||
} else {
|
||||
maven = toMavenExecutable(MAVEN_HOME_VAR);
|
||||
if (maven == null) {
|
||||
maven = toMavenExecutable(MVN_HOME_VAR);
|
||||
}
|
||||
}
|
||||
try {
|
||||
assumeTrue( "Maven not found, test is skipped", maven != null);
|
||||
maven = maven.toRealPath();
|
||||
Path shimmed = maven.getParent().getParent().resolve(MAVEN_SHIM_TARGET);
|
||||
if (Files.exists(shimmed)) {
|
||||
maven = shimmed;
|
||||
}
|
||||
mvn = maven.toRealPath();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
return mvn.toString();
|
||||
}
|
||||
|
||||
private String chooseHelidonVersion(CodegenConfigurator config) {
|
||||
Map<String, Object> unprocessedAdditionalProperties = config.toContext()
|
||||
.getGeneratorSettings()
|
||||
.getAdditionalProperties();
|
||||
if (unprocessedAdditionalProperties.containsKey(JavaHelidonCommonCodegen.HELIDON_VERSION)) {
|
||||
return unprocessedAdditionalProperties.get(JavaHelidonCommonCodegen.HELIDON_VERSION).toString();
|
||||
}
|
||||
String result = inferredHelidonVersion();
|
||||
config.addAdditionalProperty(JavaHelidonCommonCodegen.HELIDON_VERSION, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void enforceJavaVersion(String helidonVersionToUse) {
|
||||
int currentJavaVersion = getCurrentJavaMajorVersion();
|
||||
int requiredJavaVersion = getRequiredJavaVersion(helidonVersionToUse);
|
||||
String errorJavaVersion = String.format(Locale.ROOT, "Java version must be %s, test is skipped", requiredJavaVersion);
|
||||
assumeTrue(errorJavaVersion, currentJavaVersion == requiredJavaVersion);
|
||||
}
|
||||
|
||||
private int getRequiredJavaVersion(String helidonVersionToUse) {
|
||||
return helidonVersionToUse
|
||||
.startsWith("3.") ? 17 : 11;
|
||||
}
|
||||
|
||||
private int getCurrentJavaMajorVersion() {
|
||||
String[] versionElements = System.getProperty("java.version").split("\\.");
|
||||
int firstElement = Integer.parseInt(versionElements[0]);
|
||||
if (firstElement == 1) {
|
||||
return Integer.parseInt(versionElements[1]);
|
||||
} else {
|
||||
return firstElement;
|
||||
}
|
||||
}
|
||||
|
||||
private String inferredHelidonVersion() {
|
||||
int javaMajorVersion = getCurrentJavaMajorVersion();
|
||||
String result = null;
|
||||
for (Map.Entry<Integer, String> javaToHelidonVersionMapping : DEFAULT_HELIDON_VERSIONS_FOR_JAVA_VERSIONS) {
|
||||
if (javaToHelidonVersionMapping.getKey() <= javaMajorVersion) {
|
||||
result = javaToHelidonVersionMapping.getValue();
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
String message = String.format(Locale.ROOT, "Unable to infer Helidon version from current Java major version %d using mapping %s",
|
||||
javaMajorVersion, DEFAULT_HELIDON_VERSIONS_FOR_JAVA_VERSIONS);
|
||||
LOGGER.log(Level.WARNING, message);
|
||||
throw new SkipException(message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an executable in the {@code PATH} environment variable, if present.
|
||||
*
|
||||
* @return The path.
|
||||
*/
|
||||
private Optional<Path> findExecutableInPath() {
|
||||
return Arrays.stream(requireNonNull(System.getenv(PATH_VAR)).split(File.pathSeparator))
|
||||
.map(Paths::get)
|
||||
.map(path -> path.resolve(FunctionalBase.MAVEN_BINARY_NAME))
|
||||
.filter(Files::isExecutable)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private Path toMavenExecutable(String mavenHomeEnvVar) {
|
||||
Path mavenHome = envVarPath(mavenHomeEnvVar);
|
||||
if (mavenHome != null) {
|
||||
if (Files.isDirectory(mavenHome)) {
|
||||
Path executable = mavenHome.resolve("bin").resolve(MAVEN_BINARY_NAME);
|
||||
if (Files.exists(executable) && (IS_WINDOWS_OS || Files.isExecutable(executable))) {
|
||||
return executable;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Path envVarPath(String var) {
|
||||
final String path = System.getenv(var);
|
||||
return path == null ? null : Paths.get(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow junit to skip test without throwing an exception and report tests as failed.
|
||||
*
|
||||
* @param message warning message
|
||||
* @param condition to be checked
|
||||
*/
|
||||
protected static void assumeTrue(String message, boolean condition) {
|
||||
if (!condition) {
|
||||
LOGGER.log(Level.WARNING, message);
|
||||
throw new SkipException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to build project using Maven and verify test output.
|
||||
*
|
||||
* @param jarPath path to expected jar file
|
||||
*/
|
||||
protected void buildAndVerify(String jarPath) {
|
||||
ProcessReader reader = runMavenProcessAndWait("package");
|
||||
Path executableJar = outputPath.resolve(jarPath);
|
||||
String output = reader.readOutputConsole();
|
||||
assertThat(output, containsString("BUILD SUCCESS"));
|
||||
assertThat(output, containsString("Errors: 0"));
|
||||
assertThat(output, containsString("Failures: 0"));
|
||||
assertThat(output, containsString("Skipped: 0"));
|
||||
assertThat(Files.exists(executableJar), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Process} wrapper to read I/O Stream.
|
||||
*/
|
||||
static class ProcessReader {
|
||||
|
||||
private final Process process;
|
||||
private final BufferedReader consoleReader;
|
||||
|
||||
ProcessReader(Process process) {
|
||||
this.process = process;
|
||||
this.consoleReader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public String readOutputConsole() {
|
||||
return consoleReader.lines().collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean waitFor(long timeout, TimeUnit unit) {
|
||||
try {
|
||||
return process.waitFor(timeout, unit);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.java.helidon.functional;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class FunctionalHelidonClientBase extends FunctionalBase {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
generatorName("java-helidon-client");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildPetstore() {
|
||||
generate("src/test/resources/3_0/petstore.yaml");
|
||||
buildAndVerify("target/openapi-java-client.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildPetstoreWithFakeEndpoints() {
|
||||
generate("src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml");
|
||||
buildAndVerify("target/openapi-java-client.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildPetstoreNoMultipart() {
|
||||
generate("src/test/resources/3_0/helidon/petstore-no-multipart-for-testing.yaml");
|
||||
buildAndVerify("target/openapi-java-client.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyFullProjectSemantics() {
|
||||
inputSpec("src/test/resources/3_0/petstore.yaml");
|
||||
|
||||
// Generate project for first time and record pom's timestamp
|
||||
generate(createConfigurator());
|
||||
buildAndVerify("target/openapi-java-client.jar");
|
||||
Path pom1 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom1), is(true));
|
||||
long lastModified = pom1.toFile().lastModified();
|
||||
|
||||
// Re-generate project over same directory with fullProject unspecified
|
||||
generate(createConfigurator(outputPath));
|
||||
Path pom2 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom2), is(true));
|
||||
assertThat(pom2.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject false
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "false"));
|
||||
Path pom3 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom3), is(true));
|
||||
assertThat(pom3.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject true
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "true"));
|
||||
Path pom4 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom4), is(true));
|
||||
assertThat(pom4.toFile().lastModified(), is(not(lastModified))); // overwritten
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon.functional;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
public class FunctionalHelidonMPClientTest extends FunctionalHelidonClientBase {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
library("mp");
|
||||
generatorName("java-helidon-client");
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon.functional;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
|
||||
|
||||
public class FunctionalHelidonMPServerTest extends FunctionalBase {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
library("mp");
|
||||
generatorName("java-helidon-server");
|
||||
inputSpec("src/test/resources/3_0/helidon/petstore-for-testing.yaml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildProjectDefaultOptions() {
|
||||
generate();
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildProjectAbstractClasses() {
|
||||
generate(createConfigurator().addAdditionalProperty(USE_ABSTRACT_CLASS, "true"));
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildFullProject() {
|
||||
generate(createConfigurator().addAdditionalProperty(FULL_PROJECT, "true"));
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyFullProjectSemantics() {
|
||||
// Generate project for first time and record pom's timestamp
|
||||
generate(createConfigurator());
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
Path pom1 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom1), is(true));
|
||||
long lastModified = pom1.toFile().lastModified();
|
||||
|
||||
// Re-generate project over same directory with fullProject unspecified
|
||||
generate(createConfigurator(outputPath));
|
||||
Path pom2 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom2), is(true));
|
||||
assertThat(pom2.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject false
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "false"));
|
||||
Path pom3 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom3), is(true));
|
||||
assertThat(pom3.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject true
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "true"));
|
||||
Path pom4 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom4), is(true));
|
||||
assertThat(pom4.toFile().lastModified(), is(not(lastModified))); // overwritten
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildJsonbProject() {
|
||||
generate(createConfigurator().addAdditionalProperty(SERIALIZATION_LIBRARY, "jsonb"));
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildJacksonProject() {
|
||||
generate(createConfigurator().addAdditionalProperty(SERIALIZATION_LIBRARY, "jackson"));
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022, 2023 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon.functional;
|
||||
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
|
||||
|
||||
public class FunctionalHelidonSEClientTest extends FunctionalHelidonClientBase {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
library("se");
|
||||
generatorName("java-helidon-client");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildJsonbProject() {
|
||||
inputSpec("src/test/resources/3_0/petstore.yaml");
|
||||
generate(createConfigurator().addAdditionalProperty(SERIALIZATION_LIBRARY, "jsonb"));
|
||||
buildAndVerify("target/openapi-java-client.jar");
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* 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.java.helidon.functional;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class FunctionalHelidonSeServerTest extends FunctionalBase {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
library("se");
|
||||
generatorName("java-helidon-server");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildPetstoreWithDefaultOptions() {
|
||||
generate("src/test/resources/3_0/petstore.yaml");
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildPetstoreWithAbstractClasses() {
|
||||
inputSpec("src/test/resources/3_0/petstore.yaml");
|
||||
generate(createConfigurator().addAdditionalProperty(FunctionalBase.USE_ABSTRACT_CLASS, "true"));
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyFullProject() {
|
||||
inputSpec("src/test/resources/3_0/petstore.yaml");
|
||||
|
||||
// Generate project for first time and record pom's timestamp
|
||||
generate(createConfigurator());
|
||||
buildAndVerify("target/openapi-java-server.jar");
|
||||
Path pom1 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom1), is(true));
|
||||
long lastModified = pom1.toFile().lastModified();
|
||||
|
||||
// Re-generate project over same directory with fullProject unspecified
|
||||
generate(createConfigurator(outputPath));
|
||||
Path pom2 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom2), is(true));
|
||||
assertThat(pom2.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject false
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "false"));
|
||||
Path pom3 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom3), is(true));
|
||||
assertThat(pom3.toFile().lastModified(), is(lastModified)); // not overwritten
|
||||
|
||||
// Re-generate project over same directory with fullProject true
|
||||
generate(createConfigurator(outputPath).addAdditionalProperty(FULL_PROJECT, "true"));
|
||||
Path pom4 = outputPath.resolve("pom.xml");
|
||||
assertThat(Files.exists(pom4), is(true));
|
||||
assertThat(pom4.toFile().lastModified(), is(not(lastModified))); // overwritten
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user