Tests that the deployed snapshot is not more than two weeks old. @throws Exception if an error occurs
()
| 186 | * @throws Exception if an error occurs |
| 187 | */ |
| 188 | @Test |
| 189 | public void snapshot() throws Exception { |
| 190 | final File pomFile = new File("pom.xml"); |
| 191 | if (!pomFile.exists()) { |
| 192 | throw new IOException("POM file not found: " + pomFile.getAbsolutePath()); |
| 193 | } |
| 194 | |
| 195 | MavenXpp3Reader reader = new MavenXpp3Reader(); |
| 196 | try (FileReader fileReader = new FileReader(pomFile)) { |
| 197 | final Model model = reader.read(fileReader); |
| 198 | |
| 199 | final String version = model.getVersion(); |
| 200 | Assertions.assertNotNull(version); |
| 201 | if (version.contains("SNAPSHOT")) { |
| 202 | try (WebClient webClient = new WebClient(BrowserVersion.FIREFOX, false, null, -1)) { |
| 203 | final String url = SONATYPE_SNAPSHOT_REPO_URL_ |
| 204 | + "org/htmlunit/htmlunit/" + version + "/maven-metadata.xml"; |
| 205 | |
| 206 | final XmlPage page = webClient.getPage(url); |
| 207 | final String timestamp = page.getElementsByTagName("timestamp").get(0).getTextContent(); |
| 208 | final DateFormat format = new SimpleDateFormat("yyyyMMdd.HHmmss", Locale.ROOT); |
| 209 | final long snapshotMillis = format.parse(timestamp).getTime(); |
| 210 | final long nowMillis = System.currentTimeMillis(); |
| 211 | final long days = TimeUnit.MILLISECONDS.toDays(nowMillis - snapshotMillis); |
| 212 | |
| 213 | Assertions.assertTrue(days < 14, "Snapshot not deployed for " + days + " days"); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | private static void assertVersion(final String groupId, final String artifactId, |
| 220 | final String pomVersion, final Pattern ignorePattern) |
nothing calls this directly
no test coverage detected