2929import freemarker .template .TemplateExceptionHandler ;
3030import org .junit .jupiter .api .AfterEach ;
3131import org .junit .jupiter .api .BeforeEach ;
32- import org .junit .jupiter .api .Disabled ;
3332import org .junit .jupiter .api .Test ;
3433import org .stagemonitor .configuration .ConfigurationOption ;
3534import org .stagemonitor .configuration .ConfigurationOptionProvider ;
4140import java .nio .file .Files ;
4241import java .nio .file .Path ;
4342import java .nio .file .Paths ;
43+ import java .util .ArrayList ;
44+ import java .util .Arrays ;
4445import java .util .Iterator ;
4546import java .util .List ;
4647import java .util .Map ;
5152import java .util .stream .Collectors ;
5253
5354import static org .assertj .core .api .Assertions .assertThat ;
55+ import static org .assertj .core .api .Assertions .fail ;
5456import static org .mockito .Mockito .doReturn ;
5557import static org .mockito .Mockito .mock ;
5658
@@ -86,7 +88,7 @@ class ConfigurationExporterTest {
8688
8789 @ BeforeEach
8890 void setUp () {
89- renderedDocumentationPath = Paths .get ("../../docs/configuration.asciidoc " );
91+ renderedDocumentationPath = Paths .get ("../../docs/reference/config-reference-properties-file.md " );
9092 ElasticApmTracer tracer = mock (ElasticApmTracer .class );
9193 doReturn (tracer ).when (tracer ).require (ElasticApmTracer .class );
9294 doReturn (ElasticApmTracer .TracerState .UNINITIALIZED ).when (tracer ).getState ();
@@ -108,20 +110,33 @@ void tearDown() {
108110 * Since we allow a limited number of unit-test failures, this test would have always passed without this configuration.
109111 */
110112 @ Test
111- @ Disabled ("Needs migration or update for new docs system" )
112113 void testGeneratedConfigurationDocsAreUpToDate () throws IOException , TemplateException {
113114 String renderedDocumentation = renderDocumentation (configurationRegistry );
114- String expected = new String (Files .readAllBytes (this .renderedDocumentationPath ), StandardCharsets .UTF_8 );
115+
116+ // trim EOL whitespace
117+ List <String > lines = new ArrayList <>(Arrays .asList (renderedDocumentation .split ("\n " )));
118+ for (int i = 0 ; i < lines .size (); i ++) {
119+ lines .set (i , lines .get (i ).replaceAll ("\\ s+$" , "" ));
120+ }
121+ // add extra empty line at end of file
122+ lines .add ("" );
123+ renderedDocumentation = String .join ("\n " , lines );
115124
116125 if (Boolean .parseBoolean (System .getProperty ("elastic.apm.overwrite.config.docs" , Boolean .TRUE .toString ()))) {
117126 // unless explicitly disabled (e.g. on CI) overwrite the current documentation
118127 Files .write (renderedDocumentationPath , renderedDocumentation .getBytes (StandardCharsets .UTF_8 ));
119128 }
120129
130+ if (!Files .exists (this .renderedDocumentationPath )) {
131+ fail ("rendered documentation file does not exists %s" , this .renderedDocumentationPath .toAbsolutePath ());
132+ }
133+
134+ String expected = new String (Files .readAllBytes (this .renderedDocumentationPath ), StandardCharsets .UTF_8 );
135+
121136 assertThat (renderedDocumentation )
122137 .withFailMessage ("The rendered configuration documentation (/docs/configuration.asciidoc) is not up-to-date.\n " +
123138 "If you see this error on CI, it means you have to execute the tests locally " +
124- "(./mvnw -Dsurefire.failIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dtest=ConfigurationExporterTest -pl apm-agent -am clean test) " +
139+ "(./mvnw -Dsurefire.failIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dtest=ConfigurationExporterTest -pl apm-agent-builds/apm-agent -am clean test) " +
125140 "or on Windows(.\\ mvnw \" -Dsurefire.failIfNoTests=false\" \" -Dsurefire.failIfNoSpecifiedTests=false\" -Dtest=ConfigurationExporterTest -pl apm-agent-builds/apm-agent -am clean test) " +
126141 "which will update the rendered docs.\n " +
127142 "If you see this error while running the tests locally, there's nothing more to do - the rendered docs have been updated " +
@@ -136,13 +151,11 @@ static String renderDocumentation(ConfigurationRegistry configurationRegistry) t
136151 cfg .setTemplateExceptionHandler (TemplateExceptionHandler .RETHROW_HANDLER );
137152 cfg .setLogTemplateExceptions (false );
138153
139- Template temp = cfg .getTemplate ("configuration.asciidoc.ftl" );
154+ // trim EOL whitespace
155+ cfg .setWhitespaceStripping (true );
156+
157+ Template temp = cfg .getTemplate ("config-reference-properties-file.md.ftl" );
140158 StringWriter tempRenderedFile = new StringWriter ();
141- tempRenderedFile .write ("////\n " +
142- "This file is auto generated\n " +
143- "\n " +
144- "Please only make changes in configuration.asciidoc.ftl\n " +
145- "////\n " );
146159 final List <ConfigurationOption <?>> nonInternalOptions = configurationRegistry .getConfigurationOptionsByCategory ()
147160 .values ()
148161 .stream ()
0 commit comments