Add a test with a <featureManager> element and improve output.
@@ -19,6 +19,8 @@ import static org.junit.Assert.*;
import java.io.File;
import java.nio.file.Files;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -97,7 +99,7 @@ public class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
}
@Test
- public void serverXmlCommentTest() throws Exception {
+ public void serverXmlCommentNoFMTest() throws Exception {
// initially the expected comment is not found in server.xml
File serverXmlFile = new File(tempProj, "src/main/liberty/config/server.xml");
assertFalse(verifyLogMessageExists(GenerateFeaturesMojo.FEATURES_FILE_MESSAGE, 10, serverXmlFile));
@@ -110,6 +112,35 @@ public class GenerateFeaturesTest extends BaseGenerateFeaturesTest {
assertTrue(newFeatureFile.exists());
// verify expected comment found in server.xml
- assertTrue(verifyLogMessageExists(GenerateFeaturesMojo.FEATURES_FILE_MESSAGE, 100, serverXmlFile));
+ Charset charset = StandardCharsets.UTF_8;
+ String serverXmlContents = new String(Files.readAllBytes(serverXmlFile.toPath()), charset);
+ serverXmlContents = "\n" + serverXmlContents;
+ assertTrue(serverXmlContents,
+ verifyLogMessageExists(GenerateFeaturesMojo.FEATURES_FILE_MESSAGE, 100, serverXmlFile));
+ }
+
+ @Test
+ public void serverXmlCommentFMTest() throws Exception {
+ File serverXmlFile = new File(tempProj, "src/main/liberty/config/server.xml");
+ replaceString("<!--replaceable-->",
+ "<!--Feature generation comment goes below this line-->\n" +
+ " <featureManager>\n" +
+ " <feature>servlet-4.0</feature>\n" +
+ " </featureManager>\n", serverXmlFile);
+
+ // initially the expected comment is not found in server.xml
+ assertFalse(verifyLogMessageExists(GenerateFeaturesMojo.FEATURES_FILE_MESSAGE, 10, serverXmlFile));
+
+ runProcess("compile liberty:generate-features");
+
+ // verify that generated features file was created
+ assertTrue(newFeatureFile.exists());
+
+ // verify expected comment found in server.xml
+ Charset charset = StandardCharsets.UTF_8;
+ String serverXmlContents = new String(Files.readAllBytes(serverXmlFile.toPath()), charset);
+ serverXmlContents = "\n" + serverXmlContents;
+ assertTrue(serverXmlContents,
+ verifyLogMessageExists(GenerateFeaturesMojo.FEATURES_FILE_MESSAGE, 100, serverXmlFile));
}
}
