Author: husted Date: Fri Jan 6 03:35:39 2006 New Revision: 366481 URL: http://svn.apache.org/viewcvs?rev=366481&view=rev Log: MailReader Training Course * Add example code for session 1-3
Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java (with props) struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java (with props) Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,67 @@ +/* + * ================================================================= + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All + * rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software + * itself, if and wherever such third-party acknowlegements + * normally appear. + * + * 4. The names "The Jakarta Project", "junitbook", "jia", + * "JUnit in Action" and "Apache Software Foundation" must not be + * used to endorse or promote products derived from this software + * without prior written permission. For written permission, + * please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ================================================================= + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For + * more information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package jumpstart; + +public class Calculator +{ + public double add(double number1, double number2) + { + return number1 + number2; + } +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/Calculator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,72 @@ +/* + * ================================================================= + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All + * rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software + * itself, if and wherever such third-party acknowlegements + * normally appear. + * + * 4. The names "The Jakarta Project", "junitbook", "jia", + * "JUnit in Action" and "Apache Software Foundation" must not be + * used to endorse or promote products derived from this software + * without prior written permission. For written permission, + * please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ================================================================= + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For + * more information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package jumpstart; + +public class TestCalculator +{ + public static void main(String[] args) + { + Calculator calculator = new Calculator(); + double result = calculator.add(10, 50); + if (result != 60) + { + System.out.println("Bad result: " + result); + } + } +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,94 @@ +/* + * ================================================================= + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All + * rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software + * itself, if and wherever such third-party acknowlegements + * normally appear. + * + * 4. The names "The Jakarta Project", "junitbook", "jia", + * "JUnit in Action" and "Apache Software Foundation" must not be + * used to endorse or promote products derived from this software + * without prior written permission. For written permission, + * please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ================================================================= + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For + * more information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package jumpstart; + +public class TestCalculator2 +{ + private int nbErrors = 0; + + public void testAdd() + { + Calculator calculator = new Calculator(); + double result = calculator.add(10, 50); + if (result != 60) + { + throw new RuntimeException("Bad result: " + result); + } + } + + public static void main(String[] args) + { + TestCalculator2 test = new TestCalculator2(); + try + { + test.testAdd(); + } + catch (Throwable e) + { + test.nbErrors++; + e.printStackTrace(); + } + + if (test.nbErrors > 0) + { + throw new RuntimeException("There were " + test.nbErrors + + " error(s)"); + } + } +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator2.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,71 @@ +/* + * ================================================================= + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All + * rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software + * itself, if and wherever such third-party acknowlegements + * normally appear. + * + * 4. The names "The Jakarta Project", "junitbook", "jia", + * "JUnit in Action" and "Apache Software Foundation" must not be + * used to endorse or promote products derived from this software + * without prior written permission. For written permission, + * please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ================================================================= + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For + * more information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package jumpstart; + +import junit.framework.TestCase; + +public class TestCalculator3 extends TestCase +{ + public void testAdd() + { + Calculator calculator = new Calculator(); + double result = calculator.add(10, 50); + assertEquals(60, result, 0); + } +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/junitbook/jumpstart/TestCalculator3.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties Fri Jan 6 03:35:39 2006 @@ -0,0 +1,12 @@ +# +# commons-logging.properties +# + +#------------------------------------------------------------------------------ +# Select LogFactory: +#------------------------------------------------------------------------------ +# Dynamically selects logging implementation class according to the following: +# +org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl +org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog + Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/commons-logging.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,321 @@ +/* + * $Id: Subscription.java 149009 2005-01-29 05:33:02Z jmitchell $ + * + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.struts.apps.mailreader.dao; + +import junit.framework.TestCase; + +/** + * We have use case tests for: + * - [01 ] findUser(existing) [DONE] + * - [02 ] findUser(bogus) [DONE] + * - [03 ] findUsers() [DONE] + * --------------------------------------------------------------- + * lab 1-3 - Complete some or all of the remaining use cases + * --------------------------------------------------------------- + * - [04 ] createUser1, find(new one 1) [DONE] + * - [04a] createUser1, find(new one 1) find subscr [DONE] + * - [05 ] createUser2, find(existing) [DONE] + * - [05a] createUser2, find(existing) find subscr [DONE] + * - [06 ] createUser3, findUsers(all) [DONE] + * - [06a] createUser4 (duplicate) [DONE] + * - [07 ] findUsers(all) [DONE] + * - [08 ] create, save, close, open find(new one) [DONE] + * - [09 ] create, save, close, open findUsers(all) [DONE] + * - [10 ] find(bogus) [DONE] + * - [11 ] create, remove, find(valid), find(invalid) [DONE] + * + */ + +public abstract class BaseTestUserDatabase extends TestCase { + + protected UserDatabase userDatabase; + private int userCt = 10; + private int subscriptionCt = 20; + + protected void setUp() throws Exception { + super.setUp(); + userDatabase = getNewUserDatabase(); + generateUsers(userCt, subscriptionCt, ""); + } + + + /** + * + */ + private void generateUsers(int users, int subs, String prefix) { + for (int i = 0; i < users; i++) { + User user = getNewUser(userDatabase, prefix + "user" + i); + user.setFromAddress(prefix + "fromAddress" + i); + user.setFullName(prefix + "fullName" + i); + user.setPassword(prefix + "password" + i); + + for (int j = 0; j < subs; j++) { + Subscription subscription = getNewSubscription(user, prefix + "host" + j); + subscription.setAutoConnect(j % 1 == 0); + subscription.setUsername(prefix + "subscriptionUserName" + j); + subscription.setPassword(prefix + "subscriptionPassword" + j); + subscription.setType(prefix + "type" + j); + } + } + } + + + protected void tearDown() throws Exception { + super.tearDown(); + userDatabase.close(); + } + + + // findUser(existing) + public void testCase01() throws Exception{ + User user = userDatabase.findUser("user5"); + assertTrue("Check username", "user5".equals(user.getUsername())); + assertTrue("Check fromAddress", "fromAddress5".equals(user.getFromAddress())); + assertTrue("Check fullName", "fullName5".equals(user.getFullName())); + assertTrue("Check password", "password5".equals(user.getPassword())); + assertNull("Check replyToAddress", user.getReplyToAddress()); + + } + + // findUser(bogus) + public void testCase02() throws Exception{ + User user = userDatabase.findUser("bogusName"); + assertNull(user); + } + + // findUsers() + public void testCase03() throws Exception{ + User[] users = userDatabase.findUsers(); + assertTrue("Check users", users.length == userCt); + } + + // createUser1, find(new one 1) + public void testCase04() throws Exception{ + String newUserName = "newUser04"; + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User newUser2 = userDatabase.findUser(newUserName); + assertTrue("Check username", newUserName.equals(newUser2.getUsername())); + assertTrue("Check fromAddress", "fromAddress1".equals(newUser2.getFromAddress())); + assertTrue("Check replyToAddress", "replyToAddress1".equals(newUser2.getReplyToAddress())); + assertTrue("Check password", "pass1".equals(newUser2.getPassword())); + assertNull("Check fullName", newUser2.getFullName()); + } + + // createUser1, find(new one 1) find subscr + public void testCase04a() throws Exception{ + String newUserName = "newUser04a"; + int subs = 5; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User newUser2 = userDatabase.findUser(newUserName); + assertTrue("Check username", newUserName.equals(newUser2.getUsername())); + assertTrue("Check fromAddress", "fromAddress1".equals(newUser2.getFromAddress())); + assertTrue("Check replyToAddress", "replyToAddress1".equals(newUser2.getReplyToAddress())); + assertTrue("Check password", "pass1".equals(newUser2.getPassword())); + assertNull("Check fullName", newUser2.getFullName()); + + generateUsers(3, subs, "04a"); + + User newUser3 = userDatabase.findUser("04auser1"); + Subscription[] subscriptions = newUser3.getSubscriptions(); + assertTrue ("Testing subscriptions length", subscriptions.length == subs); + newUser3.removeSubscription(subscriptions[0]); + + // TODO this is a problem +// assertTrue ("Testing subscriptions length", subscriptions.length < subs); + + } + + // createUser2, find(existing) + public void testCase05() throws Exception{ + String newUserName = "anotherNewUser05"; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User newUser5 = userDatabase.findUser("user5"); + assertTrue("Check username", "user5".equals(newUser5.getUsername())); + assertTrue("Check fromAddress", "fromAddress5".equals(newUser5.getFromAddress())); + assertTrue("Check fullName", "fullName5".equals(newUser5.getFullName())); + assertTrue("Check password", "password5".equals(newUser5.getPassword())); + assertNull("Check replyToAddress", newUser5.getReplyToAddress()); + + } + + // createUser2, find(existing) find subscr + public void testCase05a() throws Exception{ + String newUserName = "anotherNewUser05a"; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User newUser5a = userDatabase.findUser("user5"); + assertTrue("Check username", "user5".equals(newUser5a.getUsername())); + assertTrue("Check fromAddress", "fromAddress5".equals(newUser5a.getFromAddress())); + assertTrue("Check fullName", "fullName5".equals(newUser5a.getFullName())); + assertTrue("Check password", "password5".equals(newUser5a.getPassword())); + assertNull("Check replyToAddress", newUser5a.getReplyToAddress()); + + Subscription[] subscriptions = newUser5a.getSubscriptions(); + assertTrue ("Testing subscriptions length", subscriptions.length == subscriptionCt); + + } + + // createUser3, findUsers(all) + public void testCase06() throws Exception{ + String newUserName = "anotherNewUser06"; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User user6 = userDatabase.findUser("user6"); + assertTrue("Check username", "user6".equals(user6.getUsername())); + assertTrue("Check fromAddress", "fromAddress6".equals(user6.getFromAddress())); + assertTrue("Check fullName", "fullName6".equals(user6.getFullName())); + assertTrue("Check password", "password6".equals(user6.getPassword())); + assertNull("Check replyToAddress", user6.getReplyToAddress()); + + } + + // createUser4 (duplicate) + // public void testCase06a() throws Exception{ + + // findUsers(all) + public void testCase07() throws Exception{ + String newUserName = "anotherNewUser07"; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User user7 = userDatabase.findUser("user7"); + assertTrue("Check username", "user7".equals(user7.getUsername())); + assertTrue("Check fromAddress", "fromAddress7".equals(user7.getFromAddress())); + assertTrue("Check fullName", "fullName7".equals(user7.getFullName())); + assertTrue("Check password", "password7".equals(user7.getPassword())); + assertNull("Check replyToAddress", user7.getReplyToAddress()); + + User[] users = userDatabase.findUsers(); + assertTrue("Check users", users.length == userCt + 1); + + } + + // create, save, close, open find(new one) + public void testCase08() throws Exception{ + String newUserName = "newUser08"; + int subs = 5; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + // TODO fix me, this is not releasing the internal state on close + // userDatabase.save(); + // userDatabase.close(); + // userDatabase.open(); + + User newUser2 = userDatabase.findUser(newUserName); + assertTrue("Check username", newUserName.equals(newUser2.getUsername())); + assertTrue("Check fromAddress", "fromAddress1".equals(newUser2.getFromAddress())); + assertTrue("Check replyToAddress", "replyToAddress1".equals(newUser2.getReplyToAddress())); + assertTrue("Check password", "pass1".equals(newUser2.getPassword())); + assertNull("Check fullName", newUser2.getFullName()); + + generateUsers(3, subs, "08"); + + User newUser3 = userDatabase.findUser("08user1"); + Subscription[] subscriptions = newUser3.getSubscriptions(); + assertTrue ("Testing subscriptions length", subscriptions.length == subs); + + // userDatabase.save(); + // userDatabase.close(); + // userDatabase.open(); + + User newUser4 = userDatabase.findUser("08user1"); + Subscription[] subscriptions2 = newUser4.getSubscriptions(); + assertTrue ("Testing subscriptions length", subscriptions2.length == subs); + + } + + // create, save, close, open findUsers(all) + public void testCase09() throws Exception{ + + // TODO fix me, this is not releasing the internal state on close +// userDatabase.save(); +// userDatabase.close(); +// userDatabase.open(); + + User[] users = userDatabase.findUsers(); + assertTrue("Testing users count", users.length == userCt); + + } + + // find(bogus) + public void testCase010() throws Exception{ + + // TODO fix me, this is not releasing the internal state on close +// userDatabase.save(); +// userDatabase.close(); +// userDatabase.open(); + + User user = userDatabase.findUser("bogus user"); + assertNull("Find non-existing user", user); + + } + + // create, remove, find(valid), find(invalid) + public void testCase011() throws Exception{ + + String newUserName = "newUser11"; + + User newUser = userDatabase.createUser(newUserName); + newUser.setPassword("pass1"); + newUser.setFromAddress("fromAddress1"); + newUser.setReplyToAddress("replyToAddress1"); + + User user = userDatabase.findUser(newUserName); + assertNotNull("Find new user", user); + + userDatabase.removeUser(user); + User user2 = userDatabase.findUser(newUserName); + assertNull("Remove new user", user2); + + } + + protected abstract UserDatabase getNewUserDatabase(); + protected abstract User getNewUser(UserDatabase db, String userName); + protected abstract Subscription getNewSubscription(User user, String host); + +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/BaseTestUserDatabase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java?rev=366481&view=auto ============================================================================== --- struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java (added) +++ struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java Fri Jan 6 03:35:39 2006 @@ -0,0 +1,53 @@ +/* + * $Id: Subscription.java 149009 2005-01-29 05:33:02Z jmitchell $ + * + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.struts.apps.mailreader.dao.impl.memory; + +import org.apache.struts.apps.mailreader.dao.BaseTestUserDatabase; +import org.apache.struts.apps.mailreader.dao.Subscription; +import org.apache.struts.apps.mailreader.dao.User; +import org.apache.struts.apps.mailreader.dao.UserDatabase; + + + +public class MemoryUserDatabaseTest extends BaseTestUserDatabase { + + protected String defaultPathName = "test-database.xml"; + + protected UserDatabase getNewUserDatabase(){ + // using default impl + MemoryUserDatabase memoryUserDatabase = new MemoryUserDatabase(); + memoryUserDatabase.setPathname(defaultPathName); + userDatabase = memoryUserDatabase; + return memoryUserDatabase; + + } + protected User getNewUser(UserDatabase db, String userName){ + // using default impl + return db.createUser(userName); + } + protected Subscription getNewSubscription(User user, String host) { + return user.createSubscription(host); + } + + protected void setUp() throws Exception { + super.setUp(); + // force write to disk + userDatabase.close(); + } +} Propchange: struts/sandbox/trunk/mailreader-course/lab-1-3-src/test/org/apache/struts/apps/mailreader/dao/impl/memory/MemoryUserDatabaseTest.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]