Skip to content

Commit

Permalink
Merge pull request #1832 from cherylking/updateBuildLogCheck
Browse files Browse the repository at this point in the history
Update build.log check for feature installation
  • Loading branch information
cherylking authored Sep 24, 2024
2 parents c0d69d2 + 49440d2 commit 6b80ca8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) Copyright IBM Corporation 2018.
* (c) Copyright IBM Corporation 2018, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,8 +18,14 @@
import java.io.File;
import java.io.FilenameFilter;
import io.openliberty.tools.common.plugins.util.InstallFeatureUtil;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;

public class BaseInstallFeature {
Expand Down Expand Up @@ -55,7 +61,10 @@ protected void assertNotInstalled(String feature) throws Exception {
protected boolean existsInFeaturesDirectory(String feature) {
boolean found = false;
for (File file : features) {
if (file.getName().equals("com.ibm.websphere.appserver." + feature + ".mf")) {
if ((file.getName().equals("com.ibm.websphere.appserver." + feature + ".mf")) ||
(file.getName().equals("io.openliberty.versionless." + feature + ".mf")) ||
(file.getName().equals("io.openliberty.jakarta." + feature + ".mf")) ||
(file.getName().equals("io.openliberty." + feature + ".mf"))) {
found = true;
break;
}
Expand All @@ -68,4 +77,33 @@ protected String getFeatureInfo() throws Exception {
return InstallFeatureUtil.productInfo(installDirectory, "featureInfo");
}

public boolean buildLogCheckForInstalledFeatures(String testname, String msg, Set<String> installedFeatures) throws Exception {
File buildLog = new File("../../build.log");
assertTrue(buildLog.exists());
boolean foundTestName = false;

try (InputStream buildOutput = new FileInputStream(buildLog); InputStreamReader in = new InputStreamReader(buildOutput); Scanner s = new Scanner(in);) {
while (s.hasNextLine()) {
String line = s.nextLine();
if (foundTestName && line.contains(msg)) {
// check for all features in message
String messageFeatures = line.substring(line.indexOf(":") + 1);
String[] messageFeaturesArray = messageFeatures.trim().split(" ");
assertTrue("The number of installed features ("+messageFeaturesArray.length+") is different than expected number ("+installedFeatures.size()+"). The log message is: "+line,messageFeaturesArray.length == installedFeatures.size());
for (int i=0; i < messageFeaturesArray.length; i++) {
assertTrue("Found unexpected feature "+messageFeaturesArray[i]+" in list of installed features in message in build.log.",installedFeatures.contains(messageFeaturesArray[i].trim()));
}
return true;
} else if (line.contains(testname)) {
// process next feature installation message
foundTestName = true;
}
}
} catch (Exception e) {
System.out.println("Error checking build.log " + e.getMessage());
}

return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) Copyright IBM Corporation 2018.
* (c) Copyright IBM Corporation 2018, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,8 @@
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
import java.util.Set;
import java.util.HashSet;

public class InstallFeaturesServerTest extends BaseInstallFeature {

Expand All @@ -31,6 +33,12 @@ public void testInstalledFeatures() throws Exception {
assertNotInstalled("beanValidation-2.0");
assertNotInstalled("couchdb-1.0");
assertNotInstalled("distributedMap-1.0");

Set<String> expectedFeatures = new HashSet<String>();
expectedFeatures.add("ssl-1.0");
expectedFeatures.add("appSecurityClient-1.0");

assertTrue(buildLogCheckForInstalledFeatures("io.openliberty.tools.it:install-features-server-it", "The following features have been installed:", expectedFeatures));
}

}

0 comments on commit 6b80ca8

Please sign in to comment.