Skip to content

Commit

Permalink
Add DaVinciDemoTest (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Sep 4, 2016
1 parent 2be2937 commit 8a0c0a7
Show file tree
Hide file tree
Showing 4 changed files with 1,023 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public DaVinciParser(SubstitutionScheduleData scheduleData, CookieProvider cooki
super(scheduleData, cookieProvider);
}

public static void parseDaVinciTable(Element table, SubstitutionScheduleDay day, ColorProvider colorProvider) {
static void parseDaVinciTable(Element table, SubstitutionScheduleDay day, ColorProvider colorProvider) {
parseDaVinciTable(table, day, null, colorProvider);
}

public static void parseDaVinciTable(Element table, SubstitutionScheduleDay day, String klasse, ColorProvider colorProvider) {
static void parseDaVinciTable(Element table, SubstitutionScheduleDay day, String klasse,
ColorProvider colorProvider) {
List<String> headers = new ArrayList<>();
for (Element header : table.select("thead tr th, tr td[bgcolor=#9999FF]")) {
headers.add(header.text());
Expand Down Expand Up @@ -203,7 +204,7 @@ private String urlFromOnclick(String onclick) {
}

@NotNull
private SubstitutionScheduleDay parseDay(Document doc) throws IOException {
SubstitutionScheduleDay parseDay(Document doc) throws IOException {
SubstitutionScheduleDay day = new SubstitutionScheduleDay();

String title = doc.select("h1.list-table-caption").first().text();
Expand Down
12 changes: 12 additions & 0 deletions parser/src/test/java/me/vertretungsplan/parser/BaseDemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.io.*;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class BaseDemoTest {
/**
* Reads content from an InputStream into a string
Expand Down Expand Up @@ -51,4 +54,13 @@ protected String readResource(String filename) {
return null;
}
}

protected static void assertNullOrNotEmpty(String value) {
if (value != null) assertTrue(!value.isEmpty());
}

protected static void assertNotEmpty(String value) {
assertNotNull(value);
assertTrue(!value.isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* substitution-schedule-parser - Java library for parsing schools' substitution schedules
* Copyright (c) 2016 Johan v. Forstner
*
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package me.vertretungsplan.parser;

import me.vertretungsplan.objects.Substitution;
import me.vertretungsplan.objects.SubstitutionScheduleData;
import me.vertretungsplan.objects.SubstitutionScheduleDay;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class DaVinciDemoTest extends BaseDemoTest {
private String html;
private DaVinciParser parser;

@Before
public void setUp() throws JSONException {
html = readResource("/davinci/davinci.html");
SubstitutionScheduleData scheduleData = new SubstitutionScheduleData();
scheduleData.setData(new JSONObject());
parser = new DaVinciParser(scheduleData, null);
}

@Test
public void demoTest() throws IOException, JSONException {
SubstitutionScheduleDay day = parser.parseDay(Jsoup.parse(html));
assertEquals(new LocalDate(2016, 9, 5), day.getDate());
assertEquals(new LocalDateTime(2016, 9, 2, 13, 32), day.getLastChange());
assertEquals(23, day.getSubstitutions().size());
assertEquals(0, day.getMessages().size());

for (Substitution subst : day.getSubstitutions()) {
assertTrue(subst.getClasses().size() > 0);
assertNotEmpty(subst.getLesson());
assertNotEmpty(subst.getPreviousSubject());
assertNotEmpty(subst.getSubject());
assertNullOrNotEmpty(subst.getRoom());
assertNullOrNotEmpty(subst.getTeacher());
assertNullOrNotEmpty(subst.getDesc());
assertNotEmpty(subst.getType());
}
}


}
Loading

0 comments on commit 8a0c0a7

Please sign in to comment.