1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 12:58:21 +01:00

API improvements (#13)

This commit is contained in:
Mikołaj Pich 2017-08-07 08:24:45 +02:00 committed by RicomenPL
parent 3d6515bcf2
commit 0ea13cdadd
41 changed files with 829 additions and 405 deletions

View File

@ -19,7 +19,6 @@ import java.util.Map;
import io.github.wulkanowy.R;
import io.github.wulkanowy.api.Cookies;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.grades.Grades;
import io.github.wulkanowy.api.grades.GradesList;
import io.github.wulkanowy.api.grades.Subject;
import io.github.wulkanowy.api.grades.SubjectsList;
@ -93,8 +92,8 @@ public class MarksFragment extends Fragment {
Account account = accountsDatabase.getAccount(mContext.getSharedPreferences("LoginData", mContext.MODE_PRIVATE).getLong("isLogin", 0));
accountsDatabase.close();
StudentAndParent snp = new StudentAndParent(cookies, account.getCounty()).setUp();
SubjectsList subjectsList = new SubjectsList(snp.getCookiesObject(), snp);
StudentAndParent snp = new StudentAndParent(cookies, account.getCounty());
SubjectsList subjectsList = new SubjectsList(snp);
SubjectsDatabase subjectsDatabase = new SubjectsDatabase(mContext);
subjectsDatabase.open();
@ -106,8 +105,7 @@ public class MarksFragment extends Fragment {
subjectsName.add(subject.getName());
}
Grades gradesObject = new Grades(snp.getCookiesObject(), snp);
GradesList gradesList = new GradesList(gradesObject, snp);
GradesList gradesList = new GradesList(snp);
GradesDatabase gradesDatabase = new GradesDatabase(mContext);
gradesDatabase.open();
gradesDatabase.put(gradesList.getAll());

View File

@ -22,7 +22,6 @@ import io.github.wulkanowy.api.login.Login;
import io.github.wulkanowy.api.login.LoginErrorException;
import io.github.wulkanowy.api.user.BasicInformation;
import io.github.wulkanowy.api.user.PersonalData;
import io.github.wulkanowy.api.user.User;
import io.github.wulkanowy.database.accounts.Account;
import io.github.wulkanowy.database.accounts.AccountsDatabase;
import io.github.wulkanowy.security.CryptoException;
@ -80,9 +79,8 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
if (save) {
try {
StudentAndParent snp = new StudentAndParent(login.getCookiesObject(),
credentials[2]).setUp();
User user = new User(snp.getCookiesObject(), snp);
BasicInformation userInfo = new BasicInformation(user, snp);
credentials[2]);
BasicInformation userInfo = new BasicInformation(snp);
PersonalData personalData = userInfo.getPersonalData();
String firstAndLastName = personalData.getFirstAndLastName();

View File

@ -9,8 +9,6 @@ import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.github.wulkanowy.api.login.LoginErrorException;
@ -18,32 +16,22 @@ public class StudentAndParent extends Vulcan {
private String startPageUrl = "https://uonetplus.vulcan.net.pl/{locationID}/Start.mvc/Index";
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
+ "Oceny/Wszystkie";
private String baseUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/";
private String gradesPageUrl = baseUrl + "Oceny/Wszystkie";
private String locationID = "";
private String uonetPlusOpiekunUrl = "";
private String id = "";
public StudentAndParent(Cookies cookies, String locID) throws IOException {
public StudentAndParent(Cookies cookies, String locID) throws IOException, LoginErrorException {
this.cookies = cookies;
this.locationID = locID;
}
public String getGradesPageUrl() {
return gradesPageUrl;
}
public StudentAndParent setUp() throws IOException {
startPageUrl = startPageUrl.replace("{locationID}", locationID);
// get link to uonetplus-opiekun.vulcan.net.pl module
Document startPage = Jsoup.connect(startPageUrl)
.followRedirects(true)
.cookies(getCookies())
.get();
Document startPage = getPageByUrl(startPageUrl.replace("{locationID}", locationID));
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
uonetPlusOpiekunUrl = studentTileLink.attr("href");
String uonetPlusOpiekunUrl = studentTileLink.attr("href");
//get context module cookie
Connection.Response res = Jsoup.connect(uonetPlusOpiekunUrl)
@ -53,39 +41,42 @@ public class StudentAndParent extends Vulcan {
cookies.addItems(res.cookies());
return this;
this.id = getCalculatedID(uonetPlusOpiekunUrl);
this.baseUrl = baseUrl
.replace("{locationID}", getLocationID())
.replace("{ID}", getID());
}
public String getLocationID() {
return locationID;
}
public String getID() throws LoginErrorException {
Pattern pattern = Pattern.compile("([0-9]{6})");
Matcher matcher = pattern.matcher(uonetPlusOpiekunUrl);
public String getID() {
return id;
}
// Finds all the matches until found by moving the `matcher` forward
if (!matcher.find()) {
public String getCalculatedID(String uonetPlusOpiekunUrl) throws LoginErrorException {
String[] path = uonetPlusOpiekunUrl.split("vulcan.net.pl/")[1].split("/");
if (4 != path.length) {
throw new LoginErrorException();
}
String match = matcher.group(1);
return match;
return path[1];
}
public String getRowDataChildValue(Element e, int index) {
return e.select(".daneWiersz .wartosc").get(index - 1).text();
Elements es = e.select(".daneWiersz .wartosc");
return es.get(index - 1).text();
}
public List<Semester> getSemesters() throws IOException, LoginErrorException {
String url = getGradesPageUrl();
url = url.replace("{locationID}", getLocationID());
url = url.replace("{ID}", getID());
public Document getSnPPageDocument(String url) throws IOException {
return getPageByUrl(baseUrl + url);
}
Document gradesPage = getPageByUrl(url);
return getSemesters(gradesPage);
public List<Semester> getSemesters() throws IOException {
return getSemesters(getSnPPageDocument(gradesPageUrl));
}
public List<Semester> getSemesters(Document gradesPage) {
@ -108,8 +99,7 @@ public class StudentAndParent extends Vulcan {
return semesters;
}
public Semester getCurrentSemester(List<Semester> semesterList)
throws IOException, LoginErrorException {
public Semester getCurrentSemester(List<Semester> semesterList) {
Semester current = null;
for (Semester s : semesterList) {
if (s.isCurrent()) {

View File

@ -1,28 +0,0 @@
package io.github.wulkanowy.api.grades;
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 Grades extends Vulcan {
private StudentAndParent snp = null;
public Grades(Cookies cookies, StudentAndParent snp) {
this.cookies = cookies;
this.snp = snp;
}
//TODO: move to snp
public Document getGradesPageDocument(String url) throws IOException, LoginErrorException {
return getPageByUrl(url
.replace("{locationID}", snp.getLocationID())
.replace("{ID}", snp.getID())
);
}
}

View File

@ -17,16 +17,13 @@ import io.github.wulkanowy.api.login.LoginErrorException;
public class GradesList extends Vulcan {
private Grades grades = null;
private StudentAndParent snp = null;
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}"
+ "/Oceny/Wszystkie?details=2&okres=";
private String gradesPageUrl = "Oceny/Wszystkie?details=2&okres=";
private List<Grade> gradesList = new ArrayList<>();
private List<Grade> grades = new ArrayList<>();
public GradesList(Grades grades, StudentAndParent snp) {
this.grades = grades;
public GradesList(StudentAndParent snp) {
this.snp = snp;
}
@ -39,7 +36,7 @@ public class GradesList extends Vulcan {
}
public List<Grade> getAll(String semester) throws IOException, LoginErrorException {
Document gradesPage = grades.getGradesPageDocument(getGradesPageUrl() + semester);
Document gradesPage = snp.getSnPPageDocument(getGradesPageUrl() + semester);
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));
@ -57,7 +54,7 @@ public class GradesList extends Vulcan {
.attr("style"));
String color = matcher.find() ? matcher.group(1) : "";
gradesList.add(new Grade()
grades.add(new Grade()
.setSubject(row.select("td:nth-child(1)").text())
.setValue(row.select("td:nth-child(2)").text())
.setColor(color)
@ -70,6 +67,6 @@ public class GradesList extends Vulcan {
);
}
return gradesList;
return grades;
}
}

View File

@ -10,11 +10,11 @@ public class Subject {
private String finalRating;
public int getId(){
public int getId() {
return id;
}
public Subject setId(int id){
public Subject setId(int id) {
this.id = id;
return this;

View File

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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;
@ -17,29 +16,24 @@ public class SubjectsList extends Vulcan {
private StudentAndParent snp = null;
private String subjectsPageUrl =
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=1";
private String subjectsPageUrl = "Oceny/Wszystkie?details=1";
private List<Subject> subjects = new ArrayList<>();
public SubjectsList(Cookies cookies, StudentAndParent snp) {
this.cookies = cookies;
public SubjectsList(StudentAndParent snp) {
this.snp = snp;
}
public List<Subject> getAll() throws IOException, LoginErrorException {
subjectsPageUrl = subjectsPageUrl.replace("{locationID}", snp.getLocationID());
subjectsPageUrl = subjectsPageUrl.replace("{ID}", snp.getID());
Document subjectPage = getPageByUrl(subjectsPageUrl);
Document subjectPage = snp.getSnPPageDocument(subjectsPageUrl);
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
for (Element subjectRow : rows) {
subjects.add(new Subject()
.setName(subjectRow.select("td:nth-child(1)").text())
.setPredictedRating(subjectRow.select("td:nth-child(3)").text())
.setFinalRating(subjectRow.select("td:nth-child(4)").text())
.setPredictedRating(subjectRow.select("td:nth-last-child(2)").text())
.setFinalRating(subjectRow.select("td:nth-last-child(1)").text())
);
}

View File

@ -13,11 +13,10 @@ public class Login extends Vulcan {
private String loginPageUrl = "https://cufs.vulcan.net.pl/{locationID}/Account/LogOn";
private String certificatePageUrl =
"https://cufs.vulcan.net.pl/"
+ "{locationID}/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/"
+ "{locationID}/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/"
+ "{locationID}/LoginEndpoint.aspx";
private String certificatePageUrl = "https://cufs.vulcan.net.pl/{locationID}"
+ "/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/{locationID}"
+ "/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/{locationID}"
+ "/LoginEndpoint.aspx";
private String loginEndpointPageUrl =
"https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
@ -60,9 +59,7 @@ public class Login extends Vulcan {
private String[] getCertificateData(String county) throws IOException {
certificatePageUrl = certificatePageUrl.replace("{locationID}", county);
Document certificatePage = Jsoup.connect(certificatePageUrl)
.cookies(getCookies())
.get();
Document certificatePage = getPageByUrl(certificatePageUrl);
return new String[]{
certificatePage.select("input[name=wa]").attr("value"),

View File

@ -7,20 +7,24 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.login.LoginErrorException;
public class AchievementsList {
private Notes notes = null;
private StudentAndParent snp = null;
private List<String> achievementsList = new ArrayList<>();
public AchievementsList(Notes notes) {
this.notes = notes;
private String notesPageUrl = "UwagiOsiagniecia.mvc/Wszystkie";
public AchievementsList(StudentAndParent snp) {
this.snp = snp;
}
public List<String> getAllAchievements() throws LoginErrorException, IOException {
Element pageFragment = notes.getNotesPageDocument().select(".mainContainer > div").get(1);
Element pageFragment = snp.getSnPPageDocument(notesPageUrl)
.select(".mainContainer > div").get(1);
Elements items = pageFragment.select("article");
for (Element item : items) {

View File

@ -1,33 +0,0 @@
package io.github.wulkanowy.api.notes;
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 Notes extends Vulcan {
private StudentAndParent snp = null;
private String notesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
+ "UwagiOsiagniecia.mvc/Wszystkie";
public Notes(Cookies cookies, StudentAndParent snp) {
this.cookies = cookies;
this.snp = snp;
}
public Document getNotesPageDocument() throws IOException, LoginErrorException {
notesPageUrl = notesPageUrl.replace("{locationID}", snp.getLocationID());
notesPageUrl = notesPageUrl.replace("{ID}", snp.getID());
return Jsoup.connect(notesPageUrl)
.cookies(getCookies())
.get();
}
}

View File

@ -12,18 +12,19 @@ import io.github.wulkanowy.api.login.LoginErrorException;
public class NotesList {
private Notes notes = null;
private StudentAndParent snp = null;
private List<Note> notesList = new ArrayList<>();
public NotesList(Notes notes, StudentAndParent snp) {
this.notes = notes;
private String notesPageUrl = "UwagiOsiagniecia.mvc/Wszystkie";
public NotesList(StudentAndParent snp) {
this.snp = snp;
}
public List<Note> getAllNotes() throws LoginErrorException, IOException {
Element pageFragment = notes.getNotesPageDocument().select(".mainContainer > div").get(0);
Element pageFragment = snp.getSnPPageDocument(notesPageUrl)
.select(".mainContainer > div").get(0);
Elements items = pageFragment.select("article");
Elements dates = pageFragment.select("h2");

View File

@ -1,32 +0,0 @@
package io.github.wulkanowy.api.school;
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 School extends Vulcan {
private StudentAndParent snp = null;
private String schoolPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
+ "Szkola.mvc/Nauczyciele";
public School(Cookies cookies, StudentAndParent snp) {
this.cookies = cookies;
this.snp = snp;
}
public Document getSchoolPageDocument() throws IOException, LoginErrorException {
schoolPageUrl = schoolPageUrl.replace("{locationID}", snp.getLocationID());
schoolPageUrl = schoolPageUrl.replace("{ID}", snp.getID());
return Jsoup.connect(schoolPageUrl)
.cookies(getCookies())
.get();
}
}

View File

@ -10,16 +10,17 @@ import io.github.wulkanowy.api.login.LoginErrorException;
public class SchoolInfo extends Vulcan {
private School school = null;
private StudentAndParent snp = null;
public SchoolInfo(School school, StudentAndParent snp) {
this.school = school;
private String schoolPageUrl = "Szkola.mvc/Nauczyciele";
public SchoolInfo(StudentAndParent snp) {
this.snp = snp;
}
public SchoolData getSchoolData() throws IOException, LoginErrorException {
Element e = school.getSchoolPageDocument().select(".mainContainer > article").get(0);
Element e = snp.getSnPPageDocument(schoolPageUrl)
.select(".mainContainer > article").get(0);
return new SchoolData()
.setName(snp.getRowDataChildValue(e, 1))

View File

@ -8,19 +8,22 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.login.LoginErrorException;
public class TeachersInfo extends Vulcan {
private School school = null;
private StudentAndParent snp = null;
public TeachersInfo(School school) {
this.school = school;
private String schoolPageUrl = "Szkola.mvc/Nauczyciele";
public TeachersInfo(StudentAndParent snp) {
this.snp = snp;
}
public TeachersData getTeachersData() throws IOException, LoginErrorException {
Document doc = school.getSchoolPageDocument();
Document doc = snp.getSnPPageDocument(schoolPageUrl);
Elements rows = doc.select(".mainContainer > table tbody tr");
String description = doc.select(".mainContainer > p").first().text();

View File

@ -3,23 +3,37 @@ 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() {

View File

@ -8,15 +8,18 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.login.LoginErrorException;
public class Table extends Vulcan {
private Timetable timetable;
private StudentAndParent snp;
public Table(Timetable timetable) {
this.timetable = timetable;
private String timetablePageurl = "Lekcja.mvc/PlanLekcji?data=";
public Table(StudentAndParent snp) {
this.snp = snp;
}
public Week getWeekTable() throws IOException, LoginErrorException {
@ -24,7 +27,7 @@ public class Table extends Vulcan {
}
public Week getWeekTable(String tick) throws IOException, LoginErrorException {
Element table = timetable.getTablePageDocument(tick)
Element table = snp.getSnPPageDocument(timetablePageurl + tick)
.select(".mainContainer .presentData").first();
Elements tableHeaderCells = table.select("thead th");
@ -84,7 +87,7 @@ public class Table extends Vulcan {
.setDays(days);
}
public Lesson getLessonFromElement(Element e) {
private Lesson getLessonFromElement(Element e) {
Lesson lesson = new Lesson();
Elements spans = e.select("span");
@ -99,7 +102,7 @@ public class Table extends Vulcan {
return lesson;
}
public Lesson getLessonGroupDivisionInfo(Lesson lesson, Elements e) {
private 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);
@ -114,7 +117,7 @@ public class Table extends Vulcan {
return lesson;
}
public Lesson getLessonTypeInfo(Lesson lesson, Elements e) {
private 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)) {
@ -131,7 +134,7 @@ public class Table extends Vulcan {
return lesson;
}
public Lesson getLessonDescriptionInfo(Lesson lesson, Elements e) {
private 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))) {

View File

@ -1,33 +0,0 @@
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();
}
}

View File

@ -2,11 +2,11 @@ package io.github.wulkanowy.api.user;
public class AddressData {
private String address;
private String address = "";
private String registeredAddress;
private String registeredAddress = "";
private String correspondenceAddress;
private String correspondenceAddress = "";
public String getAddress() {
return address;

View File

@ -10,32 +10,45 @@ import io.github.wulkanowy.api.login.LoginErrorException;
public class BasicInformation {
private StudentAndParent snp = null;
private static Document studentDataPageDocument;
private Document studentDataPageDocument;
private StudentAndParent snp;
public BasicInformation(User user, StudentAndParent snp)
throws IOException, LoginErrorException {
private String studentDataPageUrl = "Uczen.mvc/DanePodstawowe";
public BasicInformation(StudentAndParent snp) {
this.snp = snp;
studentDataPageDocument = user.getPage();
}
public PersonalData getPersonalData() {
Element e = studentDataPageDocument.select(".mainContainer > article").get(0);
public Document getStudentDataPageDocument() throws IOException, LoginErrorException {
if (null == studentDataPageDocument) {
studentDataPageDocument = snp.getSnPPageDocument(studentDataPageUrl);
}
return studentDataPageDocument;
}
public PersonalData getPersonalData() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(0);
String name = snp.getRowDataChildValue(e, 1);
String[] names = name.split(" ");
return new PersonalData()
.setNames(snp.getRowDataChildValue(e, 1))
.setName(name)
.setFirstName(names[0])
.setSurname(names[names.length - 1])
.setFirstAndLastName(names[0] + " " + names[names.length - 1])
.setDateAndBirthPlace(snp.getRowDataChildValue(e, 2))
.setPesel(snp.getRowDataChildValue(e, 3))
.setGender(snp.getRowDataChildValue(e, 4))
.setPolishCitizenship(snp.getRowDataChildValue(e, 5))
.setPolishCitizenship("Tak".equals(snp.getRowDataChildValue(e, 5)))
.setFamilyName(snp.getRowDataChildValue(e, 6))
.setParentsNames(snp.getRowDataChildValue(e, 7));
}
public AddressData getAddresData() {
Element e = studentDataPageDocument.select(".mainContainer > article").get(1);
public AddressData getAddressData() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(1);
return new AddressData()
.setAddress(snp.getRowDataChildValue(e, 1))
@ -44,8 +57,8 @@ public class BasicInformation {
}
public ContactDetails getContactDetails() {
Element e = studentDataPageDocument.select(".mainContainer > article").get(2);
public ContactDetails getContactDetails() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(2);
return new ContactDetails()
.setPhoneNumber(snp.getRowDataChildValue(e, 1))

View File

@ -2,11 +2,11 @@ package io.github.wulkanowy.api.user;
public class ContactDetails {
private String phoneNumber;
private String phoneNumber = "";
private String cellPhoneNumber;
private String cellPhoneNumber = "";
private String email;
private String email = "";
public String getPhoneNumber() {
return phoneNumber;

View File

@ -0,0 +1,42 @@
package io.github.wulkanowy.api.user;
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.StudentAndParent;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.login.LoginErrorException;
public class FamilyInformation extends Vulcan {
private StudentAndParent snp;
private String studentDataPageUrl = "Uczen.mvc/DanePodstawowe";
public FamilyInformation(StudentAndParent snp) throws IOException, LoginErrorException {
this.snp = snp;
}
public List<FamilyMember> getFamilyMembers() throws IOException, LoginErrorException {
Elements membersElements = snp.getSnPPageDocument(studentDataPageUrl)
.select(".mainContainer > article:nth-of-type(n+4)");
List<FamilyMember> familyMembers = new ArrayList<>();
for (Element e : membersElements) {
familyMembers.add(new FamilyMember()
.setName(snp.getRowDataChildValue(e, 1))
.setKinship(snp.getRowDataChildValue(e, 2))
.setAddress(snp.getRowDataChildValue(e, 3))
.setTelephones(snp.getRowDataChildValue(e, 4))
.setEmail(snp.getRowDataChildValue(e, 5))
);
}
return familyMembers;
}
}

View File

@ -0,0 +1,59 @@
package io.github.wulkanowy.api.user;
public class FamilyMember {
private String name = "";
private String kinship = "";
private String address = "";
private String telephones = "";
private String email = "";
public String getName() {
return name;
}
public FamilyMember setName(String name) {
this.name = name;
return this;
}
public String getKinship() {
return kinship;
}
public FamilyMember setKinship(String kinship) {
this.kinship = kinship;
return this;
}
public String getAddress() {
return address;
}
public FamilyMember setAddress(String address) {
this.address = address;
return this;
}
public String getTelephones() {
return telephones;
}
public FamilyMember setTelephones(String telephones) {
this.telephones = telephones;
return this;
}
public String getEmail() {
return email;
}
public FamilyMember setEmail(String email) {
this.email = email;
return this;
}
}

View File

@ -2,44 +2,60 @@ package io.github.wulkanowy.api.user;
public class PersonalData {
private String names;
private String name = "";
private String dateAndBirthPlace;
private String firstName = "";
private String pesel;
private String surname = "";
private String gender;
private String firstAndLastName = "";
private String isPolishCitizenship;
private String dateAndBirthPlace = "";
private String familyName;
private String pesel = "";
private String parentsNames;
private String gender = "";
public String getNames() {
return names;
private boolean isPolishCitizenship;
private String familyName = "";
private String parentsNames = "";
public String getName() {
return name;
}
public PersonalData setNames(String names) {
this.names = names;
public PersonalData setName(String name) {
this.name = name;
return this;
}
public String getFirstName() {
String[] name = names.split(" ");
return firstName;
}
return name[0];
public PersonalData setFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public String getSurname() {
String[] name = names.split(" ");
return surname;
}
return name[name.length - 1];
public PersonalData setSurname(String surname) {
this.surname = surname;
return this;
}
public String getFirstAndLastName() {
return getFirstName() + " " + getSurname();
return firstAndLastName;
}
public PersonalData setFirstAndLastName(String firstAndLastName) {
this.firstAndLastName = firstAndLastName;
return this;
}
public String getDateAndBirthPlace() {
@ -48,7 +64,6 @@ public class PersonalData {
public PersonalData setDateAndBirthPlace(String dateAndBirthPlace) {
this.dateAndBirthPlace = dateAndBirthPlace;
return this;
}
@ -58,7 +73,6 @@ public class PersonalData {
public PersonalData setPesel(String pesel) {
this.pesel = pesel;
return this;
}
@ -68,17 +82,15 @@ public class PersonalData {
public PersonalData setGender(String gender) {
this.gender = gender;
return this;
}
public boolean isPolishCitizenship() {
return "Tak".equals(isPolishCitizenship);
return isPolishCitizenship;
}
public PersonalData setPolishCitizenship(String polishCitizenship) {
public PersonalData setPolishCitizenship(boolean polishCitizenship) {
isPolishCitizenship = polishCitizenship;
return this;
}
@ -88,7 +100,6 @@ public class PersonalData {
public PersonalData setFamilyName(String familyName) {
this.familyName = familyName;
return this;
}
@ -98,7 +109,6 @@ public class PersonalData {
public PersonalData setParentsNames(String parentsNames) {
this.parentsNames = parentsNames;
return this;
}
}

View File

@ -1,33 +0,0 @@
package io.github.wulkanowy.api.user;
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 User extends Vulcan {
private StudentAndParent snp = null;
private String studentDataPageUrl =
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Uczen.mvc/DanePodstawowe";
public User(Cookies cookies, StudentAndParent snp) {
this.cookies = cookies;
this.snp = snp;
}
public Document getPage() throws IOException, LoginErrorException {
studentDataPageUrl = studentDataPageUrl.replace("{locationID}", snp.getLocationID());
studentDataPageUrl = studentDataPageUrl.replace("{ID}", snp.getID());
return Jsoup.connect(studentDataPageUrl)
.cookies(getCookies())
.get();
}
}

View File

@ -11,6 +11,8 @@ import org.powermock.api.mockito.PowerMockito;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.login.LoginErrorException;
public class StudentAndParentTest {
private String fixtureFileName = "OcenyWszystkie-semester.html";
@ -26,8 +28,8 @@ public class StudentAndParentTest {
PowerMockito.whenNew(StudentAndParent.class)
.withArguments(Mockito.any(Cookies.class), Mockito.anyString()).thenReturn(snp);
Mockito.when(snp.getPageByUrl(Mockito.anyString())).thenReturn(gradesPageDocument);
Mockito.when(snp.getGradesPageUrl()).thenReturn("http://example.null");
Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(gradesPageDocument);
Mockito.when(snp.getCalculatedID(Mockito.anyString())).thenCallRealMethod();
Mockito.when(snp.getLocationID()).thenReturn("symbol");
Mockito.when(snp.getID()).thenReturn("123456");
Mockito.when(snp.getSemesters()).thenCallRealMethod();
@ -36,6 +38,24 @@ public class StudentAndParentTest {
.thenCallRealMethod();
}
@Test
public void getCalculatedIDStandardTest() throws Exception {
Assert.assertEquals("123456", snp.getCalculatedID("https://uonetplus-opiekun"
+ ".vulcan.net.pl/powiat/123456/Start/Index/"));
}
@Test
public void getCalculatedIDDemoTest() throws Exception {
Assert.assertEquals("demo12345", snp.getCalculatedID("https://uonetplus-opiekundemo"
+ ".vulcan.net.pl/demoupowiat/demo12345/Start/Index/"));
}
@Test(expected = LoginErrorException.class)
public void getCalculatedIDNotLoggedTest() throws Exception {
Assert.assertEquals("123", snp.getCalculatedID("https://uonetplus"
+ ".vulcan.net.pl/powiat/"));
}
@Test
public void getSemestersTest() throws Exception {
List<Semester> semesters = snp.getSemesters();
@ -61,4 +81,11 @@ public class StudentAndParentTest {
Assert.assertEquals("2", snp.getCurrentSemester(semesters).getId());
Assert.assertEquals("1500100901", snp.getCurrentSemester(semesters).getNumber());
}
@Test
public void getCurrentSemesterFromEmptyTest() throws Exception {
List<Semester> semesters = new ArrayList<>();
Assert.assertNull(snp.getCurrentSemester(semesters));
}
}

View File

@ -1,20 +1,12 @@
package io.github.wulkanowy.api.grades;
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 org.powermock.api.mockito.PowerMockito;
import java.util.List;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.Semester;
import io.github.wulkanowy.api.StudentAndParent;
public class GradesListTest {
public class GradesListTest extends GradesTest {
private String fixtureFileName = "OcenyWszystkie-filled.html";
@ -22,25 +14,9 @@ public class GradesListTest {
@Before
public void setUp() throws Exception {
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
Document gradesPageDocument = Jsoup.parse(input);
super.setUp(fixtureFileName);
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
PowerMockito.whenNew(StudentAndParent.class).withAnyArguments().thenReturn(snp);
Mockito.when(snp.getLocationID()).thenReturn("symbol");
Mockito.when(snp.getID()).thenReturn("123456");
Mockito.when(snp.getGradesPageUrl()).thenReturn("http://example.null");
Mockito.when(snp.getSemesters()).thenCallRealMethod();
Mockito.when(snp.getSemesters(Mockito.any(Document.class))).thenCallRealMethod();
Mockito.when(snp.getCurrentSemester(Mockito.anyListOf(Semester.class)))
.thenCallRealMethod();
Grades grades = Mockito.mock(Grades.class);
PowerMockito.whenNew(Grades.class).withAnyArguments().thenReturn(grades);
Mockito.when(grades.getGradesPageDocument(Mockito.anyString()))
.thenReturn(gradesPageDocument);
gradesList = new GradesList(grades, snp);
gradesList = new GradesList(snp);
}
@Test

View File

@ -0,0 +1,26 @@
package io.github.wulkanowy.api.grades;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.mockito.Mockito;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.Semester;
import io.github.wulkanowy.api.StudentAndParent;
public class GradesTest {
protected StudentAndParent snp;
public void setUp(String fixtureFileName) throws Exception {
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
Document gradesPageDocument = Jsoup.parse(input);
snp = Mockito.mock(StudentAndParent.class);
Mockito.when(snp.getSnPPageDocument(Mockito.anyString()))
.thenReturn(gradesPageDocument);
Mockito.when(snp.getSemesters(Mockito.any(Document.class))).thenCallRealMethod();
Mockito.when(snp.getCurrentSemester(Mockito.anyListOf(Semester.class)))
.thenCallRealMethod();
}
}

View File

@ -0,0 +1,83 @@
package io.github.wulkanowy.api.grades;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
public class SubjectsListTest extends GradesTest {
private String fixtureStdFileName = "OcenyWszystkie-subjects.html";
private String fixtureAverageFileName = "OcenyWszystkie-subjects-average.html";
public SubjectsList getSetUpSubjectsList(String fixtureFileName) throws Exception {
super.setUp(fixtureFileName);
return new SubjectsList(snp);
}
@Test
public void getAllStdTest() throws Exception {
List<Subject> list = getSetUpSubjectsList(fixtureStdFileName).getAll();
Assert.assertEquals(5, list.size());
Subject subject0 = list.get(0);
Assert.assertEquals("Zachowanie", subject0.getName());
Assert.assertEquals("bardzo dobre", subject0.getPredictedRating());
Assert.assertEquals("bardzo dobre", subject0.getFinalRating());
Subject subject1 = list.get(1);
Assert.assertEquals("Praktyka zawodowa", subject1.getName());
Assert.assertEquals("-", subject1.getPredictedRating());
Assert.assertEquals("celujący", subject1.getFinalRating());
Subject subject2 = list.get(2);
Assert.assertEquals("Metodologia programowania", subject2.getName());
Assert.assertEquals("bardzo dobry", subject2.getPredictedRating());
Assert.assertEquals("celujący", subject2.getFinalRating());
Subject subject3 = list.get(3);
Assert.assertEquals("Podstawy przedsiębiorczości", subject3.getName());
Assert.assertEquals("3/4", subject3.getPredictedRating());
Assert.assertEquals("dostateczny", subject3.getFinalRating());
Subject subject4 = list.get(4);
Assert.assertEquals("Wychowanie do życia w rodzinie", subject4.getName());
Assert.assertEquals("-", subject4.getPredictedRating());
Assert.assertEquals("-", subject4.getFinalRating());
}
@Test
public void getAllAverageTest() throws Exception {
List<Subject> list = getSetUpSubjectsList(fixtureAverageFileName).getAll();
Assert.assertEquals(5, list.size());
Subject subject0 = list.get(0);
Assert.assertEquals("Zachowanie", subject0.getName());
Assert.assertEquals("bardzo dobre", subject0.getPredictedRating());
Assert.assertEquals("bardzo dobre", subject0.getFinalRating());
Subject subject1 = list.get(1);
Assert.assertEquals("Język polski", subject1.getName());
Assert.assertEquals("-", subject1.getPredictedRating());
Assert.assertEquals("dobry", subject1.getFinalRating());
Subject subject2 = list.get(2);
Assert.assertEquals("Wychowanie fizyczne", subject2.getName());
Assert.assertEquals("bardzo dobry", subject2.getPredictedRating());
Assert.assertEquals("celujący", subject2.getFinalRating());
Subject subject3 = list.get(3);
Assert.assertEquals("Język angielski", subject3.getName());
Assert.assertEquals("4/5", subject3.getPredictedRating());
Assert.assertEquals("bardzo dobry", subject3.getFinalRating());
Subject subject4 = list.get(4);
Assert.assertEquals("Wiedza o społeczeństwie", subject4.getName());
Assert.assertEquals("-", subject4.getPredictedRating());
Assert.assertEquals("-", subject4.getFinalRating());
}
}

View File

@ -1,8 +1,8 @@
package io.github.wulkanowy.api.login;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import org.junit.Test;
public class LoginTest {

View File

@ -5,12 +5,11 @@ import org.jsoup.nodes.Document;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.unitils.reflectionassert.ReflectionAssert;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.StudentAndParent;
public class AchievementsListTest {
@ -23,33 +22,25 @@ public class AchievementsListTest {
Document notesPageDocument = Jsoup.parse(input);
Notes notes = Mockito.mock(Notes.class);
Mockito.when(notes.getNotesPageDocument()).thenReturn(notesPageDocument);
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(notesPageDocument);
return new AchievementsList(notes);
return new AchievementsList(snp);
}
@Test
public void getAllAchievementsFilledTest() throws Exception {
List<String> expectedList = new ArrayList<>();
expectedList.add("I miejsce w ogólnopolskim konkursie ortograficznym");
expectedList.add("III miejsce w ogólnopolskim konkursie plastycznym");
List<String> list = getSetUpAchievementsList(fixtureFilledFileName).getAllAchievements();
List<String> actualList = getSetUpAchievementsList(
fixtureFilledFileName).getAllAchievements();
Assert.assertEquals(2, actualList.size());
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
Assert.assertEquals(2, list.size());
Assert.assertEquals("I miejsce w ogólnopolskim konkursie ortograficznym", list.get(0));
Assert.assertEquals("III miejsce w ogólnopolskim konkursie plastycznym", list.get(1));
}
@Test
public void getAllAchievementsEmptyTest() throws Exception {
List<String> expectedList = new ArrayList<>();
List<String> list = getSetUpAchievementsList(fixtureEmptyFileName).getAllAchievements();
List<String> actualList = getSetUpAchievementsList(
fixtureEmptyFileName).getAllAchievements();
Assert.assertEquals(0, actualList.size());
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
Assert.assertEquals(0, list.size());
}
}

View File

@ -6,9 +6,7 @@ import org.jsoup.nodes.Element;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.unitils.reflectionassert.ReflectionAssert;
import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.FixtureHelper;
@ -25,50 +23,35 @@ public class NotesListTest {
Document notesPageDocument = Jsoup.parse(input);
Notes notes = Mockito.mock(Notes.class);
Mockito.when(notes.getNotesPageDocument()).thenReturn(notesPageDocument);
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(notesPageDocument);
Mockito.when(snp.getRowDataChildValue(Mockito.any(Element.class),
Mockito.anyInt())).thenCallRealMethod();
return new NotesList(notes, snp);
return new NotesList(snp);
}
@Test
public void getAllNotesFilledTest() throws Exception {
List<Note> expectedList = new ArrayList<>();
expectedList.add(new Note()
.setDate("06.06.2017")
.setTeacher("Jan Kowalski [JK]")
.setCategory("Zaangażowanie społeczne")
.setContent("Pomoc przy pikniku charytatywnym")
);
expectedList.add(new Note()
.setDate("01.12.2016")
.setTeacher("Ochocka Zofia [PZ]")
.setCategory("Reprezentowanie szkoły")
.setContent("Udział w przygotowaniu spektaklu")
);
expectedList.add(new Note()
.setDate("01.10.2016")
.setTeacher("Kochański Leszek [KL]")
.setCategory("Zachowanie na lekcji")
.setContent("Przeszkadzanie w prowadzeniu lekcji")
);
List<Note> list = getSetUpNotesList(fixtureFilledFileName).getAllNotes();
List<Note> actualList = getSetUpNotesList(fixtureFilledFileName).getAllNotes();
Assert.assertEquals(3, list.size());
Assert.assertEquals(3, actualList.size());
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
Assert.assertEquals("06.06.2017", list.get(0).getDate());
Assert.assertEquals("Jan Kowalski [JK]", list.get(0).getTeacher());
Assert.assertEquals("Zaangażowanie społeczne", list.get(0).getCategory());
Assert.assertEquals("Pomoc przy pikniku charytatywnym", list.get(0).getContent());
Assert.assertEquals("01.10.2016", list.get(2).getDate());
Assert.assertEquals("Kochański Leszek [KL]", list.get(2).getTeacher());
Assert.assertEquals("Zachowanie na lekcji", list.get(2).getCategory());
Assert.assertEquals("Przeszkadzanie w prowadzeniu lekcji", list.get(2).getContent());
}
@Test
public void getAllNotesWhenEmpty() throws Exception {
List<Note> actualList = getSetUpNotesList(fixtureEmptyFileName).getAllNotes();
List<Note> list = getSetUpNotesList(fixtureEmptyFileName).getAllNotes();
List<Note> expectedList = new ArrayList<>();
Assert.assertEquals(0, actualList.size());
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
Assert.assertEquals(0, list.size());
}
}

View File

@ -11,7 +11,7 @@ public class SchoolInfoTest extends SchoolTest {
@Before
public void setUp() throws Exception {
super.setUp();
schoolInfo = new SchoolInfo(school, snp);
schoolInfo = new SchoolInfo(snp);
}
@Test

View File

@ -11,7 +11,6 @@ import io.github.wulkanowy.api.StudentAndParent;
public class SchoolTest {
protected School school;
protected StudentAndParent snp;
private String fixtureFileName = "Szkola.html";
@ -21,9 +20,8 @@ public class SchoolTest {
Document schoolPageDocument = Jsoup.parse(input);
school = Mockito.mock(School.class);
Mockito.when(school.getSchoolPageDocument()).thenReturn(schoolPageDocument);
snp = Mockito.mock(StudentAndParent.class);
Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(schoolPageDocument);
Mockito.when(snp.getRowDataChildValue(Mockito.any(Element.class),
Mockito.anyInt())).thenCallRealMethod();
}

View File

@ -13,7 +13,7 @@ public class TeachersInfoTest extends SchoolTest {
@Before
public void setUp() throws Exception {
super.setUp();
teachersInfo = new TeachersInfo(school);
teachersInfo = new TeachersInfo(snp);
}
@Test

View File

@ -7,27 +7,31 @@ import org.junit.Test;
import org.mockito.Mockito;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.StudentAndParent;
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 {
private Table getSetUpTable(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);
StudentAndParent timetable = Mockito.mock(StudentAndParent.class);
Mockito.when(timetable.getSnPPageDocument(Mockito.anyString()))
.thenReturn(tablePageDocument);
return new Table(timetable);
}
@Test
public void getWeekTableStandardTest() throws Exception {
Table table = getSetUpTable("", fixtureStdFileName);
Table table = getSetUpTable(fixtureStdFileName);
Week week = table.getWeekTable();
Assert.assertEquals(5, week.getDays().size());
@ -41,7 +45,7 @@ public class TableTest {
@Test
public void getWeekTableStandardLessonStartEndEndTest() throws Exception {
Table tableStd = getSetUpTable("", fixtureStdFileName);
Table tableStd = getSetUpTable(fixtureStdFileName);
Week stdWeek = tableStd.getWeekTable();
Assert.assertEquals("08:00", stdWeek.getDay(0).getLesson(0).getStartTime());
@ -49,7 +53,7 @@ public class TableTest {
Assert.assertEquals("12:15", stdWeek.getDay(2).getLesson(4).getEndTime());
Assert.assertEquals("14:10", stdWeek.getDay(3).getLesson(7).getStartTime());
Table tableFull = getSetUpTable("", fixtureFullFileName);
Table tableFull = getSetUpTable(fixtureFullFileName);
Week fullWeek = tableFull.getWeekTable();
Assert.assertEquals("07:10", fullWeek.getDay(0).getLesson(0).getStartTime());
@ -61,7 +65,7 @@ public class TableTest {
@Test(expected = IndexOutOfBoundsException.class)
public void getWeekTableStandardOutOfBoundsIndex() throws Exception {
Table table = getSetUpTable("", fixtureStdFileName);
Table table = getSetUpTable(fixtureStdFileName);
Week week = table.getWeekTable();
week.getDay(5);
@ -69,7 +73,7 @@ public class TableTest {
@Test
public void getWeekTableHolidaysTest() throws Exception {
Table table = getSetUpTable("", fixtureHolidaysFileName);
Table table = getSetUpTable(fixtureHolidaysFileName);
Week week = table.getWeekTable();
Assert.assertTrue(week.getDay(1).isFreeDay());
@ -84,7 +88,7 @@ public class TableTest {
@Test
public void getWeekTableHolidaysWithEmptyLessonsTest() throws Exception {
Table table = getSetUpTable("", fixtureHolidaysFileName);
Table table = getSetUpTable(fixtureHolidaysFileName);
Week week = table.getWeekTable();
Assert.assertEquals(5, week.getDays().size());
@ -97,7 +101,7 @@ public class TableTest {
@Test
public void getWeekTableFullTest() throws Exception {
Table table = getSetUpTable("", fixtureFullFileName);
Table table = getSetUpTable(fixtureFullFileName);
Week week = table.getWeekTable();
Assert.assertFalse(week.getDay(1).getLesson(2).isEmpty());
@ -105,7 +109,7 @@ public class TableTest {
@Test
public void getWeekTableFullLessonsGroupsDivisionTest() throws Exception {
Table table = getSetUpTable("", fixtureFullFileName);
Table table = getSetUpTable(fixtureFullFileName);
Week week = table.getWeekTable();
// class="", span*4
@ -136,7 +140,7 @@ public class TableTest {
@Test
public void getWeekTableFullLessonsTypesTest() throws Exception {
Table table = getSetUpTable("", fixtureFullFileName);
Table table = getSetUpTable(fixtureFullFileName);
Week week = table.getWeekTable();
// class="", span*4
@ -177,7 +181,7 @@ public class TableTest {
@Test
public void getWeekTableFullLessonsBasicInfoTest() throws Exception {
Table table = getSetUpTable("", fixtureFullFileName);
Table table = getSetUpTable(fixtureFullFileName);
Week week = table.getWeekTable();
// class="", span*4

View File

@ -0,0 +1,50 @@
package io.github.wulkanowy.api.user;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class BasicInformationTest extends UserTest {
private BasicInformation basicInformation;
@Before
public void setUp() throws Exception {
super.setUp();
basicInformation = new BasicInformation(snp);
}
@Test
public void getPersonalData() throws Exception {
PersonalData data = basicInformation.getPersonalData();
Assert.assertEquals("Maria", data.getFirstName());
Assert.assertEquals("Kamińska", data.getSurname());
Assert.assertEquals("Maria Kamińska", data.getFirstAndLastName());
Assert.assertEquals("Maria Aneta Kamińska", data.getName());
Assert.assertEquals("01.01.1900, Warszawa", data.getDateAndBirthPlace());
Assert.assertEquals("12345678900", data.getPesel());
Assert.assertEquals("Kobieta", data.getGender());
Assert.assertTrue(data.isPolishCitizenship());
Assert.assertEquals("Nowak", data.getFamilyName());
Assert.assertEquals("Gabriela, Kamil", data.getParentsNames());
}
@Test
public void getAddressData() throws Exception {
AddressData data = basicInformation.getAddressData();
Assert.assertEquals("ul. Sportowa 16, 00-123 Warszawa", data.getAddress());
Assert.assertEquals("ul. Sportowa 17, 00-123 Warszawa", data.getRegisteredAddress());
Assert.assertEquals("ul. Sportowa 18, 00-123 Warszawa", data.getCorrespondenceAddress());
}
@Test
public void getContactDetails() throws Exception {
ContactDetails data = basicInformation.getContactDetails();
Assert.assertEquals("005554433", data.getPhoneNumber());
Assert.assertEquals("555444333", data.getCellPhoneNumber());
Assert.assertEquals("wulkanowy@example.null", data.getEmail());
}
}

View File

@ -0,0 +1,39 @@
package io.github.wulkanowy.api.user;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class FamilyInformationTest extends UserTest {
private FamilyInformation familyInformation;
@Before
public void setUp() throws Exception {
super.setUp();
familyInformation = new FamilyInformation(snp);
}
@Test
public void getFamilyMembers() throws Exception {
List<FamilyMember> familyMemberList = familyInformation.getFamilyMembers();
Assert.assertEquals(2, familyMemberList.size());
FamilyMember member0 = familyMemberList.get(0);
Assert.assertEquals("Marianna Pająk", member0.getName());
Assert.assertEquals("matka", member0.getKinship());
Assert.assertEquals("ul. Sportowa 16, 00-123 Warszawa", member0.getAddress());
Assert.assertEquals("555111222", member0.getTelephones());
Assert.assertEquals("wulkanowy@example.null", member0.getEmail());
FamilyMember member1 = familyMemberList.get(1);
Assert.assertEquals("Dawid Świątek", member1.getName());
Assert.assertEquals("ojciec", member1.getKinship());
Assert.assertEquals("ul. Sportowa 18, 00-123 Warszawa", member1.getAddress());
Assert.assertEquals("555222111", member1.getTelephones());
Assert.assertEquals("wulkanowy@example.null", member1.getEmail());
}
}

View File

@ -0,0 +1,29 @@
package io.github.wulkanowy.api.user;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.Before;
import org.mockito.Mockito;
import io.github.wulkanowy.api.FixtureHelper;
import io.github.wulkanowy.api.StudentAndParent;
public class UserTest {
protected StudentAndParent snp;
private String fixtureFileName = "UczenDanePodstawowe.html";
@Before
public void setUp() throws Exception {
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
Document pageDocument = Jsoup.parse(input);
snp = Mockito.mock(StudentAndParent.class);
Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(pageDocument);
Mockito.when(snp.getRowDataChildValue(Mockito.any(Element.class), Mockito.anyInt()))
.thenCallRealMethod();
}
}

View File

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Witryna ucznia i rodzica Oceny</title>
</head>
<body>
<main class="mainContainer">
<h1>Oceny</h1>
<div class="filters">
<div>
<label for="okresyKlasyfikacyjneDropDownList">Okres klasyfikacyjny:</label>
<select id="okresyKlasyfikacyjneDropDownList" name="okresyKlasyfikacyjneDropDownList">
<option selected="selected" value="1234">1</option>
<option value="1235">2</option>
</select>
</div>
</div>
<table class="ocenyZwykle-table">
<thead>
<tr>
<th>Przedmiot</th>
<th>Oceny cząstkowe</th>
<th>Średnia</th>
<th>Przewidywana ocena roczna</th>
<th>Ocena roczna</th>
</tr>
</thead>
<tbody>
<tr>
<td>Zachowanie</td>
<td class="break-word">Brak ocen</td>
<td>-</td>
<td>bardzo dobre</td>
<td>bardzo dobre</td>
</tr>
<tr>
<td>Język polski</td>
<td class="break-word">0</td>
<td>3,53</td>
<td>-</td>
<td>dobry</td>
</tr>
<tr>
<td>Wychowanie fizyczne</td>
<td class="break-word">0</td>
<td>5,05</td>
<td>bardzo dobry</td>
<td>celujący</td>
</tr>
<tr>
<td>Język angielski</td>
<td class="break-word">0</td>
<td>4,4</td>
<td>4/5</td>
<td>bardzo dobry</td>
</tr>
<tr>
<td>Wiedza o społeczeństwie</td>
<td class="break-word">Brak ocen</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</main>
<footer>wersja: 17.02.0000.23328</footer>
</body>
</html>

View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Witryna ucznia i rodzica Oceny</title>
</head>
<body>
<main class="mainContainer">
<h1>Oceny</h1>
<div class="filters">
<div>
<label for="okresyKlasyfikacyjneDropDownList">Okres klasyfikacyjny:</label>
<select id="okresyKlasyfikacyjneDropDownList" name="okresyKlasyfikacyjneDropDownList">
<option value="1234">1</option>
<option selected="selected" value="1235">2</option>
</select>
</div>
</div>
<table class="ocenyZwykle-table">
<thead>
<tr>
<th>Przedmiot</th>
<th>Oceny cząstkowe</th>
<th>Przewidywana ocena roczna</th>
<th>Ocena roczna</th>
</tr>
</thead>
<tbody>
<tr>
<td>Zachowanie</td>
<td class="break-word">-</td>
<td>bardzo dobre</td>
<td>bardzo dobre</td>
</tr>
<tr>
<td>Praktyka zawodowa</td>
<td class="break-word">-</td>
<td>-</td>
<td>celujący</td>
</tr>
<tr>
<td>Metodologia programowania</td>
<td class="break-word">-</td>
<td>bardzo dobry</td>
<td>celujący</td>
</tr>
<tr>
<td>Podstawy przedsiębiorczości</td>
<td class="break-word">-</td>
<td>3/4</td>
<td>dostateczny</td>
</tr>
<tr>
<td>Wychowanie do życia w rodzinie</td>
<td class="break-word">-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</main>
<footer>wersja: 17.05.0000.24042</footer>
</body>
</html>

View File

@ -0,0 +1,119 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Witryna ucznia i rodzica Dane ucznia</title>
</head>
<body>
<main class="mainContainer">
<h1>Dane podstawowe</h1>
<h2>Dane osobowe</h2>
<article>
<div class="daneWiersz">
<span class="tytul">Imię (imiona) nazwisko:</span>
<span class="wartosc">Maria Aneta Kamińska</span>
</div>
<div class="daneWiersz">
<span class="tytul">Data i miejsce urodzenia:</span>
<span class="wartosc">01.01.1900, Warszawa</span>
</div>
<div class="daneWiersz">
<span class="tytul">PESEL:</span>
<span class="wartosc">12345678900</span>
</div>
<div class="daneWiersz">
<span class="tytul">Płeć:</span>
<span class="wartosc">Kobieta</span>
</div>
<div class="daneWiersz">
<span class="tytul">Obywatelstwo polskie:</span>
<span class="wartosc"> Tak </span>
</div>
<div class="daneWiersz">
<span class="tytul">Nazwisko rodowe:</span>
<span class="wartosc">Nowak</span>
</div>
<div class="daneWiersz">
<span class="tytul">Imię matki i ojca:</span>
<span class="wartosc">Gabriela, Kamil</span>
</div>
</article>
<h2>Dane adresowe</h2>
<article>
<div class="daneWiersz">
<span class="tytul">Adres zamieszkania:</span>
<span class="wartosc">ul. Sportowa 16, 00-123 Warszawa</span>
</div>
<div class="daneWiersz">
<span class="tytul">Adres zameldowania:</span>
<span class="wartosc">ul. Sportowa 17, 00-123 Warszawa</span>
</div>
<div class="daneWiersz">
<span class="tytul">Adres korespondencji:</span>
<span class="wartosc">ul. Sportowa 18, 00-123 Warszawa</span>
</div>
</article>
<h2>Kontakt</h2>
<article>
<div class="daneWiersz">
<span class="tytul">Telefon:</span>
<span class="wartosc">005554433</span>
</div>
<div class="daneWiersz">
<span class="tytul">Telefon kom&#243;rkowy:</span>
<span class="wartosc">555444333</span>
</div>
<div class="daneWiersz">
<span class="tytul">E-mail:</span>
<span class="wartosc">wulkanowy@example.null</span>
</div>
</article>
<h1>Rodzina</h1>
<article>
<div class="daneWiersz">
<span class="tytul">Nazwisko i imię:</span>
<span class="wartosc">Marianna Pająk</span>
</div>
<div class="daneWiersz">
<span class="tytul">Stopień pokrewieństwa:</span>
<span class="wartosc">matka</span>
</div>
<div class="daneWiersz">
<span class="tytul">Adres:</span>
<span class="wartosc">ul. Sportowa 16, 00-123 Warszawa</span>
</div>
<div class="daneWiersz">
<span class="tytul">Telefony:</span>
<span class="wartosc">555111222</span>
</div>
<div class="daneWiersz">
<span class="tytul">E-mail:</span>
<span class="wartosc">wulkanowy@example.null</span>
</div>
</article>
<article>
<div class="daneWiersz">
<span class="tytul">Nazwisko i imię:</span>
<span class="wartosc">Dawid Świątek</span>
</div>
<div class="daneWiersz">
<span class="tytul">Stopień pokrewieństwa:</span>
<span class="wartosc">ojciec</span>
</div>
<div class="daneWiersz">
<span class="tytul">Adres:</span>
<span class="wartosc">ul. Sportowa 18, 00-123 Warszawa</span>
</div>
<div class="daneWiersz">
<span class="tytul">Telefony:</span>
<span class="wartosc">555222111</span>
</div>
<div class="daneWiersz">
<span class="tytul">E-mail:</span>
<span class="wartosc">wulkanowy@example.null</span>
</div>
</article>
</main>
<footer>wersja: 17.02.0000.23328</footer>
</body>
</html>