|
15 | 15 | import java.io.BufferedReader; |
16 | 16 | import java.io.File; |
17 | 17 | import java.io.FileReader; |
| 18 | +import java.io.IOException; |
| 19 | +import java.util.Arrays; |
| 20 | +import java.io.FileInputStream; |
| 21 | +import java.io.FileNotFoundException; |
| 22 | +import java.util.Properties; |
18 | 23 |
|
19 | 24 | import org.junit.BeforeClass; |
20 | 25 | import org.junit.Test; |
| 26 | +import org.eclipse.aether.repository.RemoteRepository; |
| 27 | +import org.eclipse.aether.RepositorySystem; |
| 28 | +import org.eclipse.aether.RepositorySystemSession; |
| 29 | +import org.eclipse.aether.artifact.Artifact; |
| 30 | +import org.eclipse.aether.resolution.VersionRangeRequest; |
| 31 | +import org.eclipse.aether.resolution.VersionRangeResult; |
| 32 | +import org.eclipse.aether.resolution.VersionRangeResolutionException; |
| 33 | +import org.eclipse.aether.DefaultRepositorySystemSession; |
| 34 | +import org.eclipse.aether.artifact.DefaultArtifact; |
| 35 | +import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; |
| 36 | +import org.eclipse.aether.impl.DefaultServiceLocator; |
| 37 | +import org.eclipse.aether.repository.LocalRepository; |
| 38 | +import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; |
| 39 | +import org.eclipse.aether.spi.connector.transport.TransporterFactory; |
| 40 | +import org.eclipse.aether.transport.file.FileTransporterFactory; |
| 41 | +import org.eclipse.aether.transport.http.HttpTransporterFactory; |
| 42 | +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; |
| 43 | + |
| 44 | +import org.apache.commons.logging.Log; |
| 45 | +import org.apache.commons.logging.LogFactory; |
21 | 46 |
|
22 | 47 | public class LibertyFeatureVersionIT { |
23 | 48 |
|
24 | 49 | private static final String JAXRS_20_FEATURE = "<feature>jaxrs-2.0</feature>"; |
25 | 50 | private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml"; |
| 51 | + private static String LIBERTY_PROPERTIES = "target/liberty/wlp/lib/versions/openliberty.properties"; |
| 52 | + private static String LIBERTY_VERSION = "com.ibm.websphere.productVersion"; |
| 53 | + private static String runtimeVersion; |
| 54 | + private final static Log log = LogFactory.getLog(LibertyFeatureVersionIT.class); |
26 | 55 |
|
27 | 56 | @BeforeClass |
28 | 57 | public static void init() { |
29 | 58 | String runtime = System.getProperty("boostRuntime"); |
30 | 59 | org.junit.Assume.assumeTrue("ol".equals(runtime) || "wlp".equals(runtime)); |
| 60 | + runtimeVersion = System.getProperty("libertyRuntimeVersion"); |
| 61 | + } |
| 62 | + |
| 63 | + /* |
| 64 | + * Go to Maven and figure out what the latest version of liberty runtime is out |
| 65 | + * there. Use that version for comparing what level should be found in the |
| 66 | + * messages.log file when the server is run. Only used when no libertyRunTime |
| 67 | + * version is provided. |
| 68 | + */ |
| 69 | + private String getLatestLibertyRuntimeVersion() { |
| 70 | + String libertyVersion = null; |
| 71 | + |
| 72 | + RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/") |
| 73 | + .build(); |
| 74 | + RepositorySystem repoSystem = newRepositorySystem(); |
| 75 | + RepositorySystemSession session = newSession(repoSystem); |
| 76 | + String version = "[19.0.0.6,)"; |
| 77 | + Artifact artifact = new DefaultArtifact("io.openliberty:openliberty-runtime:" + version); |
| 78 | + VersionRangeRequest request = new VersionRangeRequest(artifact, Arrays.asList(central), null); |
| 79 | + try { |
| 80 | + VersionRangeResult versionResult = repoSystem.resolveVersionRange(session, request); |
| 81 | + libertyVersion = versionResult.getHighestVersion().toString(); |
| 82 | + } catch (VersionRangeResolutionException e) { |
| 83 | + e.printStackTrace(); |
| 84 | + } |
| 85 | + |
| 86 | + return libertyVersion; |
| 87 | + |
| 88 | + } |
| 89 | + |
| 90 | + private RepositorySystem newRepositorySystem() { |
| 91 | + DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); |
| 92 | + locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); |
| 93 | + locator.addService(TransporterFactory.class, FileTransporterFactory.class); |
| 94 | + locator.addService(TransporterFactory.class, HttpTransporterFactory.class); |
| 95 | + return locator.getService(RepositorySystem.class); |
| 96 | + } |
| 97 | + |
| 98 | + private RepositorySystemSession newSession(RepositorySystem system) { |
| 99 | + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); |
| 100 | + LocalRepository localRepo = new LocalRepository("target/local-repo"); |
| 101 | + session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); |
| 102 | + return session; |
31 | 103 | } |
32 | 104 |
|
33 | 105 | @Test |
@@ -56,4 +128,59 @@ public void testLibertyFeatureVersion() throws Exception { |
56 | 128 |
|
57 | 129 | assertTrue("The " + JAXRS_20_FEATURE + " feature was not found in the server configuration", found); |
58 | 130 | } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void testLibertyRuntimeVersion() throws Exception { |
| 134 | + |
| 135 | + String installedVersion = getLibertyVersionPropertyFromInstall(); |
| 136 | + |
| 137 | + if (runtimeVersion == null) { |
| 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); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + private String getLibertyVersionPropertyFromInstall() throws FileNotFoundException, IOException { |
| 167 | + |
| 168 | + Properties libertyProps = new Properties(); |
| 169 | + String propsRuntime = null; |
| 170 | + FileInputStream fis = null; |
| 171 | + try { |
| 172 | + fis = new FileInputStream(LIBERTY_PROPERTIES); |
| 173 | + libertyProps.load(fis); |
| 174 | + propsRuntime = libertyProps.getProperty(LIBERTY_VERSION); |
| 175 | + } finally { |
| 176 | + if (fis != null) { |
| 177 | + fis.close(); |
| 178 | + } |
| 179 | + } |
| 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); |
| 183 | + |
| 184 | + return propsRuntime; |
| 185 | + } |
59 | 186 | } |
0 commit comments