diff --git a/tests/src/test/java/org/keycloak/documentation/test/AbstractDocsTest.java b/tests/src/test/java/org/keycloak/documentation/test/AbstractDocsTest.java index 7d1d942bff..78f447b50c 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/AbstractDocsTest.java +++ b/tests/src/test/java/org/keycloak/documentation/test/AbstractDocsTest.java @@ -23,18 +23,18 @@ public abstract class AbstractDocsTest { protected File guideDir; protected static String body; + protected String guideUrl; @Before public void before() throws IOException { guideDir = config.getGuideDir(getGuideDirName()); + guideUrl = config.getGuideBaseUrl() + "/" + config.getGuideUrlFragment(getGuideDirName()) + "/"; if (body == null) { if (config.isLoadFromFiles()) { File htmlFile = config.getGuideHtmlFile(getGuideDirName()); body = utils.readBody(htmlFile); } else { - String guideUrl = config.getGuideBaseUrl() + "/" + config.getGuideUrlFragment(getGuideDirName()); - log.info("Loading guide from '" + guideUrl); body = utils.readBody(new URL(guideUrl)); } @@ -69,7 +69,7 @@ public abstract class AbstractDocsTest { @Test public void checkImages() { - List failures = linkUtils.findInvalidImages(body, guideDir); + List failures = linkUtils.findInvalidImages(body, guideDir, guideUrl); checkFailures("Images not found", failures); } diff --git a/tests/src/test/java/org/keycloak/documentation/test/utils/Constants.java b/tests/src/test/java/org/keycloak/documentation/test/utils/Constants.java index c5f9097299..89ad79b719 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/utils/Constants.java +++ b/tests/src/test/java/org/keycloak/documentation/test/utils/Constants.java @@ -5,8 +5,8 @@ import java.util.concurrent.TimeUnit; public class Constants { public static final int HTTP_RETRY = 3; - public static final int HTTP_CONNECTION_TIMEOUT = 5000; - public static final int HTTP_READ_TIMEOUT = 10000; + public static final int HTTP_CONNECTION_TIMEOUT = 30000; + public static final int HTTP_READ_TIMEOUT = 300000; public static final long LINK_CHECK_EXPIRATION = TimeUnit.DAYS.toMillis(1); } diff --git a/tests/src/test/java/org/keycloak/documentation/test/utils/DocUtils.java b/tests/src/test/java/org/keycloak/documentation/test/utils/DocUtils.java index 823cd98ec1..912fc8c1c9 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/utils/DocUtils.java +++ b/tests/src/test/java/org/keycloak/documentation/test/utils/DocUtils.java @@ -27,10 +27,16 @@ public class DocUtils { public String readBody(URL url) throws IOException { HttpURLConnection connection = null; + try { connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(Constants.HTTP_CONNECTION_TIMEOUT); connection.setReadTimeout(Constants.HTTP_READ_TIMEOUT); + + if (connection.getResponseCode() != 200) { + throw new IOException("Invalid status code returned " + connection.getResponseCode()); + } + StringWriter w = new StringWriter(); IOUtils.copy(connection.getInputStream(), w, "utf-8"); String s = w.toString(); @@ -43,7 +49,9 @@ public class DocUtils { } Matcher m = p.matcher(s); - m.find(); + if (!m.find()) { + throw new RuntimeException("Couldn't find body"); + } return m.group(1); } finally { @@ -53,7 +61,7 @@ public class DocUtils { public List findMissingVariables(String body, List ignoredVariables) { List missingVariables = new LinkedList<>(); - Pattern p = Pattern.compile("[^$/=\\s]\\{([^ }]*)}"); + Pattern p = Pattern.compile("[^$/=\\s]\\{([^ }\"]*)}"); Matcher m = p.matcher(body); while (m.find()) { String key = m.group(1); diff --git a/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java b/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java index f5b23e3d8e..9f0b8b4707 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java +++ b/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java @@ -102,7 +102,7 @@ public class LinkUtils { return invalidLinks; } - public List findInvalidImages(String body, File guideDir) { + public List findInvalidImages(String body, File guideDir, String guideUrl) { List missingImages = new LinkedList<>(); Pattern p = Pattern.compile("]*\""); Matcher m = p.matcher(body); @@ -114,6 +114,10 @@ public class LinkUtils { missingImages.add(image); } } else { + if (image.startsWith("./")) { + image = guideUrl + image; + } + if (!verifiedLinks.containsKey(image)) { boolean valid = http.isValid(image); if (valid) {