Skip to content

Commit 6b80ca8

Browse files
authored
Merge pull request #1832 from cherylking/updateBuildLogCheck
Update build.log check for feature installation
2 parents c0d69d2 + 49440d2 commit 6b80ca8

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

liberty-maven-plugin/src/it/kernel-install-feature-test/base-install-feature-test/src/test/java/net/wasdev/wlp/test/feature/it/BaseInstallFeature.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* (c) Copyright IBM Corporation 2018.
2+
* (c) Copyright IBM Corporation 2018, 2024.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,14 @@
1818
import java.io.File;
1919
import java.io.FilenameFilter;
2020
import io.openliberty.tools.common.plugins.util.InstallFeatureUtil;
21+
import java.io.FileInputStream;
22+
import java.io.InputStream;
23+
import java.io.InputStreamReader;
24+
import java.util.Scanner;
25+
import java.util.Set;
2126

2227
import static org.junit.Assert.assertEquals;
28+
import static org.junit.Assert.assertTrue;
2329
import org.junit.Before;
2430

2531
public class BaseInstallFeature {
@@ -55,7 +61,10 @@ protected void assertNotInstalled(String feature) throws Exception {
5561
protected boolean existsInFeaturesDirectory(String feature) {
5662
boolean found = false;
5763
for (File file : features) {
58-
if (file.getName().equals("com.ibm.websphere.appserver." + feature + ".mf")) {
64+
if ((file.getName().equals("com.ibm.websphere.appserver." + feature + ".mf")) ||
65+
(file.getName().equals("io.openliberty.versionless." + feature + ".mf")) ||
66+
(file.getName().equals("io.openliberty.jakarta." + feature + ".mf")) ||
67+
(file.getName().equals("io.openliberty." + feature + ".mf"))) {
5968
found = true;
6069
break;
6170
}
@@ -68,4 +77,33 @@ protected String getFeatureInfo() throws Exception {
6877
return InstallFeatureUtil.productInfo(installDirectory, "featureInfo");
6978
}
7079

80+
public boolean buildLogCheckForInstalledFeatures(String testname, String msg, Set<String> installedFeatures) throws Exception {
81+
File buildLog = new File("../../build.log");
82+
assertTrue(buildLog.exists());
83+
boolean foundTestName = false;
84+
85+
try (InputStream buildOutput = new FileInputStream(buildLog); InputStreamReader in = new InputStreamReader(buildOutput); Scanner s = new Scanner(in);) {
86+
while (s.hasNextLine()) {
87+
String line = s.nextLine();
88+
if (foundTestName && line.contains(msg)) {
89+
// check for all features in message
90+
String messageFeatures = line.substring(line.indexOf(":") + 1);
91+
String[] messageFeaturesArray = messageFeatures.trim().split(" ");
92+
assertTrue("The number of installed features ("+messageFeaturesArray.length+") is different than expected number ("+installedFeatures.size()+"). The log message is: "+line,messageFeaturesArray.length == installedFeatures.size());
93+
for (int i=0; i < messageFeaturesArray.length; i++) {
94+
assertTrue("Found unexpected feature "+messageFeaturesArray[i]+" in list of installed features in message in build.log.",installedFeatures.contains(messageFeaturesArray[i].trim()));
95+
}
96+
return true;
97+
} else if (line.contains(testname)) {
98+
// process next feature installation message
99+
foundTestName = true;
100+
}
101+
}
102+
} catch (Exception e) {
103+
System.out.println("Error checking build.log " + e.getMessage());
104+
}
105+
106+
return false;
107+
}
108+
71109
}

liberty-maven-plugin/src/it/kernel-install-feature-test/install-features-server-it/src/test/java/net/wasdev/wlp/test/feature/it/InstallFeaturesServerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* (c) Copyright IBM Corporation 2018.
2+
* (c) Copyright IBM Corporation 2018, 2024.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
1818
import static org.junit.Assert.*;
1919
import org.junit.Test;
2020
import java.io.File;
21+
import java.util.Set;
22+
import java.util.HashSet;
2123

2224
public class InstallFeaturesServerTest extends BaseInstallFeature {
2325

@@ -31,6 +33,12 @@ public void testInstalledFeatures() throws Exception {
3133
assertNotInstalled("beanValidation-2.0");
3234
assertNotInstalled("couchdb-1.0");
3335
assertNotInstalled("distributedMap-1.0");
36+
37+
Set<String> expectedFeatures = new HashSet<String>();
38+
expectedFeatures.add("ssl-1.0");
39+
expectedFeatures.add("appSecurityClient-1.0");
40+
41+
assertTrue(buildLogCheckForInstalledFeatures("io.openliberty.tools.it:install-features-server-it", "The following features have been installed:", expectedFeatures));
3442
}
3543

3644
}

0 commit comments

Comments
 (0)