+ public static TestEmailReciever getMailReciever() {
+ return ter;
+ }
+ public String runRegister(String param) throws IOException {
+ HttpURLConnection uc = (HttpURLConnection) new URL("https://"
+ + getServerName() + registerService).openConnection();
+ uc.setDoOutput(true);
+ uc.getOutputStream().write(param.getBytes());
+ String d = IOUtils.readURL(uc);
+ return d;
+ }
+ public String fetchStartErrorMessage(String query) throws IOException {
+ String d = runRegister(query);
+ String formFail = "<div class='formError'>";
+ int idx = d.indexOf(formFail);
+ assertNotEquals(-1, idx);
+ String startError = d.substring(idx + formFail.length(), idx + 100)
+ .trim();
+ return startError;
+ }
+
+ public void registerUser(String firstName, String lastName, String email,
+ String password) {
+ try {
+ String query = "fname=" + URLEncoder.encode(firstName, "UTF-8")
+ + "&lname=" + URLEncoder.encode(lastName, "UTF-8")
+ + "&email=" + URLEncoder.encode(email, "UTF-8")
+ + "&pword1=" + URLEncoder.encode(password, "UTF-8")
+ + "&pword2=" + URLEncoder.encode(password, "UTF-8")
+ + "&day=1&month=1&year=1910&cca_agree=1";
+ String data = fetchStartErrorMessage(query);
+ assertTrue(data, data.startsWith("</div>"));
+ } catch (UnsupportedEncodingException e) {
+ throw new Error(e);
+ } catch (IOException e) {
+ throw new Error(e);
+ }
+ }
+ public void createVerifiedUser(String firstName, String lastName,
+ String email, String password) {
+ registerUser(firstName, lastName, email, password);
+ try {
+ TestMail tm = ter.recieve();
+ String verifyLink = tm.extractLink();
+ String[] parts = verifyLink.split("\\?");
+ URL u = new URL("https://" + getServerName() + "/verify" + parts[1]);
+ u.openStream().close();;
+ } catch (InterruptedException e) {
+ throw new Error(e);
+ } catch (IOException e) {
+ throw new Error(e);
+ }
+ }