1212import java .util .Objects ;
1313
1414import org .apache .maven .cli .MavenCli ;
15+ import org .hibernate .tool .api .version .Version ;
16+ import org .junit .jupiter .api .BeforeAll ;
1517import org .junit .jupiter .api .Test ;
1618import org .junit .jupiter .api .io .TempDir ;
1719
1820public class TransformHbmTestIT {
1921
2022 public static final String MVN_HOME = "maven.multiModuleProjectDirectory" ;
23+ private static File baseFolder ;
24+ private static File localRepo ;
2125
2226 @ TempDir
2327 private Path projectPath ;
2428
29+ @ BeforeAll
30+ public static void beforeAll () throws Exception {
31+ // The needed resource for this test are put in place
32+ // in the 'baseFolder' (normally 'target/test-classes')
33+ // by the 'build-helper-maven-plugin' execution.
34+ // See the 'pom.xml'
35+ baseFolder = determineBaseFolder ();
36+ localRepo = new File (baseFolder .getParentFile (), "local-repo" );
37+ }
2538 @ Test
2639 public void testSimpleHbmTransformation () throws Exception {
2740 System .setProperty (MVN_HOME , projectPath .toAbsolutePath ().toString ());
2841 writePomFile ();
29- copyHbmFile ();
30-
42+ copyHbmFile ();
3143 runTransformHbmToOrm ();
3244 }
3345
@@ -51,16 +63,29 @@ private void copyHbmFile() throws Exception {
5163 assertTrue (destinationFile .exists ());
5264 }
5365
54- private void runTransformHbmToOrm () {
66+ private void runTransformHbmToOrm () throws Exception {
5567 File destinationDir = new File (projectPath .toFile (), "src/main/resources/" );
5668 File ormXmlFile = new File (destinationDir , "simple.mapping.xml" );
5769 assertFalse (ormXmlFile .exists ());
5870 new MavenCli ().doMain (
59- new String []{"org.hibernate.tool:hibernate-tools-maven:7.2.0.CR2:hbm2orm" , "generate-sources" },
71+ new String []{
72+ "-Dmaven.repo.local=" + localRepo .getAbsolutePath (),
73+ "org.hibernate.tool:hibernate-tools-maven:" + Version .versionString () + ":hbm2orm" ,
74+ "generate-sources" },
6075 projectPath .toAbsolutePath ().toString (),
6176 null ,
6277 null );
78+ // Check the existaence of the transformed file
6379 assertTrue (ormXmlFile .exists ());
80+ // Check if it's pretty printed
81+ assertTrue (Files .readString (ormXmlFile .toPath ()).contains ("\n <table name=\" Foo\" />\n " ));
82+ }
83+
84+ private static File determineBaseFolder () throws Exception {
85+ URL classUrl = TransformHbmTestIT .class .getResource (
86+ "/" + TransformHbmTestIT .class .getName ().replace ("." , "/" ) + ".class" );
87+ return new File (classUrl .toURI ())
88+ .getParentFile ().getParentFile ().getParentFile ().getParentFile ().getParentFile ();
6489 }
6590
6691 private static final String simplePomContents =
0 commit comments