API attendance (#24)

This commit is contained in:
Mikołaj Pich
2017-09-19 19:15:35 +02:00
committed by GitHub
parent aae3d5d357
commit c876d114e3
16 changed files with 1746 additions and 0 deletions

View File

@ -0,0 +1,159 @@
package io.github.wulkanowy.api.attendance;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.List;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.StudentAndParent;
public class StatisticsTest {
private Statistics excellent;
private Statistics full;
@Before
public void setUp() throws Exception {
this.excellent = getSetUpTable("Frekwencja-excellent.html");
this.full = getSetUpTable("Frekwencja-full.html");
}
private Statistics getSetUpTable(String fixtureFileName) throws Exception {
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
Document tablePageDocument = Jsoup.parse(input);
StudentAndParent timetable = Mockito.mock(StudentAndParent.class);
Mockito.when(timetable.getSnPPageDocument(Mockito.anyString()))
.thenReturn(tablePageDocument);
return new Statistics(timetable);
}
@Test
public void getSubjectList() throws Exception {
Assert.assertEquals(26, excellent.getSubjectList().size());
Assert.assertEquals(23, full.getSubjectList().size());
}
@Test
public void getSubjectListId() throws Exception {
Assert.assertEquals(-1, excellent.getSubjectList().get(0).getId());
Assert.assertEquals(63, excellent.getSubjectList().get(10).getId());
Assert.assertEquals(0, excellent.getSubjectList().get(25).getId());
Assert.assertEquals(-1, full.getSubjectList().get(0).getId());
Assert.assertEquals(108, full.getSubjectList().get(14).getId());
Assert.assertEquals(492, full.getSubjectList().get(21).getId());
}
@Test
public void getSubjectListName() throws Exception {
Assert.assertEquals("Wszystkie", excellent.getSubjectList().get(0).getName());
Assert.assertEquals("Fizyka", excellent.getSubjectList().get(8).getName());
Assert.assertEquals("Sieci komputerowe i administrowanie sieciami",
excellent.getSubjectList().get(21).getName());
Assert.assertEquals("Praktyka zawodowa", full.getSubjectList().get(11).getName());
Assert.assertEquals("Użytkowanie urządzeń peryferyjnych komputera",
full.getSubjectList().get(16).getName());
Assert.assertEquals("Brak opisu lekcji", full.getSubjectList().get(22).getName());
}
@Test
public void getTypesTotal() throws Exception {
Assert.assertEquals(100.0, excellent.getTypesTable().getTotal(), 0);
Assert.assertEquals(80.94, full.getTypesTable().getTotal(), 0);
}
@Test
public void getTypeName() throws Exception {
List<Type> typeList1 = excellent.getTypesTable().getTypeList();
Assert.assertEquals("Obecność", typeList1.get(0).getName());
Assert.assertEquals("Nieobecność nieusprawiedliwiona", typeList1.get(1).getName());
Assert.assertEquals("Nieobecność usprawiedliwiona", typeList1.get(2).getName());
Assert.assertEquals("Nieobecność z przyczyn szkolnych", typeList1.get(3).getName());
List<Type> typeList2 = full.getTypesTable().getTypeList();
Assert.assertEquals("Spóźnienie nieusprawiedliwione", typeList2.get(4).getName());
Assert.assertEquals("Spóźnienie usprawiedliwione", typeList2.get(5).getName());
Assert.assertEquals("Zwolnienie", typeList2.get(6).getName());
}
@Test
public void getTypeTotal() throws Exception {
List<Type> typeList1 = excellent.getTypesTable().getTypeList();
Assert.assertEquals(1211, typeList1.get(0).getTotal());
Assert.assertEquals(0, typeList1.get(1).getTotal());
Assert.assertEquals(0, typeList1.get(2).getTotal());
Assert.assertEquals(0, typeList1.get(3).getTotal());
Assert.assertEquals(0, typeList1.get(4).getTotal());
Assert.assertEquals(0, typeList1.get(5).getTotal());
Assert.assertEquals(0, typeList1.get(6).getTotal());
List<Type> typeList2 = full.getTypesTable().getTypeList();
Assert.assertEquals(822, typeList2.get(0).getTotal());
Assert.assertEquals(6, typeList2.get(1).getTotal());
Assert.assertEquals(192, typeList2.get(2).getTotal());
Assert.assertEquals(7, typeList2.get(3).getTotal());
Assert.assertEquals(12, typeList2.get(4).getTotal());
Assert.assertEquals(1, typeList2.get(5).getTotal());
Assert.assertEquals(2, typeList2.get(6).getTotal());
}
@Test
public void getTypeList() throws Exception {
List<Type> typesList1 = excellent.getTypesTable().getTypeList();
Assert.assertEquals(12, typesList1.get(0).getMonthList().size());
Assert.assertEquals(12, typesList1.get(5).getMonthList().size());
List<Type> typesList2 = full.getTypesTable().getTypeList();
Assert.assertEquals(12, typesList2.get(0).getMonthList().size());
Assert.assertEquals(12, typesList2.get(5).getMonthList().size());
}
@Test
public void getMonthList() throws Exception {
List<Type> typeList1 = excellent.getTypesTable().getTypeList();
Assert.assertEquals(12, typeList1.get(0).getMonthList().size());
List<Type> typeList2 = full.getTypesTable().getTypeList();
Assert.assertEquals(12, typeList2.get(0).getMonthList().size());
}
@Test
public void getMonthName() throws Exception {
List<Month> monthsList1 = excellent.getTypesTable().getTypeList().get(0).getMonthList();
Assert.assertEquals("IX", monthsList1.get(0).getName());
Assert.assertEquals("III", monthsList1.get(6).getName());
Assert.assertEquals("VIII", monthsList1.get(11).getName());
List<Month> monthsList2 = full.getTypesTable().getTypeList().get(0).getMonthList();
Assert.assertEquals("XI", monthsList2.get(2).getName());
Assert.assertEquals("II", monthsList2.get(5).getName());
Assert.assertEquals("VI", monthsList2.get(9).getName());
}
@Test
public void getMonthValue() throws Exception {
List<Month> monthsList1 = excellent.getTypesTable().getTypeList().get(0).getMonthList();
Assert.assertEquals(142, monthsList1.get(0).getValue());
Assert.assertEquals(131, monthsList1.get(4).getValue());
Assert.assertEquals(139, monthsList1.get(7).getValue());
Assert.assertEquals(114, monthsList1.get(9).getValue());
Assert.assertEquals(0, monthsList1.get(11).getValue());
List<Type> typeList1 = full.getTypesTable().getTypeList();
Assert.assertEquals(135, typeList1.get(0).getMonthList().get(0).getValue());
Assert.assertEquals(7, typeList1.get(3).getMonthList().get(5).getValue());
Assert.assertEquals(1, typeList1.get(5).getMonthList().get(0).getValue());
Assert.assertEquals(27, typeList1.get(2).getMonthList().get(9).getValue());
Assert.assertEquals(0, typeList1.get(0).getMonthList().get(11).getValue());
}
}

View File

@ -0,0 +1,181 @@
package io.github.wulkanowy.api.attendance;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.StudentAndParent;
public class TableTest {
private Table excellent;
private Table full;
@Before
public void setUp() throws Exception {
excellent = getSetUpTable("Frekwencja-excellent.html");
full = getSetUpTable("Frekwencja-full.html");
}
public Table getSetUpTable(String fixtureFileName) throws Exception {
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
Document tablePageDocument = Jsoup.parse(input);
StudentAndParent timetable = Mockito.mock(StudentAndParent.class);
Mockito.when(timetable.getSnPPageDocument(Mockito.anyString()))
.thenReturn(tablePageDocument);
return new Table(timetable);
}
@Test
public void getWeekStartByDate() throws Exception {
Assert.assertEquals("31.08.2015", excellent.getWeekTable().getStartDayDate());
Assert.assertEquals("05.09.2016", full.getWeekTable().getStartDayDate());
}
@Test
public void getWeekDaysNumber() throws Exception {
Assert.assertEquals(5, excellent.getWeekTable().getDays().size());
Assert.assertEquals(5, full.getWeekTable().getDays().size());
}
@Test
public void getDayLessonsNumber() throws Exception {
Assert.assertEquals(14, excellent.getWeekTable().getDay(0).getLessons().size());
Assert.assertEquals(14, full.getWeekTable().getDay(0).getLessons().size());
}
@Test
public void getDayDate() throws Exception {
Assert.assertEquals("31.08.2015", excellent.getWeekTable().getDay(0).getDate());
Assert.assertEquals("02.09.2015", excellent.getWeekTable().getDay(2).getDate());
Assert.assertEquals("04.09.2015", excellent.getWeekTable().getDay(4).getDate());
Assert.assertEquals("05.09.2016", full.getWeekTable().getDay(0).getDate());
Assert.assertEquals("07.09.2016", full.getWeekTable().getDay(2).getDate());
Assert.assertEquals("09.09.2016", full.getWeekTable().getDay(4).getDate());
}
@Test
public void getLessonSubject() throws Exception {
Assert.assertEquals("",
excellent.getWeekTable().getDay(0).getLesson(7).getSubject());
Assert.assertEquals("Uroczyste rozpoczęcie roku szkolnego 2015/2016",
excellent.getWeekTable().getDay(1).getLesson(1).getSubject());
Assert.assertEquals("Geografia",
excellent.getWeekTable().getDay(3).getLesson(4).getSubject());
Assert.assertEquals("Naprawa komputera",
full.getWeekTable().getDay(1).getLesson(8).getSubject());
Assert.assertEquals("Religia",
full.getWeekTable().getDay(3).getLesson(1).getSubject());
Assert.assertEquals("Metodologia programowania",
full.getWeekTable().getDay(4).getLesson(5).getSubject());
}
@Test
public void getLessonIsNotExist() throws Exception {
Assert.assertTrue(excellent.getWeekTable().getDay(0).getLesson(5).isNotExist());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(1).isNotExist());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(12).isNotExist());
Assert.assertFalse(full.getWeekTable().getDay(1).getLesson(12).isAbsenceUnexcused());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isAbsenceUnexcused());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(5).isAbsenceUnexcused());
}
@Test
public void getLessonIsEmpty() throws Exception {
Assert.assertTrue(excellent.getWeekTable().getDay(0).getLesson(0).isEmpty());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(6).isEmpty());
Assert.assertTrue(excellent.getWeekTable().getDay(4).getLesson(12).isEmpty());
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(9).isEmpty());
Assert.assertFalse(full.getWeekTable().getDay(2).getLesson(5).isEmpty());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(2).isEmpty());
}
@Test
public void getLessonIsPresence() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(7).isPresence());
Assert.assertTrue(excellent.getWeekTable().getDay(1).getLesson(1).isPresence());
Assert.assertTrue(excellent.getWeekTable().getDay(3).getLesson(7).isPresence());
Assert.assertTrue(full.getWeekTable().getDay(0).getLesson(1).isPresence());
Assert.assertTrue(full.getWeekTable().getDay(2).getLesson(6).isPresence());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(7).isPresence());
}
@Test
public void getLessonIsAbsenceUnexcused() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(7).isAbsenceUnexcused());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(0).isAbsenceUnexcused());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(4).isAbsenceUnexcused());
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(8).isAbsenceUnexcused());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isAbsenceUnexcused());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(8).isAbsenceUnexcused());
}
@Test
public void getLessonIsAbsenceExcused() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(7).isAbsenceExcused());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(0).isAbsenceExcused());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(4).isAbsenceExcused());
Assert.assertFalse(full.getWeekTable().getDay(2).getLesson(5).isAbsenceExcused());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isAbsenceExcused());
Assert.assertTrue(full.getWeekTable().getDay(4).getLesson(3).isAbsenceExcused());
}
@Test
public void getLessonIsAbsenceForSchoolReasons() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(4).isAbsenceForSchoolReasons());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(8).isAbsenceForSchoolReasons());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(12).isAbsenceForSchoolReasons());
Assert.assertTrue(full.getWeekTable().getDay(2).getLesson(5).isAbsenceForSchoolReasons());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isAbsenceForSchoolReasons());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(8).isAbsenceForSchoolReasons());
}
@Test
public void getLessonIsUnexcusedLateness() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(4).isUnexcusedLateness());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(8).isUnexcusedLateness());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(12).isUnexcusedLateness());
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(6).isUnexcusedLateness());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isUnexcusedLateness());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(8).isUnexcusedLateness());
}
@Test
public void getLessonIsExcusedLateness() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(4).isExcusedLateness());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(8).isExcusedLateness());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(12).isExcusedLateness());
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(7).isExcusedLateness());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isExcusedLateness());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(8).isExcusedLateness());
}
@Test
public void getLessonIsExemption() throws Exception {
Assert.assertFalse(excellent.getWeekTable().getDay(0).getLesson(4).isExemption());
Assert.assertFalse(excellent.getWeekTable().getDay(2).getLesson(8).isExemption());
Assert.assertFalse(excellent.getWeekTable().getDay(4).getLesson(12).isExemption());
Assert.assertFalse(full.getWeekTable().getDay(2).getLesson(5).isExemption());
Assert.assertFalse(full.getWeekTable().getDay(3).getLesson(1).isExemption());
Assert.assertTrue(full.getWeekTable().getDay(4).getLesson(8).isExemption());
}
}