mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-22 18:24:46 +01:00
[API] Make support for alternative log addresses more centralized (#52)
This commit is contained in:
parent
f93816910d
commit
a1a3427142
@ -9,22 +9,41 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
|
private String protocol;
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
private Cookies cookies = new Cookies();
|
private Cookies cookies = new Cookies();
|
||||||
|
|
||||||
Cookies getCookiesObject() {
|
Client(String protocol, String host, String symbol) {
|
||||||
return cookies;
|
this.protocol = protocol;
|
||||||
|
this.host = host;
|
||||||
|
this.symbol = symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCookies(Cookies cookies) {
|
String getHost() {
|
||||||
this.cookies = cookies;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> getCookies() {
|
public void setSymbol(String symbol) {
|
||||||
|
this.symbol = symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> getCookies() {
|
||||||
return cookies.getItems();
|
return cookies.getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document getPageByUrl(String url) throws IOException {
|
private String getFilledUrl(String url) {
|
||||||
Connection.Response response = Jsoup.connect(url)
|
return url
|
||||||
|
.replace("{schema}", protocol)
|
||||||
|
.replace("{host}", host.replace(":", "%253A"))
|
||||||
|
.replace("{symbol}", symbol == null ? "Default" : symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
Document getPageByUrl(String url) throws IOException {
|
||||||
|
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.cookies(getCookies())
|
.cookies(getCookies())
|
||||||
.execute();
|
.execute();
|
||||||
@ -35,7 +54,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Document postPageByUrl(String url, String[][] params) throws IOException {
|
public Document postPageByUrl(String url, String[][] params) throws IOException {
|
||||||
Connection connection = Jsoup.connect(url);
|
Connection connection = Jsoup.connect(getFilledUrl(url));
|
||||||
|
|
||||||
for (String[] data : params) {
|
for (String[] data : params) {
|
||||||
connection.data(data[0], data[1]);
|
connection.data(data[0], data[1]);
|
||||||
@ -53,7 +72,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonStringByUrl(String url) throws IOException {
|
public String getJsonStringByUrl(String url) throws IOException {
|
||||||
Connection.Response response = Jsoup.connect(url)
|
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
.cookies(getCookies())
|
.cookies(getCookies())
|
||||||
@ -65,7 +84,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String postJsonStringByUrl(String url, String[][] params) throws IOException {
|
public String postJsonStringByUrl(String url, String[][] params) throws IOException {
|
||||||
Connection connection = Jsoup.connect(url);
|
Connection connection = Jsoup.connect(getFilledUrl(url));
|
||||||
|
|
||||||
for (String[] data : params) {
|
for (String[] data : params) {
|
||||||
connection.data(data[0], data[1]);
|
connection.data(data[0], data[1]);
|
||||||
|
@ -10,14 +10,6 @@ import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|||||||
|
|
||||||
public interface SnP {
|
public interface SnP {
|
||||||
|
|
||||||
void setProtocolSchema(String schema);
|
|
||||||
|
|
||||||
String getLogHost();
|
|
||||||
|
|
||||||
void setLogHost(String hostname);
|
|
||||||
|
|
||||||
String getSymbol();
|
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
void storeContextCookies() throws IOException, NotLoggedInErrorException;
|
void storeContextCookies() throws IOException, NotLoggedInErrorException;
|
||||||
|
@ -12,67 +12,27 @@ import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|||||||
|
|
||||||
public class StudentAndParent implements SnP {
|
public class StudentAndParent implements SnP {
|
||||||
|
|
||||||
private static final String startPageUrl = "{schema}://uonetplus.{host}/{symbol}/Start.mvc/Index";
|
private static final String START_PAGE_URL = "{schema}://uonetplus.{host}/{symbol}/Start.mvc/Index";
|
||||||
|
|
||||||
private static final String baseUrl = "{schema}://uonetplus-opiekun.{host}/{symbol}/{ID}/";
|
private static final String BASE_URL = "{schema}://uonetplus-opiekun.{host}/{symbol}/{ID}/";
|
||||||
|
|
||||||
private static final String SYMBOL_PLACEHOLDER = "{symbol}";
|
|
||||||
|
|
||||||
private static final String GRADES_PAGE_URL = "Oceny/Wszystkie";
|
private static final String GRADES_PAGE_URL = "Oceny/Wszystkie";
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
private String logHost = "vulcan.net.pl";
|
|
||||||
|
|
||||||
private String protocolSchema = "https";
|
|
||||||
|
|
||||||
private String symbol;
|
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public StudentAndParent(Client client, String symbol) {
|
StudentAndParent(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.symbol = symbol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StudentAndParent(Client client, String symbol, String id) {
|
StudentAndParent(Client client, String id) {
|
||||||
this(client, symbol);
|
this(client);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocolSchema(String schema) {
|
private String getBaseUrl() {
|
||||||
this.protocolSchema = schema;
|
return BASE_URL.replace("{ID}", getId());
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogHost() {
|
|
||||||
return logHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLogHost(String hostname) {
|
|
||||||
this.logHost = hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStartPageUrl() {
|
|
||||||
return startPageUrl
|
|
||||||
.replace("{schema}", protocolSchema)
|
|
||||||
.replace("{host}", logHost)
|
|
||||||
.replace(SYMBOL_PLACEHOLDER, getSymbol());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBaseUrl() {
|
|
||||||
return baseUrl
|
|
||||||
.replace("{schema}", protocolSchema)
|
|
||||||
.replace("{host}", logHost)
|
|
||||||
.replace(SYMBOL_PLACEHOLDER, getSymbol())
|
|
||||||
.replace("{ID}", getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGradesPageUrl() {
|
|
||||||
return getBaseUrl() + GRADES_PAGE_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSymbol() {
|
|
||||||
return symbol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@ -80,16 +40,16 @@ public class StudentAndParent implements SnP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void storeContextCookies() throws IOException, NotLoggedInErrorException {
|
public void storeContextCookies() throws IOException, NotLoggedInErrorException {
|
||||||
client.getPageByUrl(getSnpPageUrl());
|
client.getPageByUrl(getSnpHomePageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSnpPageUrl() throws IOException, NotLoggedInErrorException {
|
String getSnpHomePageUrl() throws IOException, NotLoggedInErrorException {
|
||||||
if (null != getId()) {
|
if (null != getId()) {
|
||||||
return getBaseUrl();
|
return getBaseUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get url to uonetplus-opiekun.vulcan.net.pl
|
// get url to uonetplus-opiekun.vulcan.net.pl
|
||||||
Document startPage = client.getPageByUrl(getStartPageUrl());
|
Document startPage = client.getPageByUrl(START_PAGE_URL);
|
||||||
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
|
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
|
||||||
|
|
||||||
if (null == studentTileLink) {
|
if (null == studentTileLink) {
|
||||||
@ -103,14 +63,14 @@ public class StudentAndParent implements SnP {
|
|||||||
return snpPageUrl;
|
return snpPageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExtractedIdFromUrl(String snpPageUrl) throws NotLoggedInErrorException {
|
String getExtractedIdFromUrl(String snpPageUrl) throws NotLoggedInErrorException {
|
||||||
String[] path = snpPageUrl.split(getLogHost() + "/")[1].split("/");
|
String[] path = snpPageUrl.split(client.getHost())[1].split("/");
|
||||||
|
|
||||||
if (4 != path.length) {
|
if (5 != path.length) {
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return path[1];
|
return path[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRowDataChildValue(Element e, int index) {
|
public String getRowDataChildValue(Element e, int index) {
|
||||||
@ -118,13 +78,11 @@ public class StudentAndParent implements SnP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Document getSnPPageDocument(String url) throws IOException {
|
public Document getSnPPageDocument(String url) throws IOException {
|
||||||
return client.getPageByUrl(getBaseUrl()
|
return client.getPageByUrl(getBaseUrl() + url);
|
||||||
.replace(SYMBOL_PLACEHOLDER, getSymbol())
|
|
||||||
.replace("{ID}", getId()) + url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Semester> getSemesters() throws IOException {
|
public List<Semester> getSemesters() throws IOException {
|
||||||
return getSemesters(getSnPPageDocument(getGradesPageUrl()));
|
return getSemesters(getSnPPageDocument(GRADES_PAGE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Semester> getSemesters(Document gradesPage) {
|
public List<Semester> getSemesters(Document gradesPage) {
|
||||||
|
@ -36,9 +36,9 @@ public class Vulcan {
|
|||||||
|
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
private Client client = new Client();
|
private Client client;
|
||||||
|
|
||||||
private Login login = new Login(client);
|
private Login login;
|
||||||
|
|
||||||
public void setClient(Client client) {
|
public void setClient(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@ -48,17 +48,16 @@ public class Vulcan {
|
|||||||
this.login = login;
|
this.login = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vulcan login(String email, String password, String symbol)
|
public String login(String email, String password, String symbol)
|
||||||
throws BadCredentialsException, AccountPermissionException,
|
throws BadCredentialsException, AccountPermissionException,
|
||||||
LoginErrorException, IOException, VulcanOfflineException {
|
LoginErrorException, IOException, VulcanOfflineException {
|
||||||
|
|
||||||
setFullEndpointInfo(email);
|
setFullEndpointInfo(email);
|
||||||
login.setProtocolSchema(protocolSchema);
|
login = getLogin();
|
||||||
login.setLogHost(logHost);
|
|
||||||
|
|
||||||
this.symbol = login.login(this.email, password, symbol);
|
this.symbol = login.login(this.email, password, symbol);
|
||||||
|
|
||||||
return this;
|
return this.symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vulcan login(String email, String password, String symbol, String id)
|
public Vulcan login(String email, String password, String symbol, String id)
|
||||||
@ -71,11 +70,11 @@ public class Vulcan {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtocolSchema() {
|
String getProtocolSchema() {
|
||||||
return protocolSchema;
|
return protocolSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLogHost() {
|
String getLogHost() {
|
||||||
return logHost;
|
return logHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,8 +96,28 @@ public class Vulcan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Client getClient() {
|
||||||
|
if (null != client) {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
client = new Client(getProtocolSchema(), getLogHost(), symbol);
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Login getLogin() {
|
||||||
|
if (null != login) {
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
login = new Login(getClient());
|
||||||
|
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
public SnP getStudentAndParent() throws IOException, NotLoggedInErrorException {
|
public SnP getStudentAndParent() throws IOException, NotLoggedInErrorException {
|
||||||
if (0 == client.getCookies().size()) {
|
if (0 == getClient().getCookies().size()) {
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,21 +125,19 @@ public class Vulcan {
|
|||||||
return snp;
|
return snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
snp = createSnp(client, symbol, id);
|
snp = createSnp(getClient(), id);
|
||||||
snp.setLogHost(logHost);
|
|
||||||
snp.setProtocolSchema(protocolSchema);
|
|
||||||
|
|
||||||
snp.storeContextCookies();
|
snp.storeContextCookies();
|
||||||
|
|
||||||
return snp;
|
return snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SnP createSnp(Client client, String symbol, String id) {
|
SnP createSnp(Client client, String id) {
|
||||||
if (null == id) {
|
if (null == id) {
|
||||||
return new StudentAndParent(client, symbol);
|
return new StudentAndParent(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StudentAndParent(client, symbol, id);
|
return new StudentAndParent(client, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttendanceStatistics getAttendanceStatistics() throws IOException, NotLoggedInErrorException {
|
public AttendanceStatistics getAttendanceStatistics() throws IOException, NotLoggedInErrorException {
|
||||||
@ -172,6 +189,6 @@ public class Vulcan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Messages getMessages() {
|
public Messages getMessages() {
|
||||||
return new Messages(client, getProtocolSchema(), getLogHost(), symbol);
|
return new Messages(getClient());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,53 +6,33 @@ import org.jsoup.parser.Parser;
|
|||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Client;
|
import io.github.wulkanowy.api.Client;
|
||||||
|
|
||||||
public class Login {
|
public class Login {
|
||||||
|
|
||||||
private static final String loginPageUrl = "{schema}://cufs.{host}/{symbol}/Account/LogOn" +
|
private static final String LOGIN_PAGE_URL = "{schema}://cufs.{host}/{symbol}/Account/LogOn" +
|
||||||
"?ReturnUrl=%2F{symbol}%2FFS%2FLS%3Fwa%3Dwsignin1.0%26wtrealm%3D" +
|
"?ReturnUrl=%2F{symbol}%2FFS%2FLS%3Fwa%3Dwsignin1.0%26wtrealm%3D" +
|
||||||
"{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx%26wctx%3D" +
|
"{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx%26wctx%3D" +
|
||||||
"{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx";
|
"{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx";
|
||||||
|
|
||||||
private static final String loginEndpointPageUrl =
|
private static final String LOGIN_ENDPOINT_PAGE_URL =
|
||||||
"{schema}://uonetplus.{host}/{symbol}/LoginEndpoint.aspx";
|
"{schema}://uonetplus.{host}/{symbol}/LoginEndpoint.aspx";
|
||||||
|
|
||||||
private String protocolSchema = "https";
|
|
||||||
|
|
||||||
private String logHost = "vulcan.net.pl";
|
|
||||||
|
|
||||||
private String symbol = "Default";
|
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
public Login(Client client) {
|
public Login(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocolSchema(String schema) {
|
private String getLoginPageUrl() {
|
||||||
this.protocolSchema = schema;
|
return LOGIN_PAGE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogHost(String hostname) {
|
private String getLoginEndpointPageUrl() {
|
||||||
this.logHost = hostname;
|
return LOGIN_ENDPOINT_PAGE_URL;
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginPageUrl() {
|
|
||||||
return loginPageUrl
|
|
||||||
.replace("{schema}", protocolSchema)
|
|
||||||
.replaceFirst(Pattern.quote("{host}"), logHost)
|
|
||||||
.replace("{host}", logHost.replace(":", "%253A"))
|
|
||||||
.replace("{symbol}", symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginEndpointPageUrl() {
|
|
||||||
return loginEndpointPageUrl
|
|
||||||
.replace("{schema}", protocolSchema)
|
|
||||||
.replace("{host}", logHost)
|
|
||||||
.replace("{symbol}", symbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String login(String email, String password, String symbol)
|
public String login(String email, String password, String symbol)
|
||||||
@ -63,7 +43,7 @@ public class Login {
|
|||||||
return sendCertificate(certificate, symbol);
|
return sendCertificate(certificate, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendCredentials(String email, String password, String symbol)
|
String sendCredentials(String email, String password, String symbol)
|
||||||
throws IOException, BadCredentialsException {
|
throws IOException, BadCredentialsException {
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
|
|
||||||
@ -79,11 +59,13 @@ public class Login {
|
|||||||
return html.select("input[name=wresult]").attr("value");
|
return html.select("input[name=wresult]").attr("value");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendCertificate(String certificate, String defaultSymbol)
|
String sendCertificate(String certificate, String defaultSymbol)
|
||||||
throws IOException, LoginErrorException, AccountPermissionException, VulcanOfflineException {
|
throws IOException, LoginErrorException, AccountPermissionException, VulcanOfflineException {
|
||||||
this.symbol = findSymbol(defaultSymbol, certificate);
|
this.symbol = findSymbol(defaultSymbol, certificate);
|
||||||
|
client.setSymbol(this.symbol);
|
||||||
|
|
||||||
Document html = client.postPageByUrl(getLoginEndpointPageUrl(), new String[][]{
|
Document html = client.postPageByUrl(getLoginEndpointPageUrl()
|
||||||
|
.replace("{symbol}", this.symbol), new String[][]{
|
||||||
{"wa", "wsignin1.0"},
|
{"wa", "wsignin1.0"},
|
||||||
{"wresult", certificate}
|
{"wresult", certificate}
|
||||||
});
|
});
|
||||||
@ -103,7 +85,7 @@ public class Login {
|
|||||||
return this.symbol;
|
return this.symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findSymbol(String symbol, String certificate) {
|
private String findSymbol(String symbol, String certificate) {
|
||||||
if ("Default".equals(symbol)) {
|
if ("Default".equals(symbol)) {
|
||||||
return findSymbolInCertificate(certificate);
|
return findSymbolInCertificate(certificate);
|
||||||
}
|
}
|
||||||
@ -111,7 +93,7 @@ public class Login {
|
|||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findSymbolInCertificate(String certificate) {
|
String findSymbolInCertificate(String certificate) {
|
||||||
Elements els = Jsoup.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
Elements els = Jsoup.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
||||||
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
package io.github.wulkanowy.api.login;
|
||||||
|
|
||||||
|
|
||||||
public class NotLoggedInErrorException extends Exception {
|
public class NotLoggedInErrorException extends Exception {
|
||||||
}
|
}
|
||||||
|
@ -33,23 +33,8 @@ public class Messages {
|
|||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
private String schema;
|
public Messages(Client client) {
|
||||||
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
private String symbol;
|
|
||||||
|
|
||||||
public Messages(Client client, String schema, String host, String symbol) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.schema = schema;
|
|
||||||
this.host = host;
|
|
||||||
this.symbol = symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFilledUrl(String url) {
|
|
||||||
return url.replace("{schema}", schema)
|
|
||||||
.replace("{host}", host)
|
|
||||||
.replace("{symbol}", symbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getReceived() throws IOException, NotLoggedInErrorException, BadRequestException {
|
public List<Message> getReceived() throws IOException, NotLoggedInErrorException, BadRequestException {
|
||||||
@ -65,7 +50,7 @@ public class Messages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Message> getMessages(String url) throws IOException, NotLoggedInErrorException, BadRequestException {
|
private List<Message> getMessages(String url) throws IOException, NotLoggedInErrorException, BadRequestException {
|
||||||
String res = client.getJsonStringByUrl(getFilledUrl(url));
|
String res = client.getJsonStringByUrl(url);
|
||||||
|
|
||||||
List<Message> messages;
|
List<Message> messages;
|
||||||
|
|
||||||
@ -103,11 +88,11 @@ public class Messages {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MessagesContainer {
|
private static class MessagesContainer {
|
||||||
public List<Message> data;
|
private List<Message> data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MessageContainer {
|
private static class MessageContainer {
|
||||||
public Message data;
|
private Message data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,14 @@ public class StudentAndParentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void snpTest() throws Exception {
|
public void snpTest() throws Exception {
|
||||||
StudentAndParent snp = new StudentAndParent(client, "demo123", "id123");
|
StudentAndParent snp = new StudentAndParent(client, "id123");
|
||||||
Assert.assertEquals("demo123", snp.getSymbol());
|
|
||||||
Assert.assertEquals("id123", snp.getId());
|
Assert.assertEquals("id123", snp.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSnpPageUrlWithIdTest() throws Exception {
|
public void getSnpPageUrlWithIdTest() throws Exception {
|
||||||
Assert.assertEquals("https://uonetplus-opiekun.vulcan.net.pl/symbol/123456/",
|
Assert.assertEquals("{schema}://uonetplus-opiekun.{host}/{symbol}/123456/",
|
||||||
(new StudentAndParent(client, "symbol", "123456")).getSnpPageUrl());
|
(new StudentAndParent(client, "123456")).getSnpHomePageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -44,11 +43,12 @@ public class StudentAndParentTest {
|
|||||||
String input = FixtureHelper.getAsString(getClass().getResourceAsStream("Start.html"));
|
String input = FixtureHelper.getAsString(getClass().getResourceAsStream("Start.html"));
|
||||||
Document startPageDocument = Jsoup.parse(input);
|
Document startPageDocument = Jsoup.parse(input);
|
||||||
|
|
||||||
|
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
||||||
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(startPageDocument);
|
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(startPageDocument);
|
||||||
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
StudentAndParent snp = new StudentAndParent(client);
|
||||||
|
|
||||||
Assert.assertEquals("https://uonetplus-opiekun.vulcan.net.pl/symbol/534213/Start/Index/",
|
Assert.assertEquals("https://uonetplus-opiekun.vulcan.net.pl/symbol/534213/Start/Index/",
|
||||||
snp.getSnpPageUrl());
|
snp.getSnpHomePageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
@ -58,13 +58,14 @@ public class StudentAndParentTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(wrongPageDocument);
|
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(wrongPageDocument);
|
||||||
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
StudentAndParent snp = new StudentAndParent(client);
|
||||||
|
|
||||||
snp.getSnpPageUrl();
|
snp.getSnpHomePageUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExtractedIDStandardTest() throws Exception {
|
public void getExtractedIDStandardTest() throws Exception {
|
||||||
|
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
||||||
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
||||||
Assert.assertEquals("123456", snp.getExtractedIdFromUrl("https://uonetplus-opiekun"
|
Assert.assertEquals("123456", snp.getExtractedIdFromUrl("https://uonetplus-opiekun"
|
||||||
+ ".vulcan.net.pl/powiat/123456/Start/Index/"));
|
+ ".vulcan.net.pl/powiat/123456/Start/Index/"));
|
||||||
@ -72,21 +73,23 @@ public class StudentAndParentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExtractedIDDemoTest() throws Exception {
|
public void getExtractedIDDemoTest() throws Exception {
|
||||||
|
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
||||||
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
||||||
Assert.assertEquals("demo12345", snp.getExtractedIdFromUrl("https://uonetplus-opiekundemo"
|
Assert.assertEquals("demo12345",
|
||||||
+ ".vulcan.net.pl/demoupowiat/demo12345/Start/Index/"));
|
snp.getExtractedIdFromUrl("https://uonetplus-opiekun.vulcan.net.pl/demoupowiat/demo12345/Start/Index/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
public void getExtractedIDNotLoggedTest() throws Exception {
|
public void getExtractedIDNotLoggedTest() throws Exception {
|
||||||
|
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
||||||
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
StudentAndParent snp = new StudentAndParent(client, "symbol");
|
||||||
Assert.assertEquals("123", snp.getExtractedIdFromUrl("https://uonetplus"
|
Assert.assertEquals("123",
|
||||||
+ ".vulcan.net.pl/powiat/"));
|
snp.getExtractedIdFromUrl("https://uonetplus.vulcan.net.pl/powiat/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSemestersTest() throws Exception {
|
public void getSemestersTest() throws Exception {
|
||||||
SnP snp = new StudentAndParent(client, "symbol", "123456");
|
SnP snp = new StudentAndParent(client, "123456");
|
||||||
List<Semester> semesters = snp.getSemesters();
|
List<Semester> semesters = snp.getSemesters();
|
||||||
|
|
||||||
Assert.assertEquals(2, semesters.size());
|
Assert.assertEquals(2, semesters.size());
|
||||||
|
@ -5,6 +5,9 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.Login;
|
import io.github.wulkanowy.api.login.Login;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
||||||
|
|
||||||
@ -28,20 +31,51 @@ public class VulcanTest {
|
|||||||
Assert.assertEquals("admin", vulcan.getEmail());
|
Assert.assertEquals("admin", vulcan.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getClientTwiceTest() throws Exception {
|
||||||
|
Vulcan vulcan = new Vulcan();
|
||||||
|
Assert.assertTrue(vulcan.getClient().equals(vulcan.getClient()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLoginTwiceTest() throws Exception {
|
||||||
|
Vulcan vulcan = new Vulcan();
|
||||||
|
Assert.assertTrue(vulcan.getLogin().equals(vulcan.getLogin()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
public void getStudentAndParentNotLoggedInTest() throws Exception {
|
public void getStudentAndParentNotLoggedInTest() throws Exception {
|
||||||
vulcan.getStudentAndParent();
|
vulcan.getStudentAndParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getStudentAndParentTwiceTest() throws Exception {
|
||||||
|
Client client = Mockito.mock(Client.class);
|
||||||
|
Map<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("test", "test");
|
||||||
|
Mockito.when(client.getCookies()).thenReturn(cookies);
|
||||||
|
|
||||||
|
SnP snp = Mockito.mock(StudentAndParent.class);
|
||||||
|
Mockito.doNothing().when(snp).storeContextCookies();
|
||||||
|
|
||||||
|
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
||||||
|
Mockito.when(vulcan.getClient()).thenReturn(client);
|
||||||
|
Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod();
|
||||||
|
Mockito.when(vulcan.createSnp(Mockito.any(Client.class), Mockito.any())).thenReturn(snp);
|
||||||
|
|
||||||
|
vulcan.getStudentAndParent();
|
||||||
|
vulcan.getStudentAndParent();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createSnPTest() throws Exception {
|
public void createSnPTest() throws Exception {
|
||||||
vulcan.login("wulkanowy@wulkanowy.io", "wulkanowy123", "wulkan");
|
vulcan.login("wulkanowy@wulkanowy.io", "wulkanowy123", "wulkan");
|
||||||
|
|
||||||
SnP snp1 = vulcan.createSnp(Mockito.mock(Client.class), "testSymbol", null);
|
SnP snp1 = vulcan.createSnp(Mockito.mock(Client.class), null);
|
||||||
Assert.assertEquals(snp1.getId(), null);
|
Assert.assertEquals(null, snp1.getId());
|
||||||
|
|
||||||
SnP snp2 = vulcan.createSnp(Mockito.mock(Client.class), "testSymbol", "wulkan");
|
SnP snp2 = vulcan.createSnp(Mockito.mock(Client.class), "wulkan");
|
||||||
Assert.assertEquals(snp2.getId(), "wulkan");
|
Assert.assertEquals("wulkan", snp2.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public class MessagesTest {
|
|||||||
public void getMessages() throws Exception {
|
public void getMessages() throws Exception {
|
||||||
Client client = getFixtureAsString("GetWiadomosciOdebrane.json");
|
Client client = getFixtureAsString("GetWiadomosciOdebrane.json");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
List<Message> messageList = messages.getReceived();
|
List<Message> messageList = messages.getReceived();
|
||||||
|
|
||||||
Assert.assertEquals(true, messageList.get(1).unread);
|
Assert.assertEquals(true, messageList.get(1).unread);
|
||||||
@ -39,7 +39,7 @@ public class MessagesTest {
|
|||||||
public void getMessagesEmpty() throws Exception {
|
public void getMessagesEmpty() throws Exception {
|
||||||
Client client = getFixtureAsString("GetWiadomosciUsuniete-empty.json");
|
Client client = getFixtureAsString("GetWiadomosciUsuniete-empty.json");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
List<Message> messageList = messages.getSent();
|
List<Message> messageList = messages.getSent();
|
||||||
|
|
||||||
Assert.assertTrue(messageList.isEmpty());
|
Assert.assertTrue(messageList.isEmpty());
|
||||||
@ -49,7 +49,7 @@ public class MessagesTest {
|
|||||||
public void getMessagesError() throws Exception {
|
public void getMessagesError() throws Exception {
|
||||||
Client client = getFixtureAsString("UndefinedError.txt");
|
Client client = getFixtureAsString("UndefinedError.txt");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
messages.getDeleted();
|
messages.getDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class MessagesTest {
|
|||||||
public void getMessagesBadRequest() throws Exception {
|
public void getMessagesBadRequest() throws Exception {
|
||||||
Client client = getFixtureAsString("PageError.html");
|
Client client = getFixtureAsString("PageError.html");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
messages.getDeleted();
|
messages.getDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class MessagesTest {
|
|||||||
public void getMessage() throws Exception {
|
public void getMessage() throws Exception {
|
||||||
Client client = getFixtureAsString("GetTrescWiadomosci.json");
|
Client client = getFixtureAsString("GetTrescWiadomosci.json");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
Message message = messages.getMessage(123, Messages.RECEIVED_FOLDER);
|
Message message = messages.getMessage(123, Messages.RECEIVED_FOLDER);
|
||||||
Assert.assertEquals(12345, message.id);
|
Assert.assertEquals(12345, message.id);
|
||||||
Assert.assertEquals("Witam, …. \nPozdrawiam Krzysztof Czerkas", message.content);
|
Assert.assertEquals("Witam, …. \nPozdrawiam Krzysztof Czerkas", message.content);
|
||||||
@ -75,7 +75,7 @@ public class MessagesTest {
|
|||||||
public void getMessageError() throws Exception {
|
public void getMessageError() throws Exception {
|
||||||
Client client = getFixtureAsString("UndefinedError.txt");
|
Client client = getFixtureAsString("UndefinedError.txt");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
messages.getMessage(321, Messages.SENT_FOLDER);
|
messages.getMessage(321, Messages.SENT_FOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class MessagesTest {
|
|||||||
public void getMessageBadRequest() throws Exception {
|
public void getMessageBadRequest() throws Exception {
|
||||||
Client client = getFixtureAsString("PageError.html");
|
Client client = getFixtureAsString("PageError.html");
|
||||||
|
|
||||||
Messages messages = new Messages(client, "", "", "");
|
Messages messages = new Messages(client);
|
||||||
messages.getMessage(1, Messages.DELETED_FOLDER);
|
messages.getMessage(1, Messages.DELETED_FOLDER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ public class FirstAccountLoginTest {
|
|||||||
@Test
|
@Test
|
||||||
public void loginTest() throws Exception {
|
public void loginTest() throws Exception {
|
||||||
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
||||||
Mockito.when(snp.getSymbol()).thenReturn("TEST-SYMBOL");
|
|
||||||
Mockito.when(snp.getId()).thenReturn("TEST-ID");
|
Mockito.when(snp.getId()).thenReturn("TEST-ID");
|
||||||
|
|
||||||
PersonalData personalData = Mockito.mock(PersonalData.class);
|
PersonalData personalData = Mockito.mock(PersonalData.class);
|
||||||
@ -60,8 +59,9 @@ public class FirstAccountLoginTest {
|
|||||||
Mockito.doReturn(personalData).when(basicInformation).getPersonalData();
|
Mockito.doReturn(personalData).when(basicInformation).getPersonalData();
|
||||||
|
|
||||||
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
||||||
Mockito.doReturn(basicInformation).when(vulcan).getBasicInformation();
|
Mockito.doReturn("TEST-SYMBOL").when(vulcan).login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
|
||||||
Mockito.doReturn(snp).when(vulcan).getStudentAndParent();
|
Mockito.doReturn(snp).when(vulcan).getStudentAndParent();
|
||||||
|
Mockito.doReturn(basicInformation).when(vulcan).getBasicInformation();
|
||||||
|
|
||||||
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(targetContext, daoSession, vulcan);
|
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(targetContext, daoSession, vulcan);
|
||||||
LoginSession loginSession = firstAccountLogin.login("TEST@TEST", "TEST-PASS", "default");
|
LoginSession loginSession = firstAccountLogin.login("TEST@TEST", "TEST-PASS", "default");
|
||||||
|
@ -33,7 +33,7 @@ public class FirstAccountLogin {
|
|||||||
public LoginSession login(String email, String password, String symbol)
|
public LoginSession login(String email, String password, String symbol)
|
||||||
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
||||||
|
|
||||||
vulcan.login(email, password, symbol);
|
String realSymbol = vulcan.login(email, password, symbol);
|
||||||
|
|
||||||
AccountDao accountDao = daoSession.getAccountDao();
|
AccountDao accountDao = daoSession.getAccountDao();
|
||||||
Safety safety = new Safety();
|
Safety safety = new Safety();
|
||||||
@ -41,7 +41,7 @@ public class FirstAccountLogin {
|
|||||||
.setName(vulcan.getBasicInformation().getPersonalData().getFirstAndLastName())
|
.setName(vulcan.getBasicInformation().getPersonalData().getFirstAndLastName())
|
||||||
.setEmail(email)
|
.setEmail(email)
|
||||||
.setPassword(safety.encrypt(email, password, context))
|
.setPassword(safety.encrypt(email, password, context))
|
||||||
.setSymbol(vulcan.getStudentAndParent().getSymbol())
|
.setSymbol(realSymbol)
|
||||||
.setSnpId(vulcan.getStudentAndParent().getId());
|
.setSnpId(vulcan.getStudentAndParent().getId());
|
||||||
|
|
||||||
long userId = accountDao.insert(account);
|
long userId = accountDao.insert(account);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user