Commit 7b648821 authored by mirako's avatar mirako
Browse files

Testing

parent 8603f8db
......@@ -32,5 +32,11 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -9,11 +9,6 @@ import java.net.UnknownHostException;
import java.util.*;
public class Crawler {
public int countLinks;
public int countWords;
public int countImages;
public int countVideos;
public int setLinks;
Report report = new Report();
//for the recursive method
......@@ -65,13 +60,14 @@ public class Crawler {
}
private void analyze(String url, int depth) {
public void analyze(String url, int depth) {
depth--;
try {
Document doc = Jsoup.connect(url).userAgent("Mozilla").get();
Elements links = doc.select("a");
if (links.isEmpty()) {
System.out.println("The link was empty");
return;
}
......@@ -81,11 +77,11 @@ public class Crawler {
if (add && this_url.contains(myPage)) {
try {
Document newWebpage = Jsoup.connect(this_url).get();
countImages(newWebpage);
countVideos(newWebpage);
countWords(newWebpage);
getLinks(newWebpage);
findBrokenLinks(getLinks(newWebpage));
report.setImageCount(countImages(newWebpage));
report.setVideoCount(countVideos(newWebpage));
report.setWordCount(countWords(newWebpage));
report.setLinks(getLinks(newWebpage));
report.setBrokenLinks(findBrokenLinks(getLinks(newWebpage)));
} catch (IOException e) {
e.printStackTrace();
}
......
import org.junit.Assert;
import org.junit.Rule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import static org.junit.Assert.assertEquals;
public class CrawlerTest {
public static Crawler crawler1;
public static Crawler crawler2;
public static Report report1;
public static Report report2;
@BeforeAll
public static void init(){
crawler1 = new Crawler();
crawler2 = new Crawler();
report1 = new Report();
report2 = new Report();
}
@Test
public void testAnalyzeEmptyURL(){
Assert.assertThrows(IllegalArgumentException.class, () ->{
crawler1.analyze("", 1);
});
}
@Test
public void testWordCount(){
crawler1.analyze("https://www.aau.at/", 0);
crawler2.analyze("https://www.aau.at/", 1);
}
@AfterEach
public static void tearDown(){
crawler1 = null;
crawler2 = null;
report1 = null;
report2 = null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment