Fix testsuite for external docs
This commit is contained in:
parent
a3c1b7317d
commit
a5e8c09f3e
4 changed files with 20 additions and 8 deletions
|
@ -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<String> failures = linkUtils.findInvalidImages(body, guideDir);
|
||||
List<String> failures = linkUtils.findInvalidImages(body, guideDir, guideUrl);
|
||||
checkFailures("Images not found", failures);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String> findMissingVariables(String body, List<String> ignoredVariables) {
|
||||
List<String> 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);
|
||||
|
|
|
@ -102,7 +102,7 @@ public class LinkUtils {
|
|||
return invalidLinks;
|
||||
}
|
||||
|
||||
public List<String> findInvalidImages(String body, File guideDir) {
|
||||
public List<String> findInvalidImages(String body, File guideDir, String guideUrl) {
|
||||
List<String> missingImages = new LinkedList<>();
|
||||
Pattern p = Pattern.compile("<img src=\"([^ \"]*)[^>]*\"");
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue