9
9
import java .nio .file .Files ;
10
10
import java .nio .file .Path ;
11
11
import java .nio .file .Paths ;
12
+ import java .util .Map ;
12
13
import java .util .function .Predicate ;
13
14
14
15
import org .junit .jupiter .api .io .TempDir ;
20
21
import com .sap .cloud .sdk .datamodel .openapi .generator .model .GenerationResult ;
21
22
22
23
import io .vavr .control .Try ;
23
- import lombok .AllArgsConstructor ;
24
24
import lombok .RequiredArgsConstructor ;
25
25
import lombok .SneakyThrows ;
26
26
27
27
class DataModelGeneratorIntegrationTest
28
28
{
29
29
@ RequiredArgsConstructor
30
- @ AllArgsConstructor
31
30
private enum TestCase
32
31
{
33
32
API_CLASS_FOR_AI_SDK (
@@ -38,42 +37,43 @@ private enum TestCase
38
37
ApiMaturity .RELEASED ,
39
38
true ,
40
39
6 ,
41
- null ,
42
- null ,
43
- null ,
44
- "true" ),
40
+ Map .of ("aiSdkConstructor" , "true" )),
45
41
API_CLASS_VENDOR_EXTENSION_YAML (
46
42
"api-class-vendor-extension-yaml" ,
47
43
"sodastore.yaml" ,
48
44
"com.sap.cloud.sdk.services.apiclassvendorextension.api" ,
49
45
"com.sap.cloud.sdk.services.apiclassvendorextension.model" ,
50
46
ApiMaturity .RELEASED ,
51
47
false ,
52
- 4 ),
48
+ 4 ,
49
+ Map .of ()),
53
50
API_CLASS_VENDOR_EXTENSION_JSON (
54
51
"api-class-vendor-extension-json" ,
55
52
"sodastore.json" ,
56
53
"com.sap.cloud.sdk.services.apiclassvendorextension.api" ,
57
54
"com.sap.cloud.sdk.services.apiclassvendorextension.model" ,
58
55
ApiMaturity .RELEASED ,
59
56
false ,
60
- 6 ),
57
+ 6 ,
58
+ Map .of ()),
61
59
INPUT_SPEC_WITH_UPPERCASE_FILE_EXTENSION (
62
60
"input-spec-with-uppercase-file-extension" ,
63
61
"sodastore.JSON" ,
64
62
"com.sap.cloud.sdk.services.uppercasefileextension.api" ,
65
63
"com.sap.cloud.sdk.services.uppercasefileextension.model" ,
66
64
ApiMaturity .RELEASED ,
67
65
false ,
68
- 6 ),
66
+ 6 ,
67
+ Map .of ()),
69
68
INPUT_SPEC_WITH_ANYOF_ONEOF (
70
69
"input-spec-with-anyof-oneof" ,
71
70
"AggregatorNestedSchemaChild.json" ,
72
71
"com.sap.cloud.sdk.services.anyofoneof.api" ,
73
72
"com.sap.cloud.sdk.services.anyofoneof.model" ,
74
73
ApiMaturity .RELEASED ,
75
74
true ,
76
- 7 ),
75
+ 7 ,
76
+ Map .of ()),
77
77
INPUT_SPEC_WITH_BUILDER (
78
78
"input-spec-with-builder" ,
79
79
"sodastore.JSON" ,
@@ -82,10 +82,30 @@ private enum TestCase
82
82
ApiMaturity .RELEASED ,
83
83
true ,
84
84
6 ,
85
- "builder" ,
86
- "build" ,
87
- "private" ,
88
- null ),;
85
+ Map
86
+ .of (
87
+ "pojoBuilderMethodName" ,
88
+ "builder" ,
89
+ "pojoBuildMethodName" ,
90
+ "build" ,
91
+ "pojoConstructorVisibility" ,
92
+ "private" )),
93
+ REMOVE_OPERATION_ID_PREFIX (
94
+ "remove-operation-id-prefix" ,
95
+ "sodastore.json" ,
96
+ "com.sap.cloud.sdk.services.builder.api" ,
97
+ "com.sap.cloud.sdk.services.builder.model" ,
98
+ ApiMaturity .RELEASED ,
99
+ true ,
100
+ 6 ,
101
+ Map
102
+ .of (
103
+ "removeOperationIdPrefix" ,
104
+ "true" ,
105
+ "removeOperationIdPrefixDelimiter" ,
106
+ "\\ ." ,
107
+ "removeOperationIdPrefixCount" ,
108
+ "3" )),;
89
109
90
110
final String testCaseName ;
91
111
final String inputSpecFileName ;
@@ -94,10 +114,7 @@ private enum TestCase
94
114
final ApiMaturity apiMaturity ;
95
115
final boolean anyOfOneOfGenerationEnabled ;
96
116
final int expectedNumberOfGeneratedFiles ;
97
- String methodBuilder = null ;
98
- String methodBuild = null ;
99
- String constructorVisibility = null ;
100
- String aiSdkConstructor = null ;
117
+ final Map <String , String > additionalProperties ;
101
118
}
102
119
103
120
@ ParameterizedTest
@@ -115,7 +132,7 @@ void integrationTests( final TestCase testCase, @TempDir final Path path )
115
132
assertThat (tempOutputDirectory ).exists ().isReadable ().isDirectory ();
116
133
assertThat (comparisonDirectory ).exists ().isReadable ().isDirectory ();
117
134
118
- final GenerationConfiguration generationConfiguration =
135
+ final var generationConfiguration =
119
136
GenerationConfiguration
120
137
.builder ()
121
138
.apiPackage (testCase .apiPackageName )
@@ -125,15 +142,11 @@ void integrationTests( final TestCase testCase, @TempDir final Path path )
125
142
.outputDirectory (tempOutputDirectory .toAbsolutePath ().toString ())
126
143
.withSapCopyrightHeader (true )
127
144
.oneOfAnyOfGenerationEnabled (testCase .anyOfOneOfGenerationEnabled )
128
- .additionalProperty ("useAbstractionForFiles" , "true" )
129
- .additionalProperty ("pojoBuilderMethodName" , testCase .methodBuilder )
130
- .additionalProperty ("pojoBuildMethodName" , testCase .methodBuild )
131
- .additionalProperty ("pojoConstructorVisibility" , testCase .constructorVisibility )
132
- .additionalProperty ("aiSdkConstructor" , testCase .aiSdkConstructor )
133
- .build ();
145
+ .additionalProperty ("useAbstractionForFiles" , "true" );
146
+ testCase .additionalProperties .forEach (generationConfiguration ::additionalProperty );
134
147
135
148
final Try <GenerationResult > maybeGenerationResult =
136
- new DataModelGenerator ().generateDataModel (generationConfiguration );
149
+ new DataModelGenerator ().generateDataModel (generationConfiguration . build () );
137
150
138
151
assertThat (maybeGenerationResult .get ().getGeneratedFiles ()).hasSize (testCase .expectedNumberOfGeneratedFiles );
139
152
@@ -152,7 +165,7 @@ void generateDataModelForComparison( final TestCase testCase )
152
165
assertThat (inputDirectory ).exists ().isReadable ().isDirectory ();
153
166
assertThat (outputDirectory ).exists ().isReadable ().isDirectory ();
154
167
155
- final GenerationConfiguration generationConfiguration =
168
+ final var generationConfiguration =
156
169
GenerationConfiguration
157
170
.builder ()
158
171
.apiPackage (testCase .apiPackageName )
@@ -163,14 +176,11 @@ void generateDataModelForComparison( final TestCase testCase )
163
176
.deleteOutputDirectory (true )
164
177
.withSapCopyrightHeader (true )
165
178
.oneOfAnyOfGenerationEnabled (testCase .anyOfOneOfGenerationEnabled )
166
- .additionalProperty ("useAbstractionForFiles" , "true" )
167
- .additionalProperty ("pojoBuilderMethodName" , testCase .methodBuilder )
168
- .additionalProperty ("pojoBuildMethodName" , testCase .methodBuild )
169
- .additionalProperty ("pojoConstructorVisibility" , testCase .constructorVisibility )
170
- .additionalProperty ("aiSdkConstructor" , testCase .aiSdkConstructor )
171
- .build ();
172
-
173
- new DataModelGenerator ().generateDataModel (generationConfiguration );
179
+ .additionalProperty ("useAbstractionForFiles" , "true" );
180
+ testCase .additionalProperties .forEach (generationConfiguration ::additionalProperty );
181
+
182
+ GenerationConfiguration build = generationConfiguration .build ();
183
+ new DataModelGenerator ().generateDataModel (build );
174
184
}
175
185
176
186
private static Path getInputDirectory ( final TestCase testCase )
0 commit comments