fix: correct scaffold package generation
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 1m38s
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 1m38s
This commit is contained in:
@@ -127,15 +127,13 @@ public class ToolScaffolder {
|
||||
String bizPackage = BASE_PACKAGE + ".biz." + group.toLowerCase();
|
||||
boolean isMci = "MCI".equalsIgnoreCase(routingType);
|
||||
String mciGroupPath = "infra/itrf/mci/" + group.toLowerCase();
|
||||
String clientPkgSuffix = "";
|
||||
String clientPrefixCap = "";
|
||||
Path mciClientDir = null;
|
||||
|
||||
if (isMci && clientSystemCode != null && clientSystemCode.length() == 4) {
|
||||
String clientPrefix = clientSystemCode.toLowerCase();
|
||||
clientPkgSuffix = clientPrefix.substring(0, 3) + "." + clientPrefix.substring(3, 4);
|
||||
clientPrefixCap = toPascalCase(clientSystemCode);
|
||||
mciGroupPath = "infra/itrf/mci/" + clientPrefix.substring(0, 3) + "/" + clientPrefix.substring(3, 4);
|
||||
mciGroupPath = "infra/itrf/mci/" + clientPrefix;
|
||||
mciClientDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, mciGroupPath));
|
||||
}
|
||||
|
||||
@@ -236,11 +234,11 @@ public class ToolScaffolder {
|
||||
|
||||
String toolHintLine;
|
||||
if (useSchemaResource) {
|
||||
toolHintLine = " @ToolHint(register = %s,\n" +
|
||||
" inputSchemaResource = \"%s\",\n" +
|
||||
" outputSchemaResource = \"%s\")".formatted(register, inputSchemaClasspath, outputSchemaClasspath);
|
||||
toolHintLine = (" @ToolHint(register = %s, categoryKey = \"%s\", mappingId = \"%s\",\n" +
|
||||
" inputSchemaResource = \"%s\",\n" +
|
||||
" outputSchemaResource = \"%s\")").formatted(register, group.toLowerCase(Locale.ROOT), interfaceId, inputSchemaClasspath, outputSchemaClasspath);
|
||||
} else {
|
||||
toolHintLine = " @ToolHint(register = %s)".formatted(register);
|
||||
toolHintLine = " @ToolHint(register = %s, categoryKey = \"%s\", mappingId = \"%s\")".formatted(register, group.toLowerCase(Locale.ROOT), interfaceId);
|
||||
}
|
||||
|
||||
String serviceInterfaceContent = """
|
||||
@@ -298,7 +296,6 @@ public class ToolScaffolder {
|
||||
import org.springframework.stereotype.Service;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.Map;
|
||||
import %s.converter.%sConverter;
|
||||
import %s.%s.io.%s_I;
|
||||
%s
|
||||
@@ -382,8 +379,8 @@ public class ToolScaffolder {
|
||||
);
|
||||
String mciIoPackage = BASE_PACKAGE + "." + mciGroupPath.replace("/", ".");
|
||||
serviceImplContent = serviceImplContent
|
||||
.replace("import " + mciIoPackage + "." + interfaceId + "_I;",
|
||||
"import " + mciIoPackage + "." + interfaceId + "_I;\nimport " + mciIoPackage + "." + interfaceId + "_O;")
|
||||
.replace("import " + mciIoPackage + ".io." + interfaceId + "_I;",
|
||||
"import " + mciIoPackage + ".io." + interfaceId + "_I;\nimport " + mciIoPackage + ".io." + interfaceId + "_O;")
|
||||
.replace("Transfer<Object> resTransfer", "Transfer<" + interfaceId + "_O> resTransfer")
|
||||
.replace("Object.class", interfaceId + "_O.class")
|
||||
.replace("response.setResultCode(\"SUCCESS\");",
|
||||
@@ -775,6 +772,17 @@ public class ToolScaffolder {
|
||||
log.append("[Output Schema] ").append(schemaDir.resolve(outputSchemaFileName)).append("\n");
|
||||
}
|
||||
|
||||
Path mockResponsePath = rootDir.resolve(Paths.get(moduleName, "src/main/resources/mock-responses", toolName + ".json"));
|
||||
Files.createDirectories(mockResponsePath.getParent());
|
||||
Files.writeString(mockResponsePath, mockResponseContent(outputFields));
|
||||
|
||||
Path generatedTestDir = rootDir.resolve(Paths.get(moduleName, "src/test/java/io/shinhanlife/dap/mcc/biz", group.toLowerCase(), "usecase"));
|
||||
Files.createDirectories(generatedTestDir);
|
||||
Path generatedTestPath = generatedTestDir.resolve(baseName + "UseCaseTest.java");
|
||||
Files.writeString(generatedTestPath, useCaseTestContent(bizPackage, baseName));
|
||||
log.append("[Mock Response] ").append(mockResponsePath).append("\\n");
|
||||
log.append("[Unit Test] ").append(generatedTestPath).append("\\n");
|
||||
log.append("[Test Command] .\\gradlew.bat :").append(moduleName.substring(moduleName.lastIndexOf(java.io.File.separator) + 1)).append(":test --tests \"*").append(baseName).append("UseCaseTest\"\\n");
|
||||
log.append("\n Tip: ").append(interfaceId).append(" 목업 데이터를 mock-responses.json에 추가하세요.\n");
|
||||
|
||||
return log.toString();
|
||||
@@ -810,7 +818,7 @@ public class ToolScaffolder {
|
||||
private static String mciIoContent(String packageSuffix, String className, List<FieldDefinition> fields,
|
||||
String author, String createDate) {
|
||||
return """
|
||||
package %s.%s;
|
||||
package %s.%s.io;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -865,6 +873,61 @@ public class ToolScaffolder {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static String mockResponseContent(List<FieldDefinition> outputFields) {
|
||||
StringBuilder json = new StringBuilder("{\n");
|
||||
List<FieldDefinition> fields = outputFields == null ? List.of() : outputFields;
|
||||
boolean first = true;
|
||||
for (FieldDefinition field : fields) {
|
||||
if (field.name() == null || field.name().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
json.append(",\n");
|
||||
}
|
||||
json.append(" \"").append(jsonEscape(field.name())).append("\" : ")
|
||||
.append(mockValue(field));
|
||||
first = false;
|
||||
}
|
||||
return json.append("\n}\n").toString();
|
||||
}
|
||||
|
||||
private static String mockValue(FieldDefinition field) {
|
||||
if (field.example() == null || field.example().isBlank()) {
|
||||
return "null";
|
||||
}
|
||||
return switch (supportedType(field.type())) {
|
||||
case "Integer", "Long", "Double", "BigDecimal" -> field.example();
|
||||
case "Boolean" -> Boolean.parseBoolean(field.example()) ? "true" : "false";
|
||||
default -> "\"" + jsonEscape(field.example()) + "\"";
|
||||
};
|
||||
}
|
||||
|
||||
private static String jsonEscape(String value) {
|
||||
return value.replace("\\", "\\\\").replace("\"", "\\\"");
|
||||
}
|
||||
|
||||
private static String useCaseTestContent(String bizPackage, String baseName) {
|
||||
return """
|
||||
package %s.usecase;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import %s.dto.%sRequest;
|
||||
import %s.dto.%sResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class %sUseCaseTest {
|
||||
|
||||
@Test
|
||||
void createsToolRequestAndResponseDtos() {
|
||||
assertNotNull(new %sRequest());
|
||||
assertNotNull(new %sResponse());
|
||||
}
|
||||
}
|
||||
""".formatted(bizPackage, bizPackage, baseName, bizPackage, baseName,
|
||||
baseName, baseName, baseName);
|
||||
}
|
||||
private static String toToolName(String moduleName, String group, String baseName) {
|
||||
String moduleDirectory = Path.of(moduleName).getFileName().toString();
|
||||
String pod = moduleDirectory.startsWith("dap-was-")
|
||||
|
||||
Reference in New Issue
Block a user