Index: TestHarness4LAMS2/.classpath
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
--- TestHarness4LAMS2/.classpath (.../.classpath) (revision 37d07da894922569d79ce4f517c45f8cbed4c452)
+++ TestHarness4LAMS2/.classpath (.../.classpath) (revision 7f004df92bf884af26247547f7a05978a6504041)
@@ -1,19 +1,17 @@
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
Index: TestHarness4LAMS2/123.zip
===================================================================
diff -u
Binary files differ
Fisheye: Tag 7f004df92bf884af26247547f7a05978a6504041 refers to a dead (removed) revision in file `TestHarness4LAMS2/build/build_dir'.
Fisheye: No comparison available. Pass `N' to diff?
Index: TestHarness4LAMS2/lib/Tidy.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/lib/js-1.6R5.jar
===================================================================
diff -u
Binary files differ
Index: TestHarness4LAMS2/lib/js.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/lib/jtidy-4aug2000r7-dev.jar
===================================================================
diff -u
Binary files differ
Index: TestHarness4LAMS2/lib/junit-3.8.1.jar
===================================================================
diff -u
Binary files differ
Index: TestHarness4LAMS2/lib/junit.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/lib/servlet-api-2.4.jar
===================================================================
diff -u
Binary files differ
Index: TestHarness4LAMS2/lib/servlet.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/lib/xercesImpl-2.6.1.jar
===================================================================
diff -u
Binary files differ
Index: TestHarness4LAMS2/lib/xercesImpl.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/lib/xml-apis.jar
===================================================================
diff -u -r37d07da894922569d79ce4f517c45f8cbed4c452 -r7f004df92bf884af26247547f7a05978a6504041
Binary files differ
Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java
===================================================================
diff -u -r3741fcd7e30121af240a2bdafdceef6693440d33 -r7f004df92bf884af26247547f7a05978a6504041
--- TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java (.../MockUser.java) (revision 3741fcd7e30121af240a2bdafdceef6693440d33)
+++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java (.../MockUser.java) (revision 7f004df92bf884af26247547f7a05978a6504041)
@@ -33,162 +33,168 @@
import org.apache.log4j.Logger;
import org.xml.sax.SAXException;
-import com.meterware.httpunit.UploadFileSpec;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;
+import com.meterware.httpunit.protocol.UploadFileSpec;
/**
* @version
- *
+ *
*
* View Source
*
- *
+ *
* @author Fei Yang
*/
-public class MockUser{
+public class MockUser {
- private static final Logger log = Logger.getLogger(MockUser.class);
-
- private static final String[] DELAY_MESSAGES = {" is deserting ", " is napping ", " is pondering ", " is in a daze ", " will have a cup of coffee for ", " is away for toilet "};
-
- private static final String LOGIN_PAGE_FLAG = "j_security_check";
- private static final String INDEX_PAGE_FLAG = "images/loading.gif";
-
- private static final String USERNAME = "j_username";
- private static final String PASSWORD = "j_password";
-
- private static String indexPage;
+ private static final Logger log = Logger.getLogger(MockUser.class);
- protected AbstractTest test;
- protected String userId;
- protected String username;
- protected String password;
- protected WebConversation wc;
+ private static final String[] DELAY_MESSAGES = { " is deserting ", " is napping ", " is pondering ",
+ " is in a daze ", " will have a cup of coffee for ", " is away for toilet " };
- public MockUser(AbstractTest test, String username, String password, String userId) {
- this.test = test;
- this.username = username;
- this.password = password;
- this.userId = userId;
- }
+ private static final String LOGIN_PAGE_FLAG = "j_security_check";
+ private static final String INDEX_PAGE_FLAG = "images/loading.gif";
- public static final void setIndexPage(String indexPageURL){
- indexPage = indexPageURL;
- }
+ private static final String USERNAME = "j_username";
+ private static final String PASSWORD = "j_password";
- /**
- * Login to the system.
- *
- * @exception TestHarnessException:failure
- */
- public final void login()
- {
- try{
- wc = new WebConversation();
- WebResponse resp = (WebResponse)new Call(wc,test,username+" fetch index page",indexPage).execute();
- if(!checkPageContains(resp,LOGIN_PAGE_FLAG)){
- log.debug(resp.getText());
- throw new TestHarnessException(username +" didn't get login page when hitting LAMS the first time!");
- }
- Map params = new HashMap();
- params.put(USERNAME,username);
- params.put(PASSWORD,HashUtil.sha1(password));
- resp = (WebResponse)new Call(wc, test,"User login",fillForm(resp,0,params)).execute();
- if(!checkPageContains(resp,INDEX_PAGE_FLAG)){
- log.debug(resp.getText());
- throw new TestHarnessException(username+" failed to login with password "+password);
- }
- }catch(IOException e){
- throw new RuntimeException(e);
- }catch(SAXException e){
- throw new RuntimeException(e);
- }catch(NoSuchAlgorithmException e){
- throw new RuntimeException(e);
- }
+ private static String indexPage;
+
+ protected AbstractTest test;
+ protected String userId;
+ protected String username;
+ protected String password;
+ protected WebConversation wc;
+
+ public MockUser(AbstractTest test, String username, String password, String userId) {
+ this.test = test;
+ this.username = username;
+ this.password = password;
+ this.userId = userId;
+ }
+
+ public static final void setIndexPage(String indexPageURL) {
+ MockUser.indexPage = indexPageURL;
+ }
+
+ /**
+ * Login to the system.
+ *
+ * @exception TestHarnessException:failure
+ */
+ public final void login() {
+ try {
+ wc = new WebConversation();
+ WebResponse resp = (WebResponse) new Call(wc, test, username + " fetch index page", MockUser.indexPage)
+ .execute();
+ if (!checkPageContains(resp, MockUser.LOGIN_PAGE_FLAG)) {
+ MockUser.log.debug(resp.getText());
+ throw new TestHarnessException(username + " didn't get login page when hitting LAMS the first time!");
+ }
+ Map params = new HashMap();
+ params.put(MockUser.USERNAME, username);
+ params.put(MockUser.PASSWORD, HashUtil.sha1(password));
+ resp = (WebResponse) new Call(wc, test, "User login", fillForm(resp, 0, params)).execute();
+ if (!checkPageContains(resp, MockUser.INDEX_PAGE_FLAG)) {
+ MockUser.log.debug(resp.getText());
+ throw new TestHarnessException(username + " failed to login with password " + password);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(e);
}
+ }
- protected final WebForm fillForm(WebResponse resp, int formIndex, Map params) throws SAXException, IOException{
- WebForm[] forms = resp.getForms();
- if((forms==null)||(forms.length<=formIndex)){
- log.debug(resp.getText());
- throw new TestHarnessException(username + " cannot find the form whose index is "+formIndex+" in the page");
+ protected final WebForm fillForm(WebResponse resp, int formIndex, Map params) throws SAXException,
+ IOException {
+ WebForm[] forms = resp.getForms();
+ if (forms == null || forms.length <= formIndex) {
+ MockUser.log.debug(resp.getText());
+ throw new TestHarnessException(username + " cannot find the form whose index is " + formIndex
+ + " in the page");
+ }
+ WebForm form = forms[formIndex];
+ if (params != null) {
+ for (Map.Entry entry : params.entrySet()) {
+ Object value = entry.getValue();
+ if (value instanceof String) {
+ form.setParameter(entry.getKey(), (String) entry.getValue());
+ } else if (value instanceof File) {
+ form.setParameter(entry.getKey(), (File) entry.getValue());
+ } else if (value instanceof String[]) {
+ form.setParameter(entry.getKey(), (String[]) entry.getValue());
+ } else if (value instanceof UploadFileSpec[]) {
+ form.setParameter(entry.getKey(), (UploadFileSpec[]) entry.getValue());
+ } else {
+ throw new TestHarnessException("Unsupported parameter value type:"
+ + entry.getValue().getClass().getName());
}
- WebForm form = forms[formIndex];
- if (params != null) {
- for (Map.Entry entry : params.entrySet()) {
- Object value = entry.getValue();
- if (value instanceof String) {
- form.setParameter(entry.getKey(), (String) entry.getValue());
- } else if (value instanceof File) {
- form.setParameter(entry.getKey(), (File) entry.getValue());
- } else if (value instanceof String[]) {
- form.setParameter(entry.getKey(), (String[]) entry.getValue());
- } else if (value instanceof UploadFileSpec[]) {
- form.setParameter(entry.getKey(), (UploadFileSpec[]) entry.getValue());
- } else {
- throw new TestHarnessException("Unsupported parameter value type:" + entry.getValue().getClass().getName());
- }
- }
- }
- return form;
+ }
}
-
- protected final boolean checkPageContains(WebResponse resp,String flag) throws IOException
- {
- return resp.getText().indexOf(flag)!=-1;
- }
+ return form;
+ }
- protected final void delay(){
- try{
- int seconds;
- if(test.getMaxDelay() <= test.getMinDelay()){//to avoid IllegalArgumentException in nextInt method on Random object
- seconds = test.getMinDelay();
- }else{
- seconds = test.getMinDelay() + TestUtil.generateRandomIndex(test.getMaxDelay() - test.getMinDelay() + 1 );
- }
- if(seconds>0){
- log.info(composeDelayInfo(seconds));
- Thread.sleep(seconds * 1000);
- }
- }catch (InterruptedException e){
- //ignore
- }
+ protected final boolean checkPageContains(WebResponse resp, String flag) throws IOException {
+ return resp.getText().indexOf(flag) != -1;
}
-
- private String composeDelayInfo(int seconds) {
- return username+DELAY_MESSAGES[TestUtil.generateRandomIndex(DELAY_MESSAGES.length)] + seconds + (seconds==1? " second" : " seconds");
+
+ protected final void delay() {
+ try {
+ int seconds;
+ if (test.getMaxDelay() <= test.getMinDelay()) {// to avoid IllegalArgumentException in nextInt method on
+ // Random object
+ seconds = test.getMinDelay();
+ } else {
+ seconds = test.getMinDelay()
+ + TestUtil.generateRandomIndex(test.getMaxDelay() - test.getMinDelay() + 1);
+ }
+ if (seconds > 0) {
+ MockUser.log.info(composeDelayInfo(seconds));
+ Thread.sleep(seconds * 1000);
+ }
+ } catch (InterruptedException e) {
+ // ignore
}
+ }
- private static class HashUtil {
+ private String composeDelayInfo(int seconds) {
+ return username + MockUser.DELAY_MESSAGES[TestUtil.generateRandomIndex(MockUser.DELAY_MESSAGES.length)]
+ + seconds + (seconds == 1 ? " second" : " seconds");
+ }
- static String sha1(String plaintext) throws NoSuchAlgorithmException {
- MessageDigest md = MessageDigest.getInstance("SHA1");
- return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
- }
+ private static class HashUtil {
- static String md5(String plaintext) throws NoSuchAlgorithmException {
- MessageDigest md = MessageDigest.getInstance("MD5");
- return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
- }
-
+ static String sha1(String plaintext) throws NoSuchAlgorithmException {
+ MessageDigest md = MessageDigest.getInstance("SHA1");
+ return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
}
- public final String getPassword() {
- return password;
+ static String md5(String plaintext) throws NoSuchAlgorithmException {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
}
- public final String getUsername() {
- return username;
- }
+ }
- public final String getUserId() {
- return userId;
- }
+ public final String getPassword() {
+ return password;
+ }
- public final void setUserId(String userId) {
- this.userId = userId;
- }
+ public final String getUsername() {
+ return username;
+ }
+ public final String getUserId() {
+ return userId;
+ }
+
+ public final void setUserId(String userId) {
+ this.userId = userId;
+ }
+
}