Skip to content

Commit

Permalink
Add ESchoolDemoTest (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Sep 4, 2016
1 parent 89f08d1 commit 8d5510d
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 3 deletions.
13 changes: 10 additions & 3 deletions parser/src/main/java/me/vertretungsplan/parser/ESchoolParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.jetbrains.annotations.NotNull;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.json.JSONException;
Expand Down Expand Up @@ -51,8 +52,6 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx
throw new IOException("no login");
}

SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);

List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("wp", scheduleData.getData().getString("id")));
nvps.add(new BasicNameValuePair("go", "vplan"));
Expand All @@ -75,6 +74,15 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx
}
}

SubstitutionSchedule schedule = parseESchoolSchedule(doc);

return schedule;
}

@NotNull
SubstitutionSchedule parseESchoolSchedule(Document doc) throws IOException, JSONException {
SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);

String infoString = doc.select("#Content table").first().select("td").get(1).ownText();
Pattern pattern = Pattern.compile("Letzte Aktualisierung:\u00a0(\\d{2}.\\d{2}.\\d{4} - \\d{2}:\\d{2})");
Matcher matcher = pattern.matcher(infoString);
Expand All @@ -101,7 +109,6 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx

schedule.setClasses(getAllClasses());
schedule.setTeachers(getAllTeachers());

return schedule;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.SubstitutionSchedule;
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 ESchoolDemoTest extends BaseDemoTest {
private String html;

private ESchoolParser parser;

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

@Test
public void demoTest() throws IOException, JSONException {
SubstitutionSchedule schedule = parser.parseESchoolSchedule(Jsoup.parse(html));
assertEquals(new LocalDateTime(2016, 9, 4, 14, 53), schedule.getLastChange());
assertEquals(1, schedule.getDays().size());

SubstitutionScheduleDay day = schedule.getDays().get(0);

assertEquals(new LocalDate(2016, 9, 5), day.getDate());
assertEquals(6, day.getSubstitutions().size());
assertEquals(0, day.getMessages().size());

for (Substitution subst : day.getSubstitutions()) {
assertTrue(subst.getClasses().size() == 1);
assertNotEmpty(subst.getLesson());
assertNullOrNotEmpty(subst.getPreviousSubject());
assertNotEmpty(subst.getSubject());
assertNullOrNotEmpty(subst.getRoom());
assertNullOrNotEmpty(subst.getTeacher());
assertNullOrNotEmpty(subst.getPreviousTeacher());
assertNullOrNotEmpty(subst.getDesc());
assertNotEmpty(subst.getType());
}
}
}
167 changes: 167 additions & 0 deletions parser/src/test/resources/eschool/eschool.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="./site/styles.css">
<title>eSchool Web</title>
</head>

<body bgcolor="#003366">
<div id="Background">
<img src="./site/images/bg.png" class="BackgroundStretch" alt=""/>
</div>
<div id="ContainerCenter">
<div id="Header">
</div>
<div id="ContentContainer">
<div id="MenuL">
<table border="0" width="100%">
<tr>
<td align="center"><b><font color="#808080">Vertretungsplan</font></b></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=T"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x1"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;N&auml;chster Tag</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x2"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute + 1 Tag</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x3"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute + 2 Tage</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x5"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute + 4 Tage</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x7"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute + 6 Tage</a></td>
</tr>
<tr>
<td><a href="?wp=678a65dca3d2261791675cf57fee5678&go=vplan&content=x14"><img
src="./site/images/vplan_mini.png" align="absmiddle">&nbsp;Heute + 13 Tage</a></td>
</tr>
</table>
</div><!-- MenuL -->
<div id="MinHeight">
</div><!-- MinHeight -->
<div id="Content">
<table border="0" width="100%" height="55">
<tr>
<td width="48"><img src="./site/images/vplan.gif"></td>
<td>
<b><font size="5">Vertretungsplan f&uuml;r 05.09.2016 bis 22.09.2016</font></b><br/>Letzte
Aktualisierung:&nbsp;04.09.2016 - 14:53, Vertretungsplanmodus: Davinci 6 HTML
</td>
</tr>
</table>
<br>
<form name="vplanmenu" id="vplanmenu" method="GET"
action="?wp=678a65dca3d2261791675cf57fee5678&content=x14">
<input type="hidden" name="wp" value="678a65dca3d2261791675cf57fee5678">
<input type="hidden" name="go" value="vplan">
<input type="hidden" name="content" value="x14">
<table border="1" width="100%" bgcolor="#D1E7FC" bordercolor="#92C5F8" cellspacing="0" height="25">
<tr>
<td align="left" valign="baseline">
<img src="./site/images/sortieren.png" align="absmiddle"><font size="2">&nbsp;Sortieren
nach:</a>
<select size="1" name="sortby" align="middle" onchange="document.vplanmenu.submit();">
<option value="K">Klassen</option>
<option value="L">Lehrer</option>
<option value="S" selected>Stunden</option>
</select>
</td>
</tr>
</table>
</form>
<br>
<hr>
<center><b>Montag, den 05.09.2016</b></center>
<hr>
<table id="DATA" border="1" width="100%">
<th colspan="10" align="left"><br>
1. Stunde&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;Montag, den 05.09.
</th>
<tr>
<td bgcolor="#BBDDFF" align="center"><b>KLASSE(N)</b></td>
<td bgcolor="#BBDDFF" align="center"><b>LEHRER</b></td>
<td bgcolor="#BBDDFF" align="center"><b>FACH</b></td>
<td bgcolor="#BBDDFF" align="center"><b>RAUM</b></td>
<td bgcolor="#BBDDFF" align="center"><b>INFO</b></td>
</tr>
<tr>
<td>05e</td>
<td nowrap>KIR <img src="./site/images/to.png" align="absmiddle"> SEI</td>
<td nowrap>EN</td>
<td nowrap>163_M</td>
<td nowrap></td>
</tr>
<tr>
<td>11</td>
<td nowrap>IPS</td>
<td nowrap>sek1</td>
<td nowrap>EKS2_217_S</td>
<td nowrap>Klasse frei</td>
</tr>
<tr>
<td>13</td>
<td nowrap>WEN</td>
<td nowrap>BI2</td>
<td nowrap>BIS2_305_M</td>
<td nowrap>Klasse frei</td>
</tr>
<th colspan="10" align="left"><br>
2. Stunde&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;Montag, den 05.09.
</th>
<tr>
<td bgcolor="#BBDDFF" align="center"><b>KLASSE(N)</b></td>
<td bgcolor="#BBDDFF" align="center"><b>LEHRER</b></td>
<td bgcolor="#BBDDFF" align="center"><b>FACH</b></td>
<td bgcolor="#BBDDFF" align="center"><b>RAUM</b></td>
<td bgcolor="#BBDDFF" align="center"><b>INFO</b></td>
</tr>
<tr>
<td>05e</td>
<td nowrap>KIR <img src="./site/images/to.png" align="absmiddle"> SEI</td>
<td nowrap>EN</td>
<td nowrap>163_M</td>
<td nowrap></td>
</tr>
<tr>
<td>13</td>
<td nowrap>WEN</td>
<td nowrap>BI2</td>
<td nowrap>BIS2_305_M</td>
<td nowrap>Klasse frei</td>
</tr>
<tr>
<td>13</td>
<td nowrap>IPS</td>
<td nowrap>EK1</td>
<td nowrap>EKS2_217_S</td>
<td nowrap>Klasse frei</td>
</tr>
</table>
<br>
<br>

</div><!-- Content -->
<div id="clear"></div>
</div><!-- ContentContainer -->
<div id="Footer">
</div><!-- Footer -->
<div id="FooterTopackt">
&copy; 2010 - 2016 Topackt IT Solutions GmbH - Tom D&ouml;rr
</div><!-- FooterTopackt -->
<div id="clear"></div>
</body>

</html>

0 comments on commit 8d5510d

Please sign in to comment.