[duedates-ulaula commit] r90 - in trunk/src/edu/hawaii/duedates: configuration webApp

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 8, 2008, 1:03:21 AM12/8/08
to duedates-ul...@googlegroups.com
Author: tylerwolff
Date: Sun Dec 7 20:34:34 2008
New Revision: 90

Modified:
trunk/src/edu/hawaii/duedates/configuration/ConfigurationManager.java
trunk/src/edu/hawaii/duedates/configuration/DueDatesConfiguration.java
trunk/src/edu/hawaii/duedates/webApp/DueDatesApplication.java
trunk/src/edu/hawaii/duedates/webApp/DueDatesSession.java
trunk/src/edu/hawaii/duedates/webApp/Index.java
trunk/src/edu/hawaii/duedates/webApp/TestIndex.java

Log:
Issue 32, Changed a bunch of stuff to make testing the pages easier. the
duedatesapplication now has a separate constructor that can set up a config
file without having to look at a mock xml file. Implemented test cases
using this in TestIndex.java

Modified:
trunk/src/edu/hawaii/duedates/configuration/ConfigurationManager.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/configuration/ConfigurationManager.java
(original)
+++ trunk/src/edu/hawaii/duedates/configuration/ConfigurationManager.java
Sun Dec 7 20:34:34 2008
@@ -55,7 +55,7 @@
}

/**
- * Returns a DueDates constructed from the default XML DueDates.
+ * Returns a DueDatesConfiguration constructed from the default XML
DueDates.
* If no default DueDates exists, an empty DueDates is returned.
* @return A DueDatesConfiguration object with all the data.
*/

Modified:
trunk/src/edu/hawaii/duedates/configuration/DueDatesConfiguration.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/configuration/DueDatesConfiguration.java
(original)
+++ trunk/src/edu/hawaii/duedates/configuration/DueDatesConfiguration.java
Sun Dec 7 20:34:34 2008
@@ -1,5 +1,6 @@
package edu.hawaii.duedates.configuration;

+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@@ -10,8 +11,11 @@
* @author tylerwolff
*
*/
-public class DueDatesConfiguration {
+public class DueDatesConfiguration implements Serializable {

+ /** Support serialization. */
+ private static final long serialVersionUID = 1L;
+
/** The smtp server name to use for mailing. */
private String smtpServer;


Modified: trunk/src/edu/hawaii/duedates/webApp/DueDatesApplication.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/webApp/DueDatesApplication.java (original)
+++ trunk/src/edu/hawaii/duedates/webApp/DueDatesApplication.java Sun Dec
7 20:34:34 2008
@@ -5,6 +5,8 @@
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;
+import edu.hawaii.duedates.configuration.ConfigurationManager;
+import edu.hawaii.duedates.configuration.DueDatesConfiguration;

/**
* Application object for the DueDates Web Application.
@@ -14,6 +16,8 @@
*/
public class DueDatesApplication extends WebApplication {

+ private final DueDatesConfiguration config;
+
/**
* Indicate that Index is the home page for this application.
* @return The home page, which is Index.
@@ -32,16 +36,26 @@
*/
@Override
public Session newSession(Request request, Response response) {
- return new DueDatesSession(this, request);
+ DueDatesSession newSession = new DueDatesSession(request);
+ newSession.setDueDatesConfiguration(this.config);
+ return newSession;
+ }
+
+ /**
+ * The default constructor for a DueDatesApplication.
+ */
+ public DueDatesApplication() {
+ ConfigurationManager cm = new ConfigurationManager();
+ this.config = cm.getDueDates();
}

- //method is never used.
- /*
- * Return this webapp. Gets the session for your current user instance.
+ /**
+ * A constructor for starting the application without reading
from .duedates/duedates.xml.
+ * The application is started with a specified configuration object.
*
- * @return The webapp.
- *
- public static DueDatesApplication get() {
- return (DueDatesApplication) Application.get();
- }*/
+ * @param config A DueDatesConfiguration object.
+ */
+ public DueDatesApplication(DueDatesConfiguration config) {
+ this.config = config;
+ }
}

Modified: trunk/src/edu/hawaii/duedates/webApp/DueDatesSession.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/webApp/DueDatesSession.java (original)
+++ trunk/src/edu/hawaii/duedates/webApp/DueDatesSession.java Sun Dec 7
20:34:34 2008
@@ -3,10 +3,10 @@
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.Request;
-import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebSession;
import edu.hawaii.duedates.DueDates;
import edu.hawaii.duedates.ItemDue;
+import edu.hawaii.duedates.configuration.DueDatesConfiguration;
import edu.hawaii.duedates.configuration.User;

/**
@@ -26,6 +26,9 @@
private List<ItemDue> uhList = new ArrayList<ItemDue>();
private List<ItemDue> hslList = new ArrayList<ItemDue>();

+ /** The configuration file for each session, created upon application
start. */
+ private DueDatesConfiguration config;
+
/** The User of each session. */
private User user = new
User("defaultName", "defaultEmail", "defaultPassword");
private String smtpServer;
@@ -46,10 +49,9 @@
/**
* Creates a new session for this user. Called automatically by Wicket.
*
- * @param application This application.
* @param request The request.
*/
- public DueDatesSession (WebApplication application, Request request) {
+ public DueDatesSession (Request request) {
super(request);
}

@@ -89,6 +91,24 @@
*/
public void setDueDatesObject(String[] args) {
this.dueDates = new DueDates(args);
+ }
+
+ /**
+ * Returns the configuration settings.
+ *
+ * @return The configuration settings.
+ */
+ public DueDatesConfiguration getDueDatesConfiguration() {
+ return this.config;
+ }
+
+ /**
+ * Sets the configuration settings.
+ *
+ * @param config The configuration settings to set.
+ */
+ public void setDueDatesConfiguration(DueDatesConfiguration config) {
+ this.config = config;
}

/**

Modified: trunk/src/edu/hawaii/duedates/webApp/Index.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/webApp/Index.java (original)
+++ trunk/src/edu/hawaii/duedates/webApp/Index.java Sun Dec 7 20:34:34 2008
@@ -7,7 +7,6 @@
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
-import edu.hawaii.duedates.configuration.ConfigurationManager;
import edu.hawaii.duedates.configuration.DueDatesConfiguration;
import edu.hawaii.duedates.configuration.User;

@@ -44,8 +43,8 @@
/** Validates email & password and goes to ResultPage */
@Override
public void onSubmit() {
- ConfigurationManager manager = new ConfigurationManager();
- DueDatesConfiguration config = manager.getDueDates();
+ /*ConfigurationManager manager = new ConfigurationManager();*/
+ DueDatesConfiguration config =
getDueDatesSession().getDueDatesConfiguration();
User user = config.validateUser(getDueDatesSession().getEmail(),
getDueDatesSession().getPassword());


Modified: trunk/src/edu/hawaii/duedates/webApp/TestIndex.java
==============================================================================
--- trunk/src/edu/hawaii/duedates/webApp/TestIndex.java (original)
+++ trunk/src/edu/hawaii/duedates/webApp/TestIndex.java Sun Dec 7 20:34:34
2008
@@ -3,7 +3,10 @@
import static org.junit.Assert.assertEquals;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Before;
import org.junit.Test;
+import edu.hawaii.duedates.configuration.DueDatesConfiguration;
+import edu.hawaii.duedates.configuration.User;

/**
* Tests the Index page for the Due Dates 2-0 web application.
@@ -12,6 +15,20 @@
*/
public class TestIndex {

+ private DueDatesConfiguration config;
+
+ /**
+ * Sets up a mock DueDatesConfiguration object for use in
+ * tests.
+ */
+ @Before
+ public void setUp() {
+ this.config = new DueDatesConfiguration();
+ User testUser = new User("Test", "tes...@hawaii.edu", "password");
+ this.config.addUser(testUser);
+ this.config.setSmtpServer("mail.hawaii.edu");
+ }
+
/**
* Tests that the Index (login page) is rendered correctly and
* includes all the basic functionalities associated with it.
@@ -24,7 +41,7 @@
final String PASSWORD_FIELD = "LoginPassword";

// Start up the WicketTester and check that the start page renders .
- WicketTester tester = new WicketTester(new DueDatesApplication());
+ WicketTester tester = new WicketTester(new
DueDatesApplication(config));
tester.startPage(Index.class);
tester.assertRenderedPage(Index.class);

@@ -36,67 +53,18 @@
String passwordString =
formTester.getTextComponentValue(PASSWORD_FIELD);
assertEquals("Testing text field", "", passwordString);

- //Test valid login information using a dummy xml.
- /*formTester.setValue(EMAIL_FIELD, "bade...@gmail.com");
- formTester.setValue(PASSWORD_FIELD, "badpassword");*/
-
- //Test invalid login information that isn't found in dummy xml.
-
-
-/* example code
-
- stackFormTester.setValue(INPUT_FIELD, "First push");
- stackFormTester.submit(PUSH_BUTTON);
- inputString = stackFormTester.getTextComponentValue(INPUT_FIELD);
- assertEquals("Testing text field clears on push", "", inputString);
-
- Model rowModel = (Model)
tester.getComponentFromLastRenderedPage("stackTable:1").getModel();
- String element = (String) rowModel.getObject();
- assertEquals("Testing stack table", "First push", element);
-
- // Need a new FormTester after each submit. Wow that's irritating.
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.setValue(INPUT_FIELD, "Second push");
- stackFormTester.submit(PUSH_BUTTON);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.setValue(INPUT_FIELD, "Third push");
- stackFormTester.submit(PUSH_BUTTON);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.setValue(INPUT_FIELD, "Fourth push");
- stackFormTester.submit(PUSH_BUTTON);
-
- rowModel = (Model)
tester.getComponentFromLastRenderedPage("stackTable:1").getModel();
- element = (String) rowModel.getObject();
- assertEquals("Testing stack table", "Fourth push", element);
- rowModel = (Model)
tester.getComponentFromLastRenderedPage("stackTable:4").getModel();
- element = (String) rowModel.getObject();
- assertEquals("Testing stack table", "First push", element);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.submit(POP_BUTTON);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.submit(POP_BUTTON);
- inputString = stackFormTester.getTextComponentValue(INPUT_FIELD);
- assertEquals("Testing text field on pop", "Third push", inputString);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.submit("clearButton");
- inputString = stackFormTester.getTextComponentValue(INPUT_FIELD);
- assertEquals("Testing text field on clear", "", inputString);
-
- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.submit(POP_BUTTON);
- inputString = stackFormTester.getTextComponentValue(INPUT_FIELD);
- assertEquals("Testing empty pop", "No element to pop.", inputString);
+ //Test invalid login information.
+ formTester.setValue(EMAIL_FIELD, "bade...@gmail.com");
+ formTester.setValue(PASSWORD_FIELD, "badpassword");
+ formTester.submit("Login");
+ tester.assertRenderedPage(Index.class);

- stackFormTester = tester.newFormTester(STACK_FORM);
- stackFormTester.setValue(INPUT_FIELD, "");
- stackFormTester.submit(PUSH_BUTTON);
- inputString = stackFormTester.getTextComponentValue(INPUT_FIELD);
- assertEquals("Testing empty push", "Cannot push an empty field.",
inputString);
- */
+ //Test valid login. Result Page will render.
+ tester.startPage(Index.class);
+ FormTester formTester2 = tester.newFormTester(LOGIN_FORM);
+ formTester2.setValue(EMAIL_FIELD, "tes...@hawaii.edu");
+ formTester2.setValue(PASSWORD_FIELD, "password");
+ formTester2.submit("Login");
+ tester.assertRenderedPage(ResultPage.class);
}
}

Reply all
Reply to author
Forward
0 new messages