husted      2004/03/28 18:34:20

  Modified:    chain/apps/mailreader project.xml
               chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader
                        ClientContext.java MailReader.java
                        MailReaderBase.java
               
chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands
                        LocaleChange.java
               
chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts
                        ActionHelper.java ActionHelperBase.java
                        MailReaderAction.java
               chain/apps/mailreader/src/test/org/apache/commons/mailreader
                        ChangeLocaleTest.java LogonUserTest.java
  Log:
  Implement code to pass LogonUser test. Test for failure.
  
  Revision  Changes    Path
  1.3       +6 -0      jakarta-commons-sandbox/chain/apps/mailreader/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml       26 Mar 2004 18:22:41 -0000      1.2
  +++ project.xml       29 Mar 2004 02:34:19 -0000      1.3
  @@ -27,6 +27,12 @@
   
       <!-- include in WAR -->
   
  +      <dependency>
  +        <groupId>commons-beanutils</groupId>
  +        <artifactId>commons-beanutils</artifactId>
  +        <version>1.6</version>
  +      </dependency>
  +
       <dependency>
         <groupId>commons-collections</groupId>
         <artifactId>commons-collections</artifactId>
  
  
  
  1.3       +16 -0     
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ClientContext.java
  
  Index: ClientContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ClientContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClientContext.java        29 Mar 2004 00:52:22 -0000      1.2
  +++ ClientContext.java        29 Mar 2004 02:34:19 -0000      1.3
  @@ -23,8 +23,16 @@
        */
       public static String PN_LOCALE = "locale";
   
  +    /**
  +     * <p>Assign Locale property</p>
  +     * @param locale New Locale
  +     */
       public void setLocale(Locale locale);
   
  +    /**
  +     * <p>Return Locale property</p>
  +     * @return This Locale property
  +     */
       public Locale getLocale();
   
       /**
  @@ -32,8 +40,16 @@
        */
       public static String PN_INPUT = "input";
   
  +    /**
  +     * <p>Assign Input property</p>
  +     * @param context New Input context
  +     */
       public void setInput(Context context);
   
  +    /**
  +     * <p>Return Input property.</p>
  +     * @return This Input property
  +     */
       public Context getInput();
   
   }
  
  
  
  1.2       +38 -5     
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/MailReader.java
  
  Index: MailReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/MailReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MailReader.java   29 Mar 2004 00:52:22 -0000      1.1
  +++ MailReader.java   29 Mar 2004 02:34:19 -0000      1.2
  @@ -19,6 +19,9 @@
    */
   package org.apache.commons.chain.mailreader;
   
  +import org.apache.struts.webapp.example.UserDatabase;
  +import org.apache.struts.webapp.example.User;
  +
   
   /**
    * Application interface for MailReader Commands.
  @@ -35,8 +38,38 @@
        */
       static String PN_LANGUAGE = "language";
   
  +    /**
  +     * Property name for username.
  +     */
  +    static String PN_USERNAME = "username";
  +
  +    /**
  +     * Property name for password.
  +     */
  +    static String PN_PASSWORD = "password";
  +
  +    /**
  +     * <p>Return user database or null.</p>
  +     * @return user database or null.
  +     */
  +    public UserDatabase getDatabase();
   
  -    // Database
  -    // User
  +    /**
  +     * <p>Assign user database.</p>
  +     * @param database The new database instance
  +     */
  +    public void setDatabase(UserDatabase database);
  +
  +    /**
  +     * <p>Return current user, if any</p>
  +     * @return
  +     */
  +    public User getUser();
  +
  +    /**
  +     * <p>Assign current user.</p>
  +     * @param user The new user
  +     */
  +    public void setUser(User user);
   
   }
  
  
  
  1.2       +42 -20    
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/MailReaderBase.java
  
  Index: MailReaderBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/MailReaderBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MailReaderBase.java       29 Mar 2004 00:52:22 -0000      1.1
  +++ MailReaderBase.java       29 Mar 2004 02:34:19 -0000      1.2
  @@ -21,6 +21,8 @@
   
   import org.apache.commons.chain.Context;
   import org.apache.commons.chain.impl.ContextBase;
  +import org.apache.struts.webapp.example.UserDatabase;
  +import org.apache.struts.webapp.example.User;
   
   import java.util.Locale;
   
  @@ -41,10 +43,11 @@
        * @param locale
        * @param input
        */
  -    public MailReaderBase(Locale locale, Context input) {
  +    public MailReaderBase(Locale locale, Context input, UserDatabase database) {
           super();
           this.locale = locale;
           this.input = input;
  +        this.database = database;
       }
   
       /**
  @@ -52,18 +55,12 @@
        */
       private Locale locale;
   
  -    /**
  -     * <p>Return Locale property</p>
  -     * @return This Locale property
  -     */
  +    // See ContextContext interface for JavaDoc
       public Locale getLocale() {
           return locale;
       }
   
  -    /**
  -     * <p>Assign Locale property</p>
  -     * @param locale New Locale
  -     */
  +    // See ContextContext interface for JavaDoc
       public void setLocale(Locale locale) {
           this.locale = locale;
       }
  @@ -73,19 +70,44 @@
        */
       private Context input;
   
  -    /**
  -     * <p>Return Input property.</p>
  -     * @return This Input property
  -     */
  +    // See ContextContext interface for JavaDoc
       public Context getInput() {
           return input;
       }
   
  -    /**
  -     * <p>Assign Input property</p>
  -     * @param input New Input context
  -     */
  +    // See ContextContext interface for JavaDoc
       public void setInput(Context input) {
           this.input = input;
       }
  +
  +    /**
  +     * <p>Field for database property.</p>
  +     */
  +    private UserDatabase database;
  +
  +    // See MailReader interface for JavaDoc
  +    public UserDatabase getDatabase() {
  +        return database;
  +    }
  +
  +    // See MailReader interface for JavaDoc
  +    public void setDatabase(UserDatabase database) {
  +        this.database = database;
  +    }
  +
  +    /**
  +     * <p>Field for user property.</p>
  +     */
  +    private User user;
  +
  +    // See MailReader interface for JavaDoc
  +    public User getUser() {
  +        return user;
  +    }
  +
  +    // See MailReader interface for JavaDoc
  +    public void setUser(User user) {
  +        this.user = user;
  +    }
  +
   }
  
  
  
  1.2       +3 -3      
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/LocaleChange.java
  
  Index: LocaleChange.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/LocaleChange.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleChange.java 29 Mar 2004 00:52:22 -0000      1.1
  +++ LocaleChange.java 29 Mar 2004 02:34:19 -0000      1.2
  @@ -34,7 +34,7 @@
           return ((string == null) || (string.trim().length() == 0));
       }
   
  -    public boolean execute(Context context) {
  +    public boolean execute(Context context) throws Exception {
   
           MailReader app = (MailReader) context;
           Context input = app.getInput();
  
  
  
  1.2       +13 -3     
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/ActionHelper.java
  
  Index: ActionHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/ActionHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionHelper.java 29 Mar 2004 00:52:09 -0000      1.1
  +++ ActionHelper.java 29 Mar 2004 02:34:19 -0000      1.2
  @@ -241,6 +241,16 @@
       public String getEncodeURL(String url);
   
   
  +    /**
  +     * <p>Return attribute corresponding to key, searching request,
  +     * session, and application, respetively, or null if not found
  +     * in any scope.</p>
  +     * @param key Attribute name
  +     * @return Corresponding attribute or null
  +     */
  +    public Object getAttribute(String key);
  +
  +
   // ----------------------------------------------- Catalog / Context
   
       /**
  
  
  
  1.2       +11 -3     
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/ActionHelperBase.java
  
  Index: ActionHelperBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/ActionHelperBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionHelperBase.java     29 Mar 2004 00:52:09 -0000      1.1
  +++ ActionHelperBase.java     29 Mar 2004 02:34:19 -0000      1.2
  @@ -406,6 +406,14 @@
               return (url);
       }
   
  +    // See ActionHelper interface for JavaDoc
  +    public Object getAttribute(String key) {
  +        Object o = request.getAttribute(key);
  +        if (null==o) o = session.getAttribute(key);
  +        if (null==o) o = application.getAttribute(key);
  +        return o;
  +    }
  +
       // ------------------------------------------------ Presentation API
   
       // See ActionHelper interface for JavaDoc
  
  
  
  1.2       +7 -3      
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/MailReaderAction.java
  
  Index: MailReaderAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/struts/MailReaderAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MailReaderAction.java     29 Mar 2004 00:52:09 -0000      1.1
  +++ MailReaderAction.java     29 Mar 2004 02:34:19 -0000      1.2
  @@ -22,6 +22,8 @@
   import org.apache.commons.chain.Context;
   import org.apache.commons.chain.mailreader.ClientContext;
   import org.apache.commons.chain.mailreader.MailReaderBase;
  +import org.apache.struts.webapp.example.UserDatabase;
  +import org.apache.struts.webapp.example.Constants;
   
   import java.util.Locale;
   
  @@ -36,7 +38,9 @@
   
           Locale locale = helper.getLocale();
           Context input = getInput(helper.getActionForm());
  -        return new MailReaderBase(locale, input);
  +        UserDatabase database = (UserDatabase)
  +                helper.getAttribute(Constants.DATABASE_KEY);
  +        return new MailReaderBase(locale, input, database);
   
       }
   
  
  
  
  1.2       +3 -3      
jakarta-commons-sandbox/chain/apps/mailreader/src/test/org/apache/commons/mailreader/ChangeLocaleTest.java
  
  Index: ChangeLocaleTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/test/org/apache/commons/mailreader/ChangeLocaleTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChangeLocaleTest.java     29 Mar 2004 00:54:23 -0000      1.1
  +++ ChangeLocaleTest.java     29 Mar 2004 02:34:19 -0000      1.2
  @@ -50,7 +50,7 @@
           input.put(MailReader.PN_COUNTRY,"CA");
           input.put(MailReader.PN_LANGUAGE,"FR");
   
  -        MailReader context = new MailReaderBase(original,input);
  +        MailReader context = new MailReaderBase(original,input,null);
   
           try {
               command.execute(context);
  
  
  
  1.2       +44 -4     
jakarta-commons-sandbox/chain/apps/mailreader/src/test/org/apache/commons/mailreader/LogonUserTest.java
  
  Index: LogonUserTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/test/org/apache/commons/mailreader/LogonUserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogonUserTest.java        29 Mar 2004 01:37:39 -0000      1.1
  +++ LogonUserTest.java        29 Mar 2004 02:34:20 -0000      1.2
  @@ -1,4 +1,5 @@
   /*
  +
    * $Header$
    * $Revision$
    * $Date$
  @@ -20,12 +21,11 @@
   package org.apache.commons.mailreader;
   
   import junit.framework.TestCase;
  -import junit.framework.Assert;
   import org.apache.commons.chain.Command;
   import org.apache.commons.chain.Context;
   import org.apache.commons.chain.mailreader.MailReader;
   import org.apache.commons.chain.mailreader.MailReaderBase;
  -import org.apache.commons.chain.mailreader.commands.LocaleChange;
  +import org.apache.commons.chain.mailreader.commands.LogonUser;
   import org.apache.commons.chain.impl.ContextBase;
   import org.apache.struts.webapp.example.User;
   import org.apache.struts.webapp.example.UserDatabase;
  @@ -73,6 +73,46 @@
           User user = context.getUser();
           assertNotNull("Where's waldo?",user);
           assertEquals("Who am I?","John Q. User",user.getFullName());
  +
  +    }
  +
  +    public void testInvalidPassword() {
  +
  +        Context input = new ContextBase();
  +        input.put(MailReader.PN_USERNAME,USER);
  +        input.put(MailReader.PN_PASSWORD,"SezMe");
  +
  +        MailReader context = new MailReaderBase(locale,input,database);
  +
  +        try {
  +            command.execute(context);
  +        }
  +        catch(Exception e) {
  +            fail(e.getMessage());
  +        }
  +
  +        User user = context.getUser();
  +        assertNull("Who's watching the store",user);
  +
  +    }
  +
  +    public void testInvalidUsername() {
  +
  +        Context input = new ContextBase();
  +        input.put(MailReader.PN_USERNAME,"zaphod");
  +        input.put(MailReader.PN_PASSWORD,PASS);
  +
  +        MailReader context = new MailReaderBase(locale,input,database);
  +
  +        try {
  +            command.execute(context);
  +        }
  +        catch(Exception e) {
  +            fail(e.getMessage());
  +        }
  +
  +        User user = context.getUser();
  +        assertNull("Who's watching the store",user);
   
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to