19
19
import lombok .Setter ;
20
20
import org .springframework .sbm .engine .context .ProjectContext ;
21
21
import org .springframework .sbm .engine .context .ProjectContextHolder ;
22
- import org .springframework .sbm .engine .recipe .Action ;
23
22
import org .springframework .sbm .engine .recipe .Recipe ;
24
23
import org .springframework .sbm .engine .recipe .Recipes ;
25
24
import org .springframework .sbm .project .resource .TestProjectContext ;
29
28
import org .stringtemplate .v4 .ST ;
30
29
31
30
import java .nio .file .Path ;
31
+ import java .util .ArrayList ;
32
32
import java .util .List ;
33
33
import java .util .Map ;
34
34
import java .util .function .Consumer ;
@@ -115,7 +115,7 @@ private void verifyDoesNotRender() {
115
115
if (SectionBuilderData .class .isInstance (builderData )) {
116
116
SectionBuilderData sectionBuilderData = SectionBuilderData .class .cast (builderData );
117
117
withRecipes (recipes -> {
118
- Recipe recipe = recipes .getRecipeByName ("boot-2.7-3.0-upgrade-report2 " ).get ();
118
+ Recipe recipe = recipes .getRecipeByName ("sbu30-report " ).get ();
119
119
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction ) recipe .getActions ().get (0 );
120
120
List <SpringBootUpgradeReportSection > sections = (List <SpringBootUpgradeReportSection >) ReflectionTestUtils .getField (recipe .getActions ().get (0 ), "sections" );
121
121
List <SpringBootUpgradeReportSection > matchingSections = sections
@@ -134,7 +134,7 @@ private void verifyDoesNotRender() {
134
134
} else if (ReportBuilderData .class .isInstance (builderData )) {
135
135
ReportBuilderData reportBuilderData = ReportBuilderData .class .cast (builderData );
136
136
withRecipes (recipes -> {
137
- Recipe recipe = recipes .getRecipeByName ("boot-2.7-3.0-upgrade-report2 " ).get ();
137
+ Recipe recipe = recipes .getRecipeByName ("sbu30-report " ).get ();
138
138
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction ) recipe .apply (reportBuilderData .getContext ()).get (0 );
139
139
bruteForceProjectContextIntoProjectContextHolder (reportBuilderData .getContext (), action );
140
140
List <SpringBootUpgradeReportSection > sections = (List <SpringBootUpgradeReportSection >) ReflectionTestUtils .getField (recipe .getActions ().get (0 ), "sections" );
@@ -159,15 +159,15 @@ private void verify(Consumer<String> assertion) {
159
159
if (ReportBuilderData .class .isInstance (builderData )) {
160
160
ReportBuilderData reportBuilderData = ReportBuilderData .class .cast (builderData );
161
161
withRecipes (recipes -> {
162
- Recipe recipe = recipes .getRecipeByName ("boot-2.7-3.0-upgrade-report2 " ).get ();
162
+ Recipe recipe = recipes .getRecipeByName ("sbu30-report " ).get ();
163
163
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction ) recipe .getActions ().get (0 );
164
164
bruteForceProjectContextIntoProjectContextHolder (builderData .getContext (), action );
165
165
// ReflectionTestUtils.setField(action, "upgradeReportProcessor", (SpringBootUpgradeReportFileSystemRenderer) s -> assertion.accept(s));
166
166
action .apply (reportBuilderData .getContext ());
167
167
});
168
168
} else if (SectionBuilderData .class .isInstance (builderData )) {
169
169
withRecipes (recipes -> {
170
- Recipe recipe = recipes .getRecipeByName ("boot-2.7-3.0-upgrade-report2 " ).get ();
170
+ Recipe recipe = recipes .getRecipeByName ("sbu30-report " ).get ();
171
171
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction ) recipe .getActions ().get (0 );
172
172
bruteForceProjectContextIntoProjectContextHolder (builderData .getContext (), action );
173
173
List <SpringBootUpgradeReportSection > sections = (List <SpringBootUpgradeReportSection >) ReflectionTestUtils .getField (recipe .getActions ().get (0 ), "sections" );
@@ -183,7 +183,7 @@ private void verify(Consumer<String> assertion) {
183
183
SpringBootUpgradeReportSection sectionUnderTest = matchingSections .get (0 );
184
184
action .apply (builderData .getContext ());
185
185
String renderedSection = sectionUnderTest .render (builderData .getContext ());
186
- String renderedSectionWithoutButtonCode = replaceRe4cipeButtonCodeFromExpectedOutput (sectionUnderTest , renderedSection );
186
+ String renderedSectionWithoutButtonCode = replaceRecipeButtonCodeFromExpectedOutput (sectionUnderTest , renderedSection );
187
187
188
188
assertion .accept (renderedSectionWithoutButtonCode );
189
189
});
@@ -194,32 +194,43 @@ private void verify(Consumer<String> assertion) {
194
194
* Another hack, removing the expected button code added to the Asciidoc to free tests from asserting invisible
195
195
* code of buttons to apply a recipe.
196
196
*/
197
- private String replaceRe4cipeButtonCodeFromExpectedOutput (SpringBootUpgradeReportSection sectionUnderTest , String renderedSection ) {
197
+ private String replaceRecipeButtonCodeFromExpectedOutput (SpringBootUpgradeReportSection sectionUnderTest , String renderedSection ) {
198
198
StringBuilder sb = new StringBuilder ();
199
- List <String > buttonCodes = sectionUnderTest
200
- .getRemediation ()
201
- .getPossibilities ()
202
- .stream ()
203
- .filter (p -> p .getRecipe () != null )
204
- .map (RemediationPossibility ::getRecipe )
205
- .map (recipe -> {
206
- String target = """
199
+ List <String > buttonCodes = new ArrayList <>();
200
+ if (sectionUnderTest .getRemediation ().getPossibilities ().isEmpty ()) {
201
+ String recipe = sectionUnderTest .getRemediation ().getRecipe ();
202
+ if (recipe != null ) {
203
+ String target = """
207
204
208
- ++++
209
- <form name="recipe-1" action="http://localhost:8080/spring-boot-upgrade" method="post">
210
- <input type="hidden" name="recipeName" value="<RECIPE>" />
211
- <button name="<RECIPE>" type="submit" style="background-color:#71ea5b;border:width: 120px;
212
- text-align: center;
213
- font-size: 15px;
214
- padding: 20px;
215
- border-radius: 15px;">Run Recipe</button>
216
- </form>
217
- ++++
205
+ ++++
206
+ <div class="run-a-recipe" recipe="<RECIPE>">
207
+ </div>
208
+ ++++
218
209
219
- """ ;
220
- return target .replace ("<RECIPE>" , recipe );
221
- })
222
- .collect (Collectors .toList ());
210
+ """ ;
211
+ buttonCodes .add (target .replace ("<RECIPE>" , recipe ));
212
+ }
213
+ } else {
214
+ buttonCodes = sectionUnderTest
215
+ .getRemediation ()
216
+ .getPossibilities ()
217
+ .stream ()
218
+ .filter (p -> p .getRecipe () != null )
219
+ .map (RemediationPossibility ::getRecipe )
220
+ .map (recipe -> {
221
+ String target = """
222
+
223
+ ++++
224
+ <div class="run-a-recipe" recipe="<RECIPE>">
225
+ </div>
226
+ ++++
227
+
228
+ """ ;
229
+ return target .replace ("<RECIPE>" , recipe );
230
+ })
231
+ .collect (Collectors .toList ());
232
+ }
233
+
223
234
for (String buttonCode : buttonCodes ) {
224
235
renderedSection = renderedSection .replace (buttonCode , "" );
225
236
}
@@ -228,7 +239,7 @@ private String replaceRe4cipeButtonCodeFromExpectedOutput(SpringBootUpgradeRepor
228
239
229
240
private void withRecipes (Consumer <Recipes > recipesConsumer ) {
230
241
RecipeTestSupport .testRecipe (
231
- Path .of ("recipes/boot-new -report.yaml" ), recipesConsumer ,
242
+ Path .of ("recipes/27_30/report/sbu30 -report.yaml" ), recipesConsumer ,
232
243
SpringBootUpgradeReportActionDeserializer .class ,
233
244
SpringBootUpgradeReportFreemarkerSupport .class ,
234
245
SpringBootUpgradeReportFileSystemRenderer .class ,
0 commit comments