|
| 1 | +package io.zenwave360.sdk.e2e; |
| 2 | + |
| 3 | +import io.zenwave360.sdk.MainGenerator; |
| 4 | +import io.zenwave360.sdk.Plugin; |
| 5 | +import io.zenwave360.sdk.options.DatabaseType; |
| 6 | +import io.zenwave360.sdk.options.PersistenceType; |
| 7 | +import io.zenwave360.sdk.plugins.BackendApplicationDefaultPlugin; |
| 8 | +import io.zenwave360.sdk.plugins.OpenAPIControllersPlugin; |
| 9 | +import io.zenwave360.sdk.plugins.ZDLToOpenAPIPlugin; |
| 10 | +import io.zenwave360.sdk.testutils.MavenCompiler; |
| 11 | +import io.zenwave360.sdk.utils.Maps; |
| 12 | +import org.apache.commons.io.FileUtils; |
| 13 | +import org.junit.jupiter.api.*; |
| 14 | +import org.junit.jupiter.params.ParameterizedTest; |
| 15 | +import org.junit.jupiter.params.provider.CsvSource; |
| 16 | + |
| 17 | +import java.io.File; |
| 18 | +import java.util.List; |
| 19 | +import java.util.Map; |
| 20 | + |
| 21 | +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
| 22 | +public class TestMonolithKlinicalProject { |
| 23 | + static String sourceFolder = "src/test/resources/projects/monolith-clinical-project/"; |
| 24 | + static String targetFolder = "target/projects/monolith-klinical-project"; |
| 25 | + static String basePackage = "com.example.clinical"; |
| 26 | + |
| 27 | + static Map<String, Object> options = Maps.of( |
| 28 | + "title", "Clinical Tool Backend", |
| 29 | + "persistence", PersistenceType.jpa, |
| 30 | + "databaseType", DatabaseType.postgresql, |
| 31 | + "basePackage", basePackage, |
| 32 | + "layout.coreImplementationMappersCommonPackage", "{{commonPackage}}.mappers", |
| 33 | + "layout.infrastructureRepositoryCommonPackage", "{{commonPackage}}", |
| 34 | + "layout.adaptersWebMappersCommonPackage", "{{commonPackage}}.mappers", |
| 35 | + "openApiModelNameSuffix", "DTO", |
| 36 | + "idType", "integer", |
| 37 | + "idTypeFormat", "int64", |
| 38 | + "useLombok", true, |
| 39 | + "includeEmitEventsImplementation", false, |
| 40 | + "haltOnFailFormatting", false |
| 41 | + ); |
| 42 | + |
| 43 | + @BeforeAll |
| 44 | + public static void beforeAll() throws Exception { |
| 45 | + // copy whole dir from sourceFolder to targetFolder |
| 46 | + FileUtils.deleteDirectory(new File(targetFolder)); |
| 47 | + FileUtils.forceMkdir(new File(targetFolder)); |
| 48 | + FileUtils.copyDirectory(new File(sourceFolder), new File(targetFolder)); |
| 49 | + FileUtils.copyFile(new File(sourceFolder + "kotlin-pom.xml"), new File(targetFolder + "/pom.xml")); |
| 50 | + Assertions.assertTrue(new File(targetFolder).exists()); |
| 51 | + } |
| 52 | + |
| 53 | + @ParameterizedTest |
| 54 | + @CsvSource({ |
| 55 | + "clinical.zdl, webapp, getPatientProfileById, ", |
| 56 | + "clinical.zdl, mobile, , 'getPatientProfileById,requestOptOut'", |
| 57 | + "documents.zdl, documents, , ", |
| 58 | + "surveys.zdl, surveys-backoffice, 'getSurveyAndQuestionsForPatient,answerSurvey,updateSurveyAnswers,getSurveyAnswers',", |
| 59 | + "surveys.zdl, surveys-public, , 'getSurveyAndQuestionsForPatient,answerSurvey,updateSurveyAnswers,getSurveyAnswers'", |
| 60 | + "masterdata.zdl, masterdata, , ", |
| 61 | + "terms-and-conditions.zdl, terms-and-conditions, ," |
| 62 | + }) |
| 63 | + @Order(1) |
| 64 | + public void testGenerateOpenAPIs(String zdlFileNames, String webModule, String operationIdsToExclude, String operationIdsToInclude) throws Exception { |
| 65 | + List<String> zdlFiles = List.of(zdlFileNames.split(",")).stream().map(zdlFileName -> targetFolder + "/models/" + zdlFileName).toList(); |
| 66 | + String openApiFile = targetFolder + "/src/main/resources/public/apis/" + webModule + "-openapi.yml"; |
| 67 | + |
| 68 | + Plugin plugin = new ZDLToOpenAPIPlugin() |
| 69 | + .withZdlFiles(zdlFiles) |
| 70 | + .withOption("targetFile", openApiFile) |
| 71 | + .withOptions(options) |
| 72 | + .withOption("operationIdsToExclude", operationIdsToExclude) |
| 73 | + .withOption("operationIdsToInclude", operationIdsToInclude) |
| 74 | + ; |
| 75 | + new MainGenerator().generate(plugin); |
| 76 | + } |
| 77 | + |
| 78 | + @ParameterizedTest |
| 79 | + @CsvSource({ |
| 80 | + "clinical.zdl", |
| 81 | + "documents.zdl", |
| 82 | + "surveys.zdl", |
| 83 | + "masterdata.zdl", |
| 84 | + "terms-and-conditions.zdl" |
| 85 | + }) |
| 86 | + @Order(2) |
| 87 | + public void testGenerateBackendModules(String zdlFile) throws Exception { |
| 88 | + Plugin plugin = new BackendApplicationDefaultPlugin() |
| 89 | + .withZdlFile(targetFolder + "/models/" + zdlFile) |
| 90 | + .withTargetFolder(targetFolder) |
| 91 | + .withOptions(options) |
| 92 | + .withOption("templates", "new io.zenwave360.sdk.plugins.kotlin.BackendApplicationKotlinTemplates"); |
| 93 | + new MainGenerator().generate(plugin); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + @Order(3) |
| 98 | + @Disabled |
| 99 | + public void compileBackendModules() throws Exception { |
| 100 | + int exitCode = MavenCompiler.compile(new File(targetFolder)); |
| 101 | + Assertions.assertEquals(0, exitCode); |
| 102 | + } |
| 103 | + |
| 104 | + @ParameterizedTest |
| 105 | + @CsvSource({ |
| 106 | + "clinical.zdl,webapp-openapi.yml,webapp", |
| 107 | + "clinical.zdl,mobile-openapi.yml,mobile", |
| 108 | + "documents.zdl,documents-openapi.yml,documents", |
| 109 | + "surveys.zdl,surveys-backoffice-openapi.yml,surveys.backoffice", |
| 110 | + "surveys.zdl,surveys-public-openapi.yml,surveys.api", |
| 111 | + "masterdata.zdl,masterdata-openapi.yml,masterdata", |
| 112 | + "terms-and-conditions.zdl,terms-and-conditions-openapi.yml,termsandconditions" |
| 113 | + }) |
| 114 | + @Order(4) |
| 115 | + public void testGenerateControllers(String zdl, String openapi, String webModule) throws Exception { |
| 116 | + String zdlFile = targetFolder + "/models/" + zdl; |
| 117 | + String openApiFile = targetFolder + "/src/main/resources/public/apis/" + openapi; |
| 118 | + |
| 119 | + Plugin plugin = new OpenAPIControllersPlugin() |
| 120 | + .withZdlFile(zdlFile) |
| 121 | + .withApiFile(openApiFile) |
| 122 | + .withTargetFolder(targetFolder) |
| 123 | + .withOptions(options) |
| 124 | + .withOption("customWebModule", "{{basePackage}}.adapters.web." + webModule) |
| 125 | + .withOption("layout.adaptersWebPackage", "{{customWebModule}}") |
| 126 | + .withOption("layout.openApiApiPackage", "{{layout.customWebModule}}") |
| 127 | + .withOption("layout.adaptersWebCommonPackage", "{{basePackage}}.adapters.web.common") |
| 128 | + .withOption("templates", "new io.zenwave360.sdk.plugins.kotlin.OpenAPIControllersKotlinTemplates") |
| 129 | + ; |
| 130 | + new MainGenerator().generate(plugin); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + @Order(5) |
| 135 | + public void fixControllers() throws Exception { |
| 136 | + |
| 137 | + TextUtils.replaceInFile(new File(targetFolder + "/src/main/kotlin/com/example/clinical/adapters/web/masterdata/MasterDataApiController.kt"), |
| 138 | + "masterDataService.listMasterDataOfType\\(type, lang\\)", |
| 139 | + "masterDataService.listMasterDataOfType(MasterDataType.valueOf(type), lang)"); |
| 140 | + |
| 141 | + TextUtils.replaceInFile(new File(targetFolder + "/src/main/kotlin/com/example/clinical/modules/documents/mappers/DocumentServiceMapper.kt"), |
| 142 | + "DocumentInfo asDocumentInfo\\(List<Long> documentIds\\);", |
| 143 | + "default DocumentInfo asDocumentInfo(List<Long> documentIds) { return new DocumentInfo(); }"); |
| 144 | + TextUtils.replaceInFile(new File(targetFolder + "/src/main/kotlin/com/example/clinical/modules/documents/mappers/DocumentServiceMapper.kt"), |
| 145 | + "DocumentInfo update\\(@MappingTarget DocumentInfo entity, List<Long> documentIds\\);", |
| 146 | + " default DocumentInfo update(@MappingTarget DocumentInfo entity, List<Long> documentIds) { return entity; }"); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + @Order(6) |
| 151 | + public void compileControllers() throws Exception { |
| 152 | + int exitCode = MavenCompiler.compile(new File(targetFolder)); |
| 153 | + Assertions.assertEquals(0, exitCode); |
| 154 | + } |
| 155 | + |
| 156 | +} |
0 commit comments