Skip to content

Commit 99907c4

Browse files
committed
increased coverage and fixing duplicate issue in sonar
1 parent d11bd37 commit 99907c4

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

boat-scaffold/src/main/java/com/backbase/oss/codegen/java/BoatWebhooksCodeGen.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ public String toApiName(String name) {
127127
}
128128

129129

130+
/**
131+
* Centralizes the handling of configuration booleans and updates additionalProperties accordingly.
132+
*/
133+
private void handleConfigBooleans() {
134+
this.useClassLevelBeanValidation = convertPropertyToBoolean(USE_CLASS_LEVEL_BEAN_VALIDATION);
135+
this.addServletRequest = convertPropertyToBoolean(ADD_SERVLET_REQUEST);
136+
this.addBindingResult = convertPropertyToBoolean(ADD_BINDING_RESULT);
137+
this.useLombokAnnotations = convertPropertyToBoolean(USE_LOMBOK_ANNOTATIONS);
138+
this.useWithModifiers = convertPropertyToBoolean(USE_WITH_MODIFIERS);
139+
this.useProtectedFields = convertPropertyToBoolean(USE_PROTECTED_FIELDS);
140+
141+
this.additionalProperties.put(USE_CLASS_LEVEL_BEAN_VALIDATION, this.useClassLevelBeanValidation);
142+
this.additionalProperties.put(ADD_SERVLET_REQUEST, this.addServletRequest);
143+
this.additionalProperties.put(ADD_BINDING_RESULT, this.addBindingResult);
144+
this.additionalProperties.put(USE_LOMBOK_ANNOTATIONS, this.useLombokAnnotations);
145+
this.additionalProperties.put(USE_WITH_MODIFIERS, this.useWithModifiers);
146+
this.additionalProperties.put(USE_PROTECTED_FIELDS, this.useProtectedFields);
147+
this.additionalProperties.put("modelFieldsVisibility", this.useProtectedFields ? "protected" : "private");
148+
}
149+
130150
@Override
131151
public void processOpts() {
132152
super.processOpts();
@@ -137,7 +157,6 @@ public void processOpts() {
137157
// <supportingFilesToGenerate>ApiUtil.java present or not</supportingFilesToGenerate>
138158
// <generateSupportingFiles>true or false</generateSupportingFiles>
139159
final String supFiles = GlobalSettings.getProperty(CodegenConstants.SUPPORTING_FILES);
140-
// cleared by <generateSuportingFiles>false</generateSuportingFiles>
141160
final boolean useApiUtil = supFiles != null && (supFiles.isEmpty()
142161
? needApiUtil() // set to empty by <generateSuportingFiles>true</generateSuportingFiles>
143162
: supFiles.contains("ApiUtil.java")); // set by <supportingFilesToGenerate/>
@@ -146,37 +165,31 @@ public void processOpts() {
146165
this.supportingFiles
147166
.removeIf(sf -> "apiUtil.mustache".equals(sf.getTemplateFile()));
148167
}
149-
150168
writePropertyBack("useApiUtil", useApiUtil);
151-
152169
final var serializerTemplate = "BigDecimalCustomSerializer";
153170
this.supportingFiles.add(new SupportingFile(
154171
serializerTemplate + MUSTACHE_EXTENSION,
155172
(sourceFolder + File.separator + modelPackage).replace(".", File.separator),
156173
serializerTemplate + JAVA_EXTENSION
157174
));
158-
159-
// Adding Webhook related models to supporting files
160175
final var webhookResponseTemplate = "WebhookResponse";
161176
this.supportingFiles.add(new SupportingFile(webhookResponseTemplate + MUSTACHE_EXTENSION,
162177
(sourceFolder + File.separator + modelPackage).replace(".", File.separator),
163178
webhookResponseTemplate + JAVA_EXTENSION));
164-
165179
final var servletContentTemplate = "ServletContent";
166180
this.supportingFiles.add(new SupportingFile(servletContentTemplate + MUSTACHE_EXTENSION,
167181
(sourceFolder + File.separator + modelPackage).replace(".", File.separator),
168182
servletContentTemplate + JAVA_EXTENSION));
169-
170183
final var posthookRequestTemplate = "PosthookRequest";
171184
this.supportingFiles.add(new SupportingFile(posthookRequestTemplate + MUSTACHE_EXTENSION,
172185
(sourceFolder + File.separator + modelPackage).replace(".", File.separator),
173186
posthookRequestTemplate + JAVA_EXTENSION));
174-
175187
final var prehookRequestTemplate = "PrehookRequest";
176188
this.supportingFiles.add(new SupportingFile(prehookRequestTemplate + MUSTACHE_EXTENSION,
177189
(sourceFolder + File.separator + modelPackage).replace(".", File.separator),
178190
prehookRequestTemplate + JAVA_EXTENSION));
179-
191+
// Centralized config boolean handling
192+
handleConfigBooleans();
180193
this.additionalProperties.put("indent4", new IndentedLambda(4, " ", true, true));
181194
this.additionalProperties.put("newLine4", new BoatSpringCodeGen.NewLineIndent(4, " "));
182195
this.additionalProperties.put("indent8", new IndentedLambda(8, " ", true, true));

boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatWebhooksCodeGenTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import org.apache.commons.io.FileUtils;
1111
import org.junit.jupiter.api.BeforeAll;
1212
import org.junit.jupiter.api.Test;
13-
import org.openapitools.codegen.CodegenModel;;
13+
import org.openapitools.codegen.CodegenModel;
1414
import org.openapitools.codegen.CodegenOperation;
1515
import org.openapitools.codegen.CodegenProperty;
1616
import org.openapitools.codegen.ClientOptInput;
1717
import org.openapitools.codegen.DefaultGenerator;
1818
import org.openapitools.codegen.SupportingFile;
19+
import org.openapitools.codegen.CodegenParameter;
1920

2021
import java.io.File;
2122
import java.io.IOException;
@@ -59,7 +60,7 @@ void newLineIndent() throws IOException {
5960
}
6061

6162
@Test
62-
void addServletRequestTestFromOperation(){
63+
void addServletRequestTestFromOperation() {
6364
final BoatWebhooksCodeGen gen = new BoatWebhooksCodeGen();
6465
gen.addServletRequest = true;
6566
CodegenOperation co = gen.fromOperation("/test", "POST", new Operation(), null);
@@ -103,7 +104,7 @@ void testReplaceBeanValidationCollectionType() {
103104
codegenProperty.baseName = "request"; // not a response
104105

105106
String result = codegen.replaceBeanValidationCollectionType(
106-
codegenProperty,"Set<com.backbase.dbs.arrangement.commons.model.TranslationItemDto>");
107+
codegenProperty, "Set<com.backbase.dbs.arrangement.commons.model.TranslationItemDto>");
107108
assertEquals("Set<@Valid com.backbase.dbs.arrangement.commons.model.TranslationItemDto>", result);
108109
}
109110

@@ -184,7 +185,7 @@ void postProcessModelProperty_shouldNotAddAnnotationForNonBigDecimal() {
184185
CodegenProperty property = new CodegenProperty();
185186
property.baseType = "String";
186187
property.openApiType = "string";
187-
property.dataFormat = "string";
188+
property.dataFormat = "number";
188189

189190
codegen.postProcessModelProperty(model, property);
190191

@@ -221,5 +222,18 @@ void processOpts_shouldRemoveApiUtilSupportingFileWhenNotUsed() {
221222
}
222223
}
223224

225+
@Test
226+
void postProcessParameter_setsBaseTypeForContainer() {
227+
BoatWebhooksCodeGen codeGen = new BoatWebhooksCodeGen();
228+
codeGen.setReactive(false);
229+
CodegenParameter param = new CodegenParameter();
230+
param.isContainer = true;
231+
param.isMap = false;
232+
param.dataType = "List<String>";
233+
param.baseType = null;
224234

235+
codeGen.postProcessParameter(param);
236+
237+
assertEquals("List", param.baseType, "Base type should be extracted from dataType for containers");
238+
}
225239
}

0 commit comments

Comments
 (0)