Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build.log check for feature installation #1832

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

}
Loading