From 1a244e39955efc105c1faa0ea8625b19af5132e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sat, 5 Aug 2017 14:05:57 +0200 Subject: [PATCH] Add timetable api (#9) --- .../github/wulkanowy/api/timetable/Day.java | 55 +++ .../wulkanowy/api/timetable/Lesson.java | 141 ++++++ .../github/wulkanowy/api/timetable/Table.java | 143 +++++++ .../wulkanowy/api/timetable/Timetable.java | 33 ++ .../github/wulkanowy/api/timetable/Week.java | 33 ++ .../wulkanowy/utilities/DateHelper.java | 37 ++ .../wulkanowy/api/timetable/TableTest.java | 218 ++++++++++ .../wulkanowy/utilities/DateHelperTest.java | 58 +++ .../api/timetable/PlanLekcji-full.html | 405 ++++++++++++++++++ .../api/timetable/PlanLekcji-holidays.html | 156 +++++++ .../api/timetable/PlanLekcji-std.html | 303 +++++++++++++ 11 files changed, 1582 insertions(+) create mode 100644 app/src/main/java/io/github/wulkanowy/api/timetable/Day.java create mode 100644 app/src/main/java/io/github/wulkanowy/api/timetable/Lesson.java create mode 100644 app/src/main/java/io/github/wulkanowy/api/timetable/Table.java create mode 100644 app/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java create mode 100644 app/src/main/java/io/github/wulkanowy/api/timetable/Week.java create mode 100644 app/src/main/java/io/github/wulkanowy/utilities/DateHelper.java create mode 100644 app/src/test/java/io/github/wulkanowy/api/timetable/TableTest.java create mode 100644 app/src/test/java/io/github/wulkanowy/utilities/DateHelperTest.java create mode 100644 app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html create mode 100644 app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-holidays.html create mode 100644 app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-std.html diff --git a/app/src/main/java/io/github/wulkanowy/api/timetable/Day.java b/app/src/main/java/io/github/wulkanowy/api/timetable/Day.java new file mode 100644 index 000000000..9b44647f9 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/api/timetable/Day.java @@ -0,0 +1,55 @@ +package io.github.wulkanowy.api.timetable; + +import java.util.ArrayList; +import java.util.List; + +public class Day { + + private List lessons = new ArrayList<>(); + + private String date = ""; + + private boolean isFreeDay = false; + + private String freeDayName = ""; + + public Lesson getLesson(int index) { + return lessons.get(index); + } + + public List getLessons() { + return lessons; + } + + public Day setLesson(Lesson lesson) { + this.lessons.add(lesson); + return this; + } + + public String getDate() { + return date; + } + + public Day setDate(String date) { + this.date = date; + return this; + } + + public boolean isFreeDay() { + return isFreeDay; + } + + public Day setFreeDay(boolean freeDay) { + isFreeDay = freeDay; + return this; + } + + public String getFreeDayName() { + return freeDayName; + } + + public Day setFreeDayName(String freeDayName) { + this.freeDayName = freeDayName; + return this; + } +} diff --git a/app/src/main/java/io/github/wulkanowy/api/timetable/Lesson.java b/app/src/main/java/io/github/wulkanowy/api/timetable/Lesson.java new file mode 100644 index 000000000..b7aaa16fe --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/api/timetable/Lesson.java @@ -0,0 +1,141 @@ +package io.github.wulkanowy.api.timetable; + +public class Lesson { + + public static final String CLASS_PLANNING = "x-treelabel-ppl"; + public static final String CLASS_REALIZED = "x-treelabel-rlz"; + public static final String CLASS_MOVED_OR_CANCELED = "x-treelabel-inv"; + public static final String CLASS_NEW_MOVED_IN_OR_CHANGED = "x-treelabel-zas"; + + private String subject = ""; + private String teacher = ""; + private String room = ""; + private String description = ""; + private String groupName = ""; + private String startTime = ""; + private String endTime = ""; + + private boolean isEmpty = false; + private boolean isDivisionIntoGroups = false; + private boolean isPlanning = false; + private boolean isRealized = false; + private boolean isMovedOrCanceled = false; + private boolean isNewMovedInOrChanged = false; + + public String getSubject() { + return subject; + } + + public Lesson setSubject(String subject) { + this.subject = subject; + return this; + } + + public String getTeacher() { + return teacher; + } + + public Lesson setTeacher(String teacher) { + this.teacher = teacher; + return this; + } + + public String getRoom() { + return room; + } + + public Lesson setRoom(String room) { + this.room = room; + return this; + } + + public String getDescription() { + return description; + } + + public Lesson setDescription(String description) { + this.description = description; + return this; + } + + public String getGroupName() { + return groupName; + } + + public Lesson setGroupName(String groupName) { + this.groupName = groupName; + return this; + } + + public String getStartTime() { + return startTime; + } + + public Lesson setStartTime(String startTime) { + this.startTime = startTime; + return this; + } + + public String getEndTime() { + return endTime; + } + + public Lesson setEndTime(String endTime) { + this.endTime = endTime; + return this; + } + + public boolean isEmpty() { + return isEmpty; + } + + public Lesson setEmpty(boolean empty) { + isEmpty = empty; + return this; + } + + public boolean isDivisionIntoGroups() { + return isDivisionIntoGroups; + } + + public Lesson setDivisionIntoGroups(boolean divisionIntoGroups) { + isDivisionIntoGroups = divisionIntoGroups; + return this; + } + + public boolean isPlanning() { + return isPlanning; + } + + public Lesson setPlanning(boolean planning) { + isPlanning = planning; + return this; + } + + public boolean isRealized() { + return isRealized; + } + + public Lesson setRealized(boolean realized) { + isRealized = realized; + return this; + } + + public boolean isMovedOrCanceled() { + return isMovedOrCanceled; + } + + public Lesson setMovedOrCanceled(boolean movedOrCanceled) { + isMovedOrCanceled = movedOrCanceled; + return this; + } + + public boolean isNewMovedInOrChanged() { + return isNewMovedInOrChanged; + } + + public Lesson setNewMovedInOrChanged(boolean newMovedInOrChanged) { + isNewMovedInOrChanged = newMovedInOrChanged; + return this; + } +} diff --git a/app/src/main/java/io/github/wulkanowy/api/timetable/Table.java b/app/src/main/java/io/github/wulkanowy/api/timetable/Table.java new file mode 100644 index 000000000..0a52778bc --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/api/timetable/Table.java @@ -0,0 +1,143 @@ +package io.github.wulkanowy.api.timetable; + +import org.apache.commons.lang3.StringUtils; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import io.github.wulkanowy.api.Vulcan; +import io.github.wulkanowy.api.login.LoginErrorException; + +public class Table extends Vulcan { + + private Timetable timetable; + + public Table(Timetable timetable) { + this.timetable = timetable; + } + + public Week getWeekTable() throws IOException, LoginErrorException { + return getWeekTable(""); + } + + public Week getWeekTable(String tick) throws IOException, LoginErrorException { + Element table = timetable.getTablePageDocument(tick) + .select(".mainContainer .presentData").first(); + + Elements tableHeaderCells = table.select("thead th"); + List days = new ArrayList<>(); + + for (int i = 2; i < 7; i++) { + String[] dayHeaderCell = tableHeaderCells.get(i).html().split("
"); + boolean isFreeDay = tableHeaderCells.get(i).hasClass("free-day"); + + Day day = new Day(); + day.setDate(dayHeaderCell[1]); + + if (isFreeDay) { + day.setFreeDay(isFreeDay); + day.setFreeDayName(dayHeaderCell[2]); + } + + days.add(day); + } + + Elements hoursInDays = table.select("tbody tr"); + + // fill days in week with lessons + for (Element row : hoursInDays) { + Elements hours = row.select("td"); + + // fill hours in day + for (int i = 2; i < hours.size(); i++) { + Lesson lesson = new Lesson(); + + Elements e = hours.get(i).select("div"); + switch (e.size()) { + case 1: + lesson = getLessonFromElement(e.first()); + break; + case 3: + lesson = getLessonFromElement(e.get(1)); + break; + default: + lesson.setEmpty(true); + break; + } + + String[] startEndEnd = hours.get(1).text().split(" "); + lesson.setStartTime(startEndEnd[0]); + lesson.setEndTime(startEndEnd[1]); + + days.get(i - 2).setLesson(lesson); + } + } + + Element startDayCellHeader = tableHeaderCells.get(2); + String[] dayDescription = startDayCellHeader.html().split("
"); + + return new Week() + .setStartDayDate(dayDescription[1]) + .setDays(days); + } + + public Lesson getLessonFromElement(Element e) { + Lesson lesson = new Lesson(); + Elements spans = e.select("span"); + + lesson.setSubject(spans.get(0).text()); + lesson.setTeacher(spans.get(1).text()); + lesson.setRoom(spans.get(2).text()); + + lesson = getLessonGroupDivisionInfo(lesson, spans); + lesson = getLessonTypeInfo(lesson, spans); + lesson = getLessonDescriptionInfo(lesson, spans); + + return lesson; + } + + public Lesson getLessonGroupDivisionInfo(Lesson lesson, Elements e) { + if ((4 == e.size() && (e.first().attr("class").equals("")) || + (5 == e.size() && e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED)))) { + lesson.setDivisionIntoGroups(true); + String[] subjectNameArray = lesson.getSubject().split(" "); + String groupName = subjectNameArray[subjectNameArray.length - 1]; + lesson.setSubject(lesson.getSubject().replace(" " + groupName, "")); + lesson.setGroupName(StringUtils.substringBetween(groupName, "[", "]")); + lesson.setTeacher(e.get(2).text()); + lesson.setRoom(e.get(3).text()); + } + + return lesson; + } + + public Lesson getLessonTypeInfo(Lesson lesson, Elements e) { + if (e.first().hasClass(Lesson.CLASS_MOVED_OR_CANCELED)) { + lesson.setMovedOrCanceled(true); + } else if (e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED)) { + lesson.setNewMovedInOrChanged(true); + } else if (e.first().hasClass(Lesson.CLASS_PLANNING)) { + lesson.setPlanning(true); + } + + if (e.last().hasClass(Lesson.CLASS_REALIZED) + || e.first().attr("class").equals("")) { + lesson.setRealized(true); + } + + return lesson; + } + + public Lesson getLessonDescriptionInfo(Lesson lesson, Elements e) { + if ((4 == e.size() || 5 == e.size()) + && (e.first().hasClass(Lesson.CLASS_MOVED_OR_CANCELED) + || e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED))) { + lesson.setDescription(StringUtils.substringBetween(e.last().text(), "(", ")")); + } + + return lesson; + } +} diff --git a/app/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java b/app/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java new file mode 100644 index 000000000..ce2cf2f65 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java @@ -0,0 +1,33 @@ +package io.github.wulkanowy.api.timetable; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; + +import java.io.IOException; + +import io.github.wulkanowy.api.Cookies; +import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.Vulcan; +import io.github.wulkanowy.api.login.LoginErrorException; + +public class Timetable extends Vulcan { + + private StudentAndParent snp; + + private String timetablePageurl = + "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Lekcja.mvc/PlanLekcji?data="; + + public Timetable(Cookies cookies, StudentAndParent snp) { + this.cookies = cookies; + this.snp = snp; + } + + public Document getTablePageDocument(String tick) throws IOException, LoginErrorException { + timetablePageurl = timetablePageurl.replace("{locationID}", snp.getLocationID()); + timetablePageurl = timetablePageurl.replace("{ID}", snp.getID()); + + return Jsoup.connect(timetablePageurl + tick) + .cookies(getCookies()) + .get(); + } +} diff --git a/app/src/main/java/io/github/wulkanowy/api/timetable/Week.java b/app/src/main/java/io/github/wulkanowy/api/timetable/Week.java new file mode 100644 index 000000000..ddcd96703 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/api/timetable/Week.java @@ -0,0 +1,33 @@ +package io.github.wulkanowy.api.timetable; + +import java.util.ArrayList; +import java.util.List; + +public class Week { + + private List days = new ArrayList<>(); + + private String startDayDate = ""; + + public Day getDay(int index) { + return days.get(index); + } + + public List getDays() { + return days; + } + + public Week setDays(List days) { + this.days = days; + return this; + } + + public String getStartDayDate() { + return startDayDate; + } + + public Week setStartDayDate(String startDayDate) { + this.startDayDate = startDayDate; + return this; + } +} diff --git a/app/src/main/java/io/github/wulkanowy/utilities/DateHelper.java b/app/src/main/java/io/github/wulkanowy/utilities/DateHelper.java new file mode 100644 index 000000000..5677f721a --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utilities/DateHelper.java @@ -0,0 +1,37 @@ +package io.github.wulkanowy.utilities; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +abstract public class DateHelper { + + private static final long TICKS_AT_EPOCH = 621355968000000000L; + private static final long TICKS_PER_MILLISECOND = 10000; + + public static long getTicks(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + return (calendar.getTimeInMillis() * TICKS_PER_MILLISECOND) + TICKS_AT_EPOCH; + } + + public static long getTics(String dateString) throws ParseException { + return getTics(dateString, "dd.MM.yyyy"); + } + + public static long getTics(String dateString, String dateFormat) throws ParseException { + SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + Date dateObject = format.parse(dateString); + + return getTicks(dateObject); + } + + public static Date getDate(long ticks) { + return new Date((ticks - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND); + } +} diff --git a/app/src/test/java/io/github/wulkanowy/api/timetable/TableTest.java b/app/src/test/java/io/github/wulkanowy/api/timetable/TableTest.java new file mode 100644 index 000000000..b813f1238 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/api/timetable/TableTest.java @@ -0,0 +1,218 @@ +package io.github.wulkanowy.api.timetable; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import io.github.wulkanowy.api.FixtureHelper; + +public class TableTest { + + private String fixtureStdFileName = "PlanLekcji-std.html"; + private String fixtureHolidaysFileName = "PlanLekcji-holidays.html"; + private String fixtureFullFileName = "PlanLekcji-full.html"; + + private Table getSetUpTable(String tick, String fixtureFileName) throws Exception { + String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName)); + + Document tablePageDocument = Jsoup.parse(input); + + Timetable timetable = Mockito.mock(Timetable.class); + Mockito.when(timetable.getTablePageDocument(tick)).thenReturn(tablePageDocument); + + return new Table(timetable); + } + + @Test + public void getWeekTableStandardTest() throws Exception { + Table table = getSetUpTable("", fixtureStdFileName); + Week week = table.getWeekTable(); + + Assert.assertEquals(5, week.getDays().size()); + Assert.assertEquals("19.06.2017", week.getStartDayDate()); + + Assert.assertEquals("19.06.2017", week.getDay(0).getDate()); + Assert.assertEquals("23.06.2017", week.getDay(4).getDate()); + + Assert.assertFalse(week.getDay(4).isFreeDay()); + } + + @Test + public void getWeekTableStandardLessonStartEndEndTest() throws Exception { + Table tableStd = getSetUpTable("", fixtureStdFileName); + Week stdWeek = tableStd.getWeekTable(); + + Assert.assertEquals("08:00", stdWeek.getDay(0).getLesson(0).getStartTime()); + Assert.assertEquals("08:45", stdWeek.getDay(1).getLesson(0).getEndTime()); + Assert.assertEquals("12:15", stdWeek.getDay(2).getLesson(4).getEndTime()); + Assert.assertEquals("14:10", stdWeek.getDay(3).getLesson(7).getStartTime()); + + Table tableFull = getSetUpTable("", fixtureFullFileName); + Week fullWeek = tableFull.getWeekTable(); + + Assert.assertEquals("07:10", fullWeek.getDay(0).getLesson(0).getStartTime()); + Assert.assertEquals("07:55", fullWeek.getDay(1).getLesson(0).getEndTime()); + Assert.assertEquals("12:20", fullWeek.getDay(2).getLesson(6).getStartTime()); + Assert.assertEquals("19:00", fullWeek.getDay(3).getLesson(13).getEndTime()); + + } + + @Test(expected = IndexOutOfBoundsException.class) + public void getWeekTableStandardOutOfBoundsIndex() throws Exception { + Table table = getSetUpTable("", fixtureStdFileName); + Week week = table.getWeekTable(); + + week.getDay(5); + } + + @Test + public void getWeekTableHolidaysTest() throws Exception { + Table table = getSetUpTable("", fixtureHolidaysFileName); + Week week = table.getWeekTable(); + + Assert.assertTrue(week.getDay(1).isFreeDay()); + + Assert.assertNotEquals("Wakacje", week.getDay(2).getFreeDayName()); + + Assert.assertEquals("Ferie letnie", week.getDay(3).getFreeDayName()); + Assert.assertEquals("31.07.2017", week.getStartDayDate()); + Assert.assertEquals(5, week.getDays().size()); + Assert.assertEquals(14, week.getDay(4).getLessons().size()); + } + + @Test + public void getWeekTableHolidaysWithEmptyLessonsTest() throws Exception { + Table table = getSetUpTable("", fixtureHolidaysFileName); + Week week = table.getWeekTable(); + + Assert.assertEquals(5, week.getDays().size()); + + Assert.assertTrue(week.getDay(0).getLesson(5).isEmpty()); + Assert.assertTrue(week.getDay(2).getLesson(13).isEmpty()); + Assert.assertTrue(week.getDay(3).getLesson(0).isEmpty()); + Assert.assertTrue(week.getDay(4).getLesson(13).isEmpty()); + } + + @Test + public void getWeekTableFullTest() throws Exception { + Table table = getSetUpTable("", fixtureFullFileName); + Week week = table.getWeekTable(); + + Assert.assertFalse(week.getDay(1).getLesson(2).isEmpty()); + } + + @Test + public void getWeekTableFullLessonsGroupsDivisionTest() throws Exception { + Table table = getSetUpTable("", fixtureFullFileName); + Week week = table.getWeekTable(); + + // class="", span*4 + Lesson lesson1 = week.getDay(0).getLesson(1); + Assert.assertTrue(lesson1.isDivisionIntoGroups()); + Assert.assertEquals("J1", lesson1.getGroupName()); + + // class="", span*3 + Lesson lesson2 = week.getDay(0).getLesson(7); + Assert.assertFalse(lesson2.isDivisionIntoGroups()); + Assert.assertEquals("", lesson2.getGroupName()); + + // div*3 (2), class="x-treelabel-zas", span*4 + Lesson lesson3 = week.getDay(1).getLesson(2); + Assert.assertFalse(lesson3.isDivisionIntoGroups()); + Assert.assertEquals("", lesson3.getGroupName()); + + // div*3 (2), class="x-treelabel-zas", span*5 + Lesson lesson4 = week.getDay(1).getLesson(3); + Assert.assertTrue(lesson4.isDivisionIntoGroups()); + Assert.assertEquals("wf2", lesson4.getGroupName()); + + // class="x-treelabel-ppl", span*3 + Lesson lesson5 = week.getDay(4).getLesson(0); + Assert.assertFalse(lesson5.isDivisionIntoGroups()); + Assert.assertEquals("", lesson5.getGroupName()); + } + + @Test + public void getWeekTableFullLessonsTypesTest() throws Exception { + Table table = getSetUpTable("", fixtureFullFileName); + Week week = table.getWeekTable(); + + // class="", span*4 + Lesson lesson1 = week.getDay(0).getLesson(1); + Assert.assertFalse(lesson1.isPlanning()); + Assert.assertTrue(lesson1.isRealized()); + Assert.assertFalse(lesson1.isMovedOrCanceled()); + Assert.assertFalse(lesson1.isNewMovedInOrChanged()); + + // class="", span*3 + Lesson lesson2 = week.getDay(0).getLesson(7); + Assert.assertFalse(lesson2.isPlanning()); + Assert.assertTrue(lesson2.isRealized()); + Assert.assertTrue(lesson2.isMovedOrCanceled()); + Assert.assertFalse(lesson2.isNewMovedInOrChanged()); + + // div*3 (2), class="x-treelabel-zas", span*4 + Lesson lesson3 = week.getDay(1).getLesson(2); + Assert.assertFalse(lesson3.isPlanning()); + Assert.assertTrue(lesson3.isRealized()); + Assert.assertFalse(lesson3.isMovedOrCanceled()); + Assert.assertTrue(lesson3.isNewMovedInOrChanged()); + + // div*3 (2), class="x-treelabel-zas", span*5 + Lesson lesson4 = week.getDay(1).getLesson(3); + Assert.assertFalse(lesson4.isPlanning()); + Assert.assertTrue(lesson4.isRealized()); + Assert.assertFalse(lesson4.isMovedOrCanceled()); + Assert.assertTrue(lesson4.isNewMovedInOrChanged()); + + // class="x-treelabel-ppl", span*3 + Lesson lesson5 = week.getDay(4).getLesson(0); + Assert.assertTrue(lesson5.isPlanning()); + Assert.assertFalse(lesson5.isRealized()); + Assert.assertFalse(lesson5.isMovedOrCanceled()); + Assert.assertFalse(lesson5.isNewMovedInOrChanged()); + } + + @Test + public void getWeekTableFullLessonsBasicInfoTest() throws Exception { + Table table = getSetUpTable("", fixtureFullFileName); + Week week = table.getWeekTable(); + + // class="", span*4 + Lesson lesson1 = week.getDay(0).getLesson(1); + Assert.assertEquals("Język angielski", lesson1.getSubject()); + Assert.assertEquals("Kobczyk Iwona", lesson1.getTeacher()); + Assert.assertEquals("", lesson1.getRoom()); + Assert.assertEquals("", lesson1.getDescription()); + + // class="", span*3 + Lesson lesson2 = week.getDay(0).getLesson(7); + Assert.assertEquals("Fizyka", lesson2.getSubject()); + Assert.assertEquals("Bączek Grzegorz", lesson2.getTeacher()); + Assert.assertEquals("33", lesson2.getRoom()); + Assert.assertEquals("okienko dla uczniów", lesson2.getDescription()); + + // div*3 (2), class="x-treelabel-zas", span*4 + Lesson lesson3 = week.getDay(1).getLesson(2); + Assert.assertEquals("Język polski", lesson3.getSubject()); + Assert.assertEquals("Bocian Natalia", lesson3.getTeacher()); + Assert.assertEquals("", lesson3.getRoom()); + Assert.assertEquals("przeniesiona z lekcji 7, 20.06.2017", lesson3.getDescription()); + + // div*3 (2), class="x-treelabel-zas", span*5 + Lesson lesson4 = week.getDay(1).getLesson(3); + Assert.assertEquals("Wychowanie fizyczne", lesson4.getSubject()); + Assert.assertEquals("Nowicka Irena", lesson4.getTeacher()); + Assert.assertEquals("", lesson4.getRoom()); + Assert.assertEquals("przeniesiona z lekcji 4, 20.06.2017", lesson4.getDescription()); + + // class="x-treelabel-ppl", span*3 + Lesson lesson5 = week.getDay(4).getLesson(0); + Assert.assertEquals("Uroczyste zakończenie roku szkolnego", lesson5.getSubject()); + Assert.assertEquals("Baran Małgorzata", lesson5.getTeacher()); + Assert.assertEquals("37", lesson5.getRoom()); + Assert.assertEquals("", lesson5.getDescription()); + } +} diff --git a/app/src/test/java/io/github/wulkanowy/utilities/DateHelperTest.java b/app/src/test/java/io/github/wulkanowy/utilities/DateHelperTest.java new file mode 100644 index 000000000..d6a99def7 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/utilities/DateHelperTest.java @@ -0,0 +1,58 @@ +package io.github.wulkanowy.utilities; + +import org.junit.Assert; +import org.junit.Test; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +public class DateHelperTest extends DateHelper { + + @Test + public void getTicksDateObjectTest() throws Exception { + SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + Date date = format.parse("31.07.2017"); + + Assert.assertEquals(636370560000000000L, DateHelper.getTicks(date)); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.DAY_OF_YEAR, -14); + Date dateTwoWeekBefore = calendar.getTime(); + + Assert.assertEquals(636358464000000000L, DateHelper.getTicks(dateTwoWeekBefore)); + } + + @Test(expected = ParseException.class) + public void getTicsStringInvalidFormatTest() throws Exception { + Assert.assertEquals(636370560000000000L, DateHelper.getTics("31.07.2017", "dd.MMM.yyyy")); + } + + @Test + public void getTicsStringFormatTest() throws Exception { + Assert.assertEquals(636370560000000000L, DateHelper.getTics("31.07.2017", "dd.MM.yyyy")); + } + + @Test + public void getTicsStringTest() throws Exception { + Assert.assertEquals(636370560000000000L, DateHelper.getTics("31.07.2017")); + Assert.assertEquals(636334272000000000L, DateHelper.getTics("19.06.2017")); + Assert.assertEquals(636189120000000000L, DateHelper.getTics("02.01.2017")); + Assert.assertEquals(636080256000000000L, DateHelper.getTics("29.08.2016")); + } + + @Test + public void getDateTest() throws Exception { + DateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + Date date = format.parse("31.07.2017"); + + Assert.assertEquals(date, DateHelper.getDate(636370560000000000L)); + } +} diff --git a/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html new file mode 100644 index 000000000..fc717ae7e --- /dev/null +++ b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html @@ -0,0 +1,405 @@ + + + + + Witryna ucznia i rodzica – Plan lekcji + + +
+

Plan lekcji

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LekcjaPora lekcjiponiedziałek
19.06.2017
wtorek
20.06.2017
środa
21.06.2017
czwartek
22.06.2017
piątek
23.06.2017
007:10 07:55 +
+ Uroczyste zakończenie roku szkolnego + Baran Małgorzata + 37 +
+
108:00 08:45 +
+ Język angielski [J1] + + Kobczyk Iwona + +
+
+
+ Użytkowanie urządzeń peryferyjnych komputera [zaw2] + + Bączek Robert + +
+
208:50 09:35 +
+ Język polski + Bocian Natalia + +
+
+
+ Język niemiecki [J1] + + Rożeniec Honorata + 25 + (okienko dla uczniów) +
+
+ Język polski + Bocian Natalia + + (przeniesiona z lekcji 7, 20.06.2017) +
+
+ Język polski + Bocian Natalia + +
+
+
+ Urządzenia techniki komputerowej [zaw2] + + Bocian Grzegorz + +
+
+
+ Matematyka + Baran Małgorzata + +
+
309:40 10:25 +
+ Język polski + Bocian Natalia + +
+
+
+ Fizyka + Bączek Grzegorz + 19 + (okienko dla uczniów) +
+
+ Wychowanie fizyczne [wf2] + + Nowicka Irena + + (przeniesiona z lekcji 4, 20.06.2017) +
+
+ Wychowanie fizyczne [wf2] + + Nowicka Irena + +
+
+
+ Metodologia programowania [zaw2] + + Baran Małgorzata + +
+
+
+ Wychowanie fizyczne [wf2] + + Nowicka Irena + +
+
410:40 11:25 +
+ Urządzenia techniki komputerowej [zaw2] + + Bocian Grzegorz + +
+
+
+ Wychowanie fizyczne [wf2] + + Nowicka Irena + + (przeniesiona na lekcję 3, 20.06.2017) +
+
+
+ Matematyka + Baran Małgorzata + +
+
+
+ Wychowanie fizyczne [wf2] + + Nowicka Irena + +
+
511:30 12:15 +
+ Urządzenia techniki komputerowej [zaw2] + + Bocian Grzegorz + +
+
+
+ Podstawy przedsiębiorczości + Bogatka Anna + W12 + (okienko dla uczniów) +
+
+
+ Religia + Cyranka Krystian + +
+
+
+ Sieci komputerowe i administrowanie sieciami [zaw2] + + Rożeniec Piotr + +
+
612:20 13:05 +
+ Matematyka + Baran Małgorzata + +
+
+
+ Podstawy przedsiębiorczości + Bogatka Anna + W12 + (okienko dla uczniów) +
+
+
+ Język angielski [J1] + + Brodziec Sylwia + +
+
+
+ Religia + Cyranka Krystian + +
+
713:10 13:55 +
+ Fizyka + Bączek Grzegorz + 33 + (okienko dla uczniów) +
+
+
+ Język polski + Bocian Natalia + + (przeniesiona na lekcję 2, 20.06.2017) +
+
+
+ Multimedia i grafika komputerowa [zaw2] + + Bocian Konrad + +
+
+
+ Wiedza o kulturze + Bocian Natalia + +
+
814:00 14:45 +
+ Zajęcia z wychowawcą + Baran Małgorzata + +
+
+
+ Naprawa komputera [zaw2] + + Kraska Maciej + 32 + (okienko dla uczniów) +
+
+
+ Systemy operacyjne [zaw2] + + Kraska Maciej + 32 +
+
914:50 15:35 +
+ Język niemiecki [J1] + + Rożeniec Honorata + 25 + (uczniowie zwolnieni do domu) +
+
1015:40 16:25
1116:35 17:20
1217:25 18:10
1318:15 19:00
+
+
+
+ Kursywa- planowane +
+
+ Zwykła czcionka- zrealizowane +
+
+ Przekreślone- odwołane lub przeniesione +
+
+ Pogrubione- nowe lekcje, przeniesione z innego terminu, zastępstwa +
+
+
+
wersja: 17.05.0000.24042
+ + diff --git a/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-holidays.html b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-holidays.html new file mode 100644 index 000000000..09555cf3f --- /dev/null +++ b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-holidays.html @@ -0,0 +1,156 @@ + + + + + Witryna ucznia i rodzica – Plan lekcji + + +
+

Plan lekcji

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LekcjaPora lekcjiponiedziałek
31.07.2017
Ferie letnie
wtorek
01.08.2017
Ferie letnie
środa
02.08.2017
Ferie letnie
czwartek
03.08.2017
Ferie letnie
piątek
04.08.2017
Ferie letnie
007:10 07:55
108:00 08:45
208:50 09:35
309:40 10:25
410:40 11:25
511:30 12:15
612:20 13:05
713:10 13:55
814:00 14:45
914:50 15:35
1015:40 16:25
1116:35 17:20
1217:25 18:10
1318:15 19:00
+
+
+
wersja: 17.05.0000.24042
+ + diff --git a/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-std.html b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-std.html new file mode 100644 index 000000000..345a1ff53 --- /dev/null +++ b/app/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-std.html @@ -0,0 +1,303 @@ + + + + + Witryna ucznia i rodzica – Plan lekcji + + +
+

Plan lekcji

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LekcjaPora lekcjiponiedziałek
19.06.2017
wtorek
20.06.2017
środa
21.06.2017
czwartek
22.06.2017
piątek
23.06.2017
108:00 08:45 +
+ Edukacja dla bezpieczeństwa + Kobczyk Iwona + +
+
+
+ Język niemiecki [JNPW] + + Dzwoniec Ewa + +
+
+
+ Wychowanie do życia w rodzinie + Baran Dominika + +
+
+
+ Język niemiecki [JNPW] + + Dzwoniec Ewa + +
+
208:50 09:35 +
+ Historia + Bogatka Katarzyna + +
+
+
+ Wychowanie fizyczne [CH] + + Brodziec Dominika + +
+
+
+ Fizyka + Bocian Łukasz + +
+
+
+ Biologia + Kowalska Anna + +
+
+
+ Religia + Kraska Maciej + +
+
309:40 10:25 +
+ Wychowanie fizyczne [CH] + + Brodziec Dominika + +
+
+
+ Język polski + Rożeniec Paulina + +
+
+
+ Matematyka + Bączek Dominika + +
+
+
+ Plastyka + Rożeniec Paulina + +
+
+
+ Zajęcia z wychowawcą + Kowalska Anna + +
+
410:30 11:15 +
+ Geografia + Orłowski Konrad + +
+
+
+ Matematyka + Bączek Dominika + +
+
+
+ Język angielski [JAPN] + + Biegus Kazimiera + +
+
+
+ Matematyka + Bączek Dominika + +
+
+
+ Historia + Bogatka Katarzyna + +
+
511:30 12:15 +
+ Matematyka + Bączek Dominika + +
+
+
+ Biologia + Kowalska Anna + +
+
+
+ Zajęcia techniczne + Chlebowski Stanisław + +
+
+
+ Język angielski [JAPN] + + Biegus Kazimiera + +
+
+
+ Język polski + Rożeniec Paulina + +
+
612:30 13:15 +
+ Matematyka + Bączek Dominika + +
+
+
+ Fizyka + Bocian Łukasz + +
+
+
+ Język polski + Rożeniec Paulina + +
+
+
+ Wychowanie fizyczne [CH] + + Brodziec Dominika + +
+
+
+ Język polski + Rożeniec Paulina + +
+
713:20 14:05 +
+ Język angielski [JAPN] + + Biegus Kazimiera + +
+
+
+ Religia + Kraska Maciej + +
+
+
+ Wychowanie fizyczne [CH] + + Brodziec Dominika + +
+
814:10 14:55
+
+
+ + +