1515import java .io .BufferedReader ;
1616import java .io .File ;
1717import java .io .FileReader ;
18+ import java .io .IOException ;
1819import java .util .Arrays ;
1920import java .io .FileInputStream ;
21+ import java .io .FileNotFoundException ;
2022import java .util .Properties ;
2123
2224import org .junit .BeforeClass ;
3941import org .eclipse .aether .transport .http .HttpTransporterFactory ;
4042import org .apache .maven .repository .internal .MavenRepositorySystemUtils ;
4143
44+ import org .apache .commons .logging .Log ;
45+ import org .apache .commons .logging .LogFactory ;
46+
4247public class LibertyFeatureVersionIT {
4348
4449 private static final String JAXRS_20_FEATURE = "<feature>jaxrs-2.0</feature>" ;
4550 private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml" ;
4651 private static String LIBERTY_PROPERTIES = "target/liberty/wlp/lib/versions/openliberty.properties" ;
4752 private static String LIBERTY_VERSION = "com.ibm.websphere.productVersion" ;
4853 private static String runtimeVersion ;
54+ private final static Log log = LogFactory .getLog (LibertyFeatureVersionIT .class );
4955
5056 @ BeforeClass
5157 public static void init () {
@@ -60,7 +66,7 @@ public static void init() {
6066 * messages.log file when the server is run. Only used when no libertyRunTime
6167 * version is provided.
6268 */
63- private String getLatesLibertyRuntimeVersion () {
69+ private String getLatestLibertyRuntimeVersion () {
6470 String libertyVersion = null ;
6571
6672 RemoteRepository central = new RemoteRepository .Builder ("central" , "default" , "http://repo1.maven.org/maven2/" )
@@ -126,17 +132,38 @@ public void testLibertyFeatureVersion() throws Exception {
126132 @ Test
127133 public void testLibertyRuntimeVersion () throws Exception {
128134
129- boolean found = false ;
135+ String installedVersion = getLibertyVersionPropertyFromInstall () ;
130136
131137 if (runtimeVersion == null ) {
132- // This relies on a scan of the maven repository to find the lastest version of
133- // liberty installed. Not sure what subtle issues this might cause.
134- // if there are issues matching the runtime versions then
135- // this may be the culprit and not actually a Boost issue.
136- runtimeVersion = getLatesLibertyRuntimeVersion ();
138+
139+ // The getLatestLibertyRuntimeVersion() relies on a scan of the maven repository
140+ // to find the latest version of liberty available, possibly remotely.
141+ //
142+ // Not sure what subtle issues this might cause. If there are issues matching
143+ // the runtime versions then this may be the culprit and not actually a Boost
144+ // issue.
145+ String expectedVersion = getLatestLibertyRuntimeVersion ();
146+
147+ log .info ("Found installed version = " + installedVersion
148+ + ". From Boost we defaulted the runtime version (to the latest). According to the test logic the latest version available is: "
149+ + expectedVersion );
150+
151+ String assertMsg = "Expected default runtime version not found in installed Liberty properties file. This may be because the "
152+ + "default to latest version algorithm produced subtly different results when it was called from the runtime code "
153+ + "vs. the test code trying to validate that the latest was used. As such, this may not be a boost issue, but an "
154+ + "implementation detail of the underlying Maven APIs." ;
155+ assertEquals (assertMsg , expectedVersion , installedVersion );
156+ } else {
157+
158+ log .info ("Found installed version = " + installedVersion + ", looking for runtime version = "
159+ + runtimeVersion );
160+
161+ assertEquals ("Didn't find expected runtime version in product install properties file" , runtimeVersion ,
162+ installedVersion );
137163 }
138- String assertMsg = "Runtime version is null. This may be an issue with checking for the latest runtime version from maven and may not be a boost issue" ;
139- assertNotNull (assertMsg , runtimeVersion );
164+ }
165+
166+ private String getLibertyVersionPropertyFromInstall () throws FileNotFoundException , IOException {
140167
141168 Properties libertyProps = new Properties ();
142169 String propsRuntime = null ;
@@ -145,19 +172,15 @@ public void testLibertyRuntimeVersion() throws Exception {
145172 fis = new FileInputStream (LIBERTY_PROPERTIES );
146173 libertyProps .load (fis );
147174 propsRuntime = libertyProps .getProperty (LIBERTY_VERSION );
148- assertNotNull ("Property runtime empty" , propsRuntime );
149- if (propsRuntime .equals (runtimeVersion )) {
150- found = true ;
151- }
152175 } finally {
153176 if (fis != null ) {
154177 fis .close ();
155178 }
156179 }
157- assertMsg = "The run time version " + runtimeVersion
158- + " was not found in the openliberty.properties. openliberty.properties version = " + propsRuntime
159- + ". This may be an issue with checking for the latest runtime version from maven and may not be a boost issue" ;
180+ assertNotNull ( "Didn't find property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES , propsRuntime );
181+ assertNotEquals ( "Found empty-valued property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES , "" ,
182+ propsRuntime ) ;
160183
161- assertTrue ( assertMsg , found ) ;
184+ return propsRuntime ;
162185 }
163186}
0 commit comments