This Java library allows you to automatically create resources in Java.
Define the content of your document in your test source code:
public class MyReportGenerator {
public static void main(final String[] args) {
new AutogeneratedResourceVerifier().verifyResource(Path.of(args[0]), new MyReport());
}
private static class MyReport implements AutogeneratedResource {
@Override
public String generateContent() {
StringBuilder report;
//build your report here
return report.toString();
}
@Override
public Path getPathOfGeneratedFile() {
return Path.of("doc", "generated", "myReport.md");
}
}
}
You can add the execution of your generator to the maven build using the maven-execution-plugin
. To do so add the following lines to your pom.xml
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>validate-capabilities-report</id>
<goals>
<goal>java</goal>
</goals>
<phase>package</phase>
<configuration>
<mainClass>com.example.MyReportGenerator</mainClass> <!-- Add your class here -->
<classpathScope>test</classpathScope>
<systemProperties>
<systemProperty>
<key>projectDir</key>
<value>${project.basedir}</value>
</systemProperty>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
Now you can run the validation using mvn package
.
The verifier can also fix the generated resource. To do so, run:
mvn package -DfixAutogeneratedResources=true