diff --git a/.travis.yml b/.travis.yml
index 7b6baed..2c7933d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,6 @@
language: java
+before_install: "./.travis.before_install.sh"
+script: "./.travis.script.sh"
install:
- mvn install
jdk:
@@ -10,4 +12,4 @@ deploy:
app: dominus-app
on:
repo: mnosoudi/dominus
- branch: searchbar_background
+ branch: VerifyLandlord
diff --git a/pom.xml b/pom.xml
index 45546d6..7406a5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,14 @@
easymock
3.4
+
+
+ mysql
+ mysql-connector-java
+ 5.1.6
+
+
+
diff --git a/src/main/java/com/dominus/dominus/Authorizer.java b/src/main/java/com/dominus/dominus/Authorizer.java
index 1eb4524..80d27bc 100644
--- a/src/main/java/com/dominus/dominus/Authorizer.java
+++ b/src/main/java/com/dominus/dominus/Authorizer.java
@@ -1,6 +1,5 @@
package com.dominus.dominus;
-import java.util.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.SecretKey;
@@ -29,83 +28,60 @@ public boolean authorize(String username, String password) throws NoSuchAlgorith
Pattern pattern = Pattern.compile("\\b[a-zA-Z][a-zA-Z0-9\\-._]{7,}\\b");
Matcher unamematcher = pattern.matcher(username);
Matcher pwdmatcher = pattern.matcher(password);
+ boolean success = false;
-
- //Displays success message if there are no errors
- try
- {
- if(!unamematcher.find() || !pwdmatcher.find()){
- throw new InvalidInputException();
+ if(unamematcher.matches() && pwdmatcher.matches()){
+ String hashedpass;
+ hashedpass = hashIt(password);
+ if(login(username, hashedpass))
+ VaadinSession.getCurrent().setAttribute("user", username);
+ success = true;
}
- //hash password
- //check username and hashed password against database
- //if they match, login (bool?)
- String hashedpass;
- hashedpass = hashIt(password);
- login(username, hashedpass);
- //Returns true if login is good
- return true;
-
- }
- catch(InvalidInputException ex)
- {
- loginError("Invalid username or password");
- //Returns false if there was an error
- return false;
- }
-
-
-
+ else
+ success = false;
+ return success;
}
- //displays error message when invalid input is entered
- public void loginError(String errorMessage)
- {
- Notification notif = new Notification(
- "Login Error",
- errorMessage,
- Notification.Type.ERROR_MESSAGE);
- notif.setDelayMsec(2000);
- //position message in the top left corner
- notif.setPosition(Position.TOP_LEFT);
- notif.show(Page.getCurrent());
- }
+
//password hasher method
- public String hashIt(String b) throws NoSuchAlgorithmException{
- MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
- //one-way encryption for database
- messageDigest.update(b.getBytes());
- String encryptedString = new String(messageDigest.digest());
- return encryptedString;
- }
+ public String hashIt(String password)
+ {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(password.getBytes());
+ byte[] bytes = md.digest();
+ //convert string to hex
+ StringBuilder sb = new StringBuilder();
+ for(int i=0; i< bytes.length ;i++)
+ {
+ sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
+ }
+ return sb.toString();
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ return null;
+ }
+ }
+
- public void login(String username, String password)
+ public boolean login(String username, String password)
{
//dummy database
- try {
- String hashedpass = hashIt("test12345");
- if(username.equals("username123") && password.equals(hashedpass)){
- VaadinSession.getCurrent().setAttribute("user", username);
- Notification notif = new Notification(
- "Login",
- "Login was Successful",
- Notification.Type.HUMANIZED_MESSAGE);
- notif.setDelayMsec(2000);
- notif.setPosition(Position.TOP_LEFT);
- notif.show(Page.getCurrent());
- }
- else
- loginError("Username and Password do not match");
- }
- catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
-
+ String hashedpass = hashIt("test12345");
+ if(username.equals("username123") && password.equals(hashedpass))
+ return true;
+ else
+ return false;
+ }
+
+ public void logout(){
+ VaadinSession.getCurrent().setAttribute("user", null);
}
}
diff --git a/src/main/java/com/dominus/dominus/LoginView.java b/src/main/java/com/dominus/dominus/LoginView.java
new file mode 100644
index 0000000..794ae56
--- /dev/null
+++ b/src/main/java/com/dominus/dominus/LoginView.java
@@ -0,0 +1,73 @@
+/**
+ *
+ */
+package com.dominus.dominus;
+
+import java.security.NoSuchAlgorithmException;
+
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+
+/**
+ * @author Kelvin
+ *
+ */
+public class LoginView extends LoginViewDesign implements View {
+
+ /**
+ *
+ */
+ public static final String VIEW_NAME = "login";
+
+ MainLayout jMain = new MainLayout();
+
+
+ public LoginView(){
+
+ btnLogin.addClickListener(new Button.ClickListener() {
+
+ Authorizer authorize = new Authorizer();
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ // TODO Auto-generated method stub
+ try {
+ if(authorize.authorize(userName.getValue(), password.getValue())){
+ //login successful
+ getUI().getNavigator().navigateTo("search");
+ Notification.show("Login Successful", Notification.Type.HUMANIZED_MESSAGE);
+ //reset UI Components
+ userName.setValue("");
+ password.setValue("");
+ } else{
+ Notification.show("Incorrect Login Details!!!", Notification.Type.ERROR_MESSAGE);
+ }
+ } catch (NoSuchAlgorithmException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+
+
+ btnSignup.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ // TODO Auto-generated method stub
+ getUI().getNavigator().navigateTo("signup");
+ }
+ });
+ }
+ @Override
+ public void enter(ViewChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/main/java/com/dominus/dominus/LoginViewDesign.java b/src/main/java/com/dominus/dominus/LoginViewDesign.java
new file mode 100644
index 0000000..730ce8d
--- /dev/null
+++ b/src/main/java/com/dominus/dominus/LoginViewDesign.java
@@ -0,0 +1,37 @@
+package com.dominus.dominus;
+
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.PasswordField;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * !! DO NOT EDIT THIS FILE !!
+ *
+ * This class is generated by Vaadin Designer and will be overwritten.
+ *
+ * Please make a subclass with logic and additional interfaces as needed,
+ * e.g class LoginView extends LoginDesign implements View { }
+ */
+@DesignRoot
+@AutoGenerated
+@SuppressWarnings("serial")
+public class LoginViewDesign extends VerticalLayout {
+ protected Panel loginPanel;
+ protected FormLayout formLayout;
+ protected TextField userName;
+ protected PasswordField password;
+ protected HorizontalLayout hLayout;
+ protected Button btnLogin;
+ protected Button btnSignup;
+
+ public LoginViewDesign() {
+ Design.read(this);
+ }
+}
diff --git a/src/main/java/com/dominus/dominus/MainLayout.java b/src/main/java/com/dominus/dominus/MainLayout.java
index cbb27ca..4c79135 100644
--- a/src/main/java/com/dominus/dominus/MainLayout.java
+++ b/src/main/java/com/dominus/dominus/MainLayout.java
@@ -10,9 +10,14 @@
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewDisplay;
+import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.shared.Position;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.UI;
@@ -25,36 +30,54 @@ public MainLayout() {
navigator = new Navigator(UI.getCurrent(), (ViewDisplay) this);
addNavigatorView(SearchView.VIEW_NAME, SearchView.class, search);
addNavigatorView(SignUpView.VIEW_NAME, SignUpView.class, signup);
+ addNavigatorView(LoginView.VIEW_NAME, LoginView.class, login);
if (navigator.getState().isEmpty()) {
navigator.navigateTo(SearchView.VIEW_NAME);
}
- Authorizer authorizer = new Authorizer();
- final PasswordField tmpPassword = new PasswordField();
- password.addFocusListener(new FocusListener() {
- public void focus (FieldEvents.FocusEvent event) {
- menu.replaceComponent(password, tmpPassword);
- tmpPassword.focus();
- }
- });
-
- tmpPassword.addBlurListener(new BlurListener () {
- public void blur (FieldEvents.BlurEvent event) {
- password.setValue(tmpPassword.getValue());
- if (password.getValue().isEmpty()) {
- menu.replaceComponent(tmpPassword, password);
- }
- }
- });
- login.addClickListener(event -> {
- try {
- authorizer.authorize(username.getValue(), password.getValue());
- } catch (NoSuchAlgorithmException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- });
+
+// Authorizer authorizer = new Authorizer();
+// final PasswordField tmpPassword = new PasswordField();
+// password.addFocusListener(new FocusListener() {
+// public void focus (FieldEvents.FocusEvent event) {
+// menu.replaceComponent(password, tmpPassword);
+// tmpPassword.focus();
+// }
+// });
+//
+// tmpPassword.addBlurListener(new BlurListener () {
+// public void blur (FieldEvents.BlurEvent event) {
+// password.setValue(tmpPassword.getValue());
+// if (password.getValue().isEmpty()) {
+// menu.replaceComponent(tmpPassword, password);
+// }
+// }
+// });
+
+ Button logout = new Button("Logout");
+ //login.addStyleName("friendly");
+
+// login.addClickListener(event -> {
+// try {
+// if(authorizer.authorize(username.getValue(), password.getValue())){
+// loginSuccess();
+// menu.removeComponent(signup);
+// menu.removeComponent(username);
+// menu.removeComponent(password);
+// menu.removeComponent(login);
+// menu.removeComponent(tmpPassword);
+// Label label = new Label("Signed in as " + (String) VaadinSession.getCurrent().getAttribute("user"));
+// menu.addComponent(label);
+// menu.addComponent(logout);
+// }
+// else
+// loginError();
+// } catch (NoSuchAlgorithmException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// });
}
private void doNavigate(String viewName) {
@@ -90,4 +113,29 @@ public void showView(View view) {
throw new IllegalArgumentException("View is not a Component");
}
}
+
+ //displays error message when invalid input is entered
+ public void loginError()
+ {
+ Notification notif = new Notification(
+ "Login Error",
+ "Wrong username or password",
+ Notification.Type.ERROR_MESSAGE);
+ notif.setDelayMsec(2000);
+ //position message in the top left corner
+ notif.setPosition(Position.TOP_LEFT);
+ notif.show(Page.getCurrent());
+ }
+
+ public void loginSuccess()
+ {
+ Notification notif = new Notification(
+ "Login",
+ "Login was Successful",
+ Notification.Type.HUMANIZED_MESSAGE);
+ notif.setDelayMsec(2000);
+ notif.setPosition(Position.TOP_LEFT);
+ notif.show(Page.getCurrent());
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/dominus/dominus/MainLayoutDesign.java b/src/main/java/com/dominus/dominus/MainLayoutDesign.java
index 986bc11..16fbd8a 100644
--- a/src/main/java/com/dominus/dominus/MainLayoutDesign.java
+++ b/src/main/java/com/dominus/dominus/MainLayoutDesign.java
@@ -1,35 +1,32 @@
-package com.dominus.dominus;
-
-import com.vaadin.annotations.AutoGenerated;
-import com.vaadin.annotations.DesignRoot;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.Design;
-
-/**
- * !! DO NOT EDIT THIS FILE !!
- *
- * This class is generated by Vaadin Designer and will be overwritten.
- *
- * Please make a subclass with logic and additional interfaces as needed,
- * e.g class LoginView extends LoginDesign implements View { }
- */
-@DesignRoot
-@AutoGenerated
-@SuppressWarnings("serial")
-public class MainLayoutDesign extends HorizontalLayout {
- protected CssLayout menu;
- protected Button search;
- protected Button signup;
- protected TextField username;
- protected TextField password;
- protected Button login;
- protected Panel scroll_panel;
-
- public MainLayoutDesign() {
- Design.read(this);
- }
-}
+package com.dominus.dominus;
+
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * !! DO NOT EDIT THIS FILE !!
+ *
+ * This class is generated by Vaadin Designer and will be overwritten.
+ *
+ * Please make a subclass with logic and additional interfaces as needed,
+ * e.g class LoginView extends LoginDesign implements View { }
+ */
+@DesignRoot
+@AutoGenerated
+@SuppressWarnings("serial")
+public class MainLayoutDesign extends HorizontalLayout {
+ protected CssLayout menu;
+ protected Button search;
+ protected Button signup;
+ protected Button login;
+ protected Panel scroll_panel;
+
+ public MainLayoutDesign() {
+ Design.read(this);
+ }
+}
diff --git a/src/main/java/com/dominus/dominus/SignUpView.java b/src/main/java/com/dominus/dominus/SignUpView.java
index 070642d..02ca8a7 100644
--- a/src/main/java/com/dominus/dominus/SignUpView.java
+++ b/src/main/java/com/dominus/dominus/SignUpView.java
@@ -1,14 +1,138 @@
package com.dominus.dominus;
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.event.ContextClickEvent;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.server.Page;
+import com.vaadin.shared.Position;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Notification;
public class SignUpView extends SignUpViewDesign implements View {
public static final String VIEW_NAME = "signup";
+
+
+ public SignUpView()
+ {
+ //gets the landlords registration number
+ registrationNumber.setVisible(false);
+ query.addValueChangeListener(new Property.ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ if(query.getValue().equals("Landlord"))
+ registrationNumber.setVisible(true);
+ else
+ registrationNumber.setVisible(false);
+
+ }
+ });
+
+ cancel.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ // TODO Auto-generated method stub
+ getUI().getNavigator().navigateTo("login");
+ }
+ });
+ }
@Override
- public void enter(ViewChangeEvent event) {
- // TODO Auto-generated method stub
+ public void enter(ViewChangeEvent event)
+ {
+ submit.addClickListener(new Button.ClickListener()
+ {
+ public void buttonClick(ClickEvent event)
+ {
+ SignupValidate validate = new SignupValidate();
+
+ //Not sure if this is necessary or not
+ boolean success = true;
+
+ //Validating the first name
+ if(!validate.validateName(firstName.getValue()) && success==true)
+ {
+ signupError("Make sure you entered a valid first name");
+ success = false;
+ }
+
+ //Validating the last name
+ if(!validate.validateName(lastName.getValue()) && success==true)
+ {
+ signupError("Make sure you entered a valid last name");
+ success = false;
+ }
+
+ //Validating the email
+ if(!validate.validateEmail(email.getValue()) && success==true)
+ {
+ signupError("Make sure you entered a valid email");
+ success = false;
+ }
+
+ //Validating the password
+ if(!validate.validatePassword(password.getValue()) && success==true)
+ {
+ signupError("Make sure you entered a valid password");
+ success = false;
+ }
+
+ //Both passwords match
+ if(!(password.getValue().equals(confirmpass.getValue())) && success== true)
+ {
+ signupError("Make sure both passwords match");
+ success = false;
+ }
+
+ //Terms and Conditions
+ if(!checkAgree.getValue() && success==true)
+ {
+ signupError("Make sure to agree to the Terms and Conditions");
+ success = false;
+ }
+
+ //Displays success notification if all of the fields are valid
+ if(success == true)
+ {
+ signupSuccess();
+ }
+
+
+
+ }
+
+ });
}
+
+
+
+ //Failure Notification
+ public void signupError(String message)
+ {
+ Notification notif = new Notification(
+ "Signup Error",
+ message,
+ Notification.Type.ERROR_MESSAGE);
+ notif.setDelayMsec(2000);
+ notif.setPosition(Position.TOP_LEFT);
+ notif.show(Page.getCurrent());
+ }
+
+ //Success Notification
+ public void signupSuccess()
+ {
+ Notification notif = new Notification(
+ "Signup Success",
+ "Signup was successful",
+ Notification.Type.HUMANIZED_MESSAGE);
+ notif.setDelayMsec(2000);
+ notif.setPosition(Position.TOP_LEFT);
+ notif.show(Page.getCurrent());
+ }
+
}
diff --git a/src/main/java/com/dominus/dominus/SignUpViewDesign.java b/src/main/java/com/dominus/dominus/SignUpViewDesign.java
index 58d44b1..8c8935e 100644
--- a/src/main/java/com/dominus/dominus/SignUpViewDesign.java
+++ b/src/main/java/com/dominus/dominus/SignUpViewDesign.java
@@ -1,38 +1,40 @@
-package com.dominus.dominus;
-
-import com.vaadin.annotations.AutoGenerated;
-import com.vaadin.annotations.DesignRoot;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.Link;
-import com.vaadin.ui.OptionGroup;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.Design;
-
-/**
- * !! DO NOT EDIT THIS FILE !!
- *
- * This class is generated by Vaadin Designer and will be overwritten.
- *
- * Please make a subclass with logic and additional interfaces as needed,
- * e.g class LoginView extends LoginDesign implements View { }
- */
-@DesignRoot
-@AutoGenerated
-@SuppressWarnings("serial")
-public class SignUpViewDesign extends CssLayout {
- protected TextField email;
- protected TextField password;
- protected TextField confirmpass;
- protected TextField lastName;
- protected OptionGroup query;
- protected CheckBox checkAgree;
- protected Link linkTerms;
- protected Button submit;
- protected Button cancel;
-
- public SignUpViewDesign() {
- Design.read(this);
- }
-}
+package com.dominus.dominus;
+
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.OptionGroup;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * !! DO NOT EDIT THIS FILE !!
+ *
+ * This class is generated by Vaadin Designer and will be overwritten.
+ *
+ * Please make a subclass with logic and additional interfaces as needed,
+ * e.g class LoginView extends LoginDesign implements View { }
+ */
+@DesignRoot
+@AutoGenerated
+@SuppressWarnings("serial")
+public class SignUpViewDesign extends CssLayout {
+ protected TextField firstName;
+ protected TextField password;
+ protected TextField email;
+ protected TextField lastName;
+ protected TextField confirmpass;
+ protected OptionGroup query;
+ protected TextField registrationNumber;
+ protected CheckBox checkAgree;
+ protected Link linkTerms;
+ protected Button submit;
+ protected Button cancel;
+
+ public SignUpViewDesign() {
+ Design.read(this);
+ }
+}
diff --git a/src/main/java/com/dominus/dominus/SignupValidate.java b/src/main/java/com/dominus/dominus/SignupValidate.java
index 33934e5..5523453 100644
--- a/src/main/java/com/dominus/dominus/SignupValidate.java
+++ b/src/main/java/com/dominus/dominus/SignupValidate.java
@@ -1,5 +1,136 @@
package com.dominus.dominus;
-public class SignupValidate {
+import java.util.Scanner;
+public class SignupValidate
+{
+
+ //This function will call all of the methods to validate the first name and last name
+ public boolean validateName(String name)
+ {
+ if(!testLength(name))
+ {
+ return false;
+ }
+
+ if(!testLetters(name))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ //This function will call all of the methods to validate the email
+ public boolean validateEmail(String email)
+ {
+ if(!testAt(email))
+ {
+ return false;
+ }
+
+ if(!testPeriod(email))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ //This function will call all of the methods to validate the email
+ public boolean validatePassword(String password)
+ {
+
+ if(passwordNull(password))
+ {
+ //Delete later
+ System.out.println("Password null error");
+ return false;
+ }
+
+
+ if(passwordEmpty(password))
+ {
+ System.out.println("Password empty error");
+ return false;
+ }
+
+ if(!passwordSize(password))
+ {
+
+ System.out.println("Password size error: " + password.length());
+ return false;
+ }
+
+ return true;
+ }
+
+ //This function will call all of the methods to validate the password
+
+ public boolean testLength(String name)
+ {
+ //boolean result = false;
+
+ if(name == null)
+ {
+ return false;
+ }
+
+ if(name == "")
+ {
+ return false;
+ }
+
+ if(name.length()>20)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+
+
+ }
+
+ public boolean testLetters(String name)
+ {
+ return name.matches("[a-zA-Z]+");
+ }
+
+ public boolean testAt(String email)
+ {
+ return email.matches("[^@]*@[^@]*");
+ }
+
+ public boolean testPeriod(String email)
+ {
+ return email.matches(".*[.].*");
+ }
+
+ public boolean passwordNull(String password)
+ {
+ return password.equals(null);
+ }
+
+ public boolean passwordEmpty(String password)
+ {
+ return password.equals("");
+ }
+
+ public boolean passwordSize(String password)
+ {
+ return (password.length() >= 6 && password.length() <= 20);
+ }
+
+ public boolean validateRegistrationNull(String string) {
+ return string.equals(null);
+ }
+
+ public boolean validateRegistrationEmpty(String string) {
+ // TODO Auto-generated method stub
+ string = "";
+ return string.isEmpty();
+ }
+
}
diff --git a/src/main/resources/com/dominus/dominus/LoginViewDesign.html b/src/main/resources/com/dominus/dominus/LoginViewDesign.html
new file mode 100644
index 0000000..a4b2753
--- /dev/null
+++ b/src/main/resources/com/dominus/dominus/LoginViewDesign.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Login
+
+
+ Sign Up
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/com/dominus/dominus/MainLayoutDesign.html b/src/main/resources/com/dominus/dominus/MainLayoutDesign.html
index be1473e..f93b690 100644
--- a/src/main/resources/com/dominus/dominus/MainLayoutDesign.html
+++ b/src/main/resources/com/dominus/dominus/MainLayoutDesign.html
@@ -1,31 +1,30 @@
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
Search
-
+
Sign Up
-
-
-
-
+
+
Log In
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/com/dominus/dominus/SignUpViewDesign.html b/src/main/resources/com/dominus/dominus/SignUpViewDesign.html
index 2fe0535..5ef47d6 100644
--- a/src/main/resources/com/dominus/dominus/SignUpViewDesign.html
+++ b/src/main/resources/com/dominus/dominus/SignUpViewDesign.html
@@ -2,66 +2,62 @@
-
+
-
-
-
+
+
+
Sign Up for Dominus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
Submit
-
-
+
+
Cancel
-
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/dominus/dominus/SignUpViewTest.java b/src/test/java/com/dominus/dominus/SignUpViewTest.java
index edc26b5..cfab360 100644
--- a/src/test/java/com/dominus/dominus/SignUpViewTest.java
+++ b/src/test/java/com/dominus/dominus/SignUpViewTest.java
@@ -1,4 +1,6 @@
-/*import static org.junit.Assert.*;
+package com.dominus.dominus;
+
+import static org.junit.Assert.*;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
@@ -13,11 +15,11 @@
//import org.mockito.Mockito;
import junit.framework.TestCase;
-/*import org.powermock.api.easymock.PowerMock;
-import org.powermock.api.easymock.annotation.Mock;
+//import org.powermock.api.easymock.PowerMock;
+//import org.powermock.api.easymock.annotation.Mock;
import org.powermock.api.mockito.*;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+//import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;
import org.mockito.Matchers;
@@ -29,51 +31,57 @@
public class SignUpViewTest extends TestCase {
//This test addresses the length of the first name (over 20 characters)
- @Test(expected = NullPointerException.class)
- public void testFirstNameLengthOver() throws NoSuchAlgorithmException
+ //Negative test
+ @Test
+ public void testNameLengthOver() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLength("123456789012345678901");
+ assertFalse(signupValidate.testLength("123456789012345678901"));
}
//This test addresses the length of the last name (equal to 20 characters)
+ //Positive test
@Test
- public void testFirstNameNameLengthUnder() throws NoSuchAlgorithmException
+ public void testNameLengthUnder() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLength("12345678901234567890");
+ assertTrue(signupValidate.testLength("12345678901234567890"));
}
//This test addresses if the first name is empty
- @Test(expected = NullPointerException.class)
- public void testFirstNameLengthEmpty() throws NoSuchAlgorithmException
+ //Negative test
+ @Test
+ public void testNameLengthEmpty() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLength("");
+ assertFalse(signupValidate.testLength(""));
}
//This test addresses if the first name is null
- @Test(expected = NullPointerException.class)
- public void testFirstNameLengthNull() throws NoSuchAlgorithmException
+ //Negative test
+ @Test
+ public void testNameLengthNull() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLength(null);
+ assertFalse(signupValidate.testLength(null));
}
//This test addresses if the first name contains numbers
- @Test(expected = NullPointerException.class)
- public void testFirstNameNumbers() throws NoSuchAlgorithmException
+ //Negative test
+ @Test
+ public void testNameNumbers() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLetters("123456");
+ assertFalse(signupValidate.testLetters("123456"));
}
//This test addresses if the last name contains letters
+ //Positive test
@Test
- public void testFirstNameLetters() throws NoSuchAlgorithmException
+ public void testNameLetters() throws NoSuchAlgorithmException
{
SignupValidate signupValidate = new SignupValidate();
- signupValidate.testLetters("ALEXISTHEBEST");
+ assertTrue(signupValidate.testLetters("ALEXISTHEBEST"));
}
//This test checks for an email address with only one '@' character
@@ -134,21 +142,36 @@ public final void whenPasswordIsEmptyExceptionIsThrown() {
@Test
public final void whenLessThan6CharactersThenExceptionIsThrown() {
SignupValidate signupValidate = new SignupValidate();
- AssertFalse(signupValidate.password("123AB"));
+ assertFalse(signupValidate.passwordSize("123AB"));
}
//This test checks the more than size of the password
@Test(expected = RuntimeException.class)
public final void whenMoreThan20CharactersThenExceptionIsThrown() {
SignupValidate signupValidate = new SignupValidate();
- assertFalse(signupValidate.password("0123456789ABCDEFGHIJK"));
+ assertFalse(signupValidate.passwordSize("0123456789ABCDEFGHIJK"));
}
//This test checks the acceptable size of the password
@Test
public final void when6AndMoreCharactersThenNoExceptionIsThrown() {
SignupValidate signupValidate = new SignupValidate();
- assertTrue(signupValidate.password("123ABC"));
+ assertTrue(signupValidate.passwordSize("123ABC"));
+ }
+
+ //This test checks for a registration number for the Landlord if is null
+ @Test
+ public final void isLandlordRegistrationNumberAvailable(){
+ SignupValidate signupValidate = new SignupValidate();
+ assertNull(signupValidate.validateRegistrationNull(null));
}
-}*/
\ No newline at end of file
+ //This test check if the registration number is empty
+ @Test
+ public final void isLandlordRegistrationNumberEmpty(){
+ SignupValidate signupValidate = new SignupValidate();
+ assertTrue(signupValidate.validateRegistrationEmpty(""));
+ }
+
+}
+
diff --git a/src/test/java/com/dominus/dominus/TestBenchUI.java b/src/test/java/com/dominus/dominus/TestBenchUI.java
new file mode 100644
index 0000000..4eef8e0
--- /dev/null
+++ b/src/test/java/com/dominus/dominus/TestBenchUI.java
@@ -0,0 +1,66 @@
+package com.dominus.dominus;
+
+import org.junit.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import com.vaadin.testbench.*;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+
+public class TestBenchUI extends TestBenchTestCase {
+
+ @Rule
+ public ScreenshotOnFailureRule screenshotOnFailureRule = new ScreenshotOnFailureRule(this,true);
+
+ @Before
+ public void setUp() throws Exception {
+ System.setProperty("webdriver.chrome.driver", "/Users/adamwoodland/Downloads/chromedriver");
+ setDriver(new ChromeDriver());
+ }
+
+ public void openTestUrl() {
+ getDriver().get("http://localhost:8080");
+ }
+
+ @Test
+ public void testSearch() {
+ openTestUrl();
+ ButtonElement SearchButton = $(ButtonElement.class).caption("Search").first();
+ SearchButton.click();
+ assertEquals(1, $(TextFieldElement.class).all().size());
+ assertEquals("Search Landlords", $(TextFieldElement.class).first().getCaption());
+ }
+
+ @Test
+ public void testSignUp() {
+ openTestUrl();
+ ButtonElement SignUpButton = $(ButtonElement.class).caption("Sign Up").first();
+ SignUpButton.click();
+ assertEquals("Sign Up for Dominus", $(LabelElement.class).first().getText());
+ assertEquals(5, $(TextFieldElement.class).all().size());
+ assertEquals("First Name", $(TextFieldElement.class).all().get(0).getCaption());
+ assertEquals("Password", $(TextFieldElement.class).all().get(1).getCaption());
+ assertEquals("Email", $(TextFieldElement.class).all().get(2).getCaption());
+ assertEquals("Last Name", $(TextFieldElement.class).all().get(3).getCaption());
+ assertEquals("Confirm Password", $(TextFieldElement.class).all().get(4).getCaption());
+ }
+
+ @Test
+ public void testLogInButton() {
+ openTestUrl();
+ List allButtons = $(ButtonElement.class).all();
+ ButtonElement LogInButton = allButtons.get(2);
+ LogInButton.click();
+ }
+
+ @After
+ public void testDown() throws Exception {
+ driver.quit();
+ }
+}
+