From: Pieter v. Z. <pv...@us...> - 2005-08-05 12:53:39
|
Update of /cvsroot/coefficient/mailForum/src-test/za/org/coefficient/modules/mailforum In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17598/modules/mailForum/src-test/za/org/coefficient/modules/mailforum Modified Files: MailForumTest.java Log Message: both test are now working. moved some methods for setting up the db from MailforumTest to the TestDBSetup class. One instance is created of the db and context and used by both tests. Need to move the code in the constructor to the setUp(); tearDown(); methods of the testcase Index: MailForumTest.java =================================================================== RCS file: /cvsroot/coefficient/mailForum/src-test/za/org/coefficient/modules/mailforum/MailForumTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MailForumTest.java 5 Aug 2005 09:13:33 -0000 1.2 --- MailForumTest.java 5 Aug 2005 12:53:28 -0000 1.3 *************** *** 7,27 **** import java.util.HashMap; import java.util.List; - import java.util.Locale; import java.util.Map; - import java.util.TimeZone; - import net.sf.hibernate.HibernateException; import net.sf.hibernate.util.HibernateUtil; - - import za.org.coefficient.authentication.CoefficientUser; - import za.org.coefficient.authentication.Role; - import za.org.coefficient.core.Constants; - import za.org.coefficient.core.Project; - import za.org.coefficient.interfaces.CoefficientContext; - import za.org.coefficient.testing.CoefficientTestCase; import za.org.coefficient.testing.CoefficientTestingContext; import za.org.coefficient.testing.TestDBSetup; ! import za.org.coefficient.util.ejb.SecurityUtil; /** --- 7,17 ---- import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.hibernate.HibernateException; import net.sf.hibernate.util.HibernateUtil; import za.org.coefficient.testing.CoefficientTestCase; import za.org.coefficient.testing.CoefficientTestingContext; import za.org.coefficient.testing.TestDBSetup; ! /** *************** *** 31,38 **** public class MailForumTest extends CoefficientTestCase { private TestDBSetup testDbSchema = null; ! ! private static String CURRENT_CONTEXT = "CURRENT_CONTEXT"; ! ! private static String CURRENT_PROJECT = "CURRENT_PROJECT"; /** --- 21,25 ---- public class MailForumTest extends CoefficientTestCase { private TestDBSetup testDbSchema = null; ! private HashMap currentSetupMap = null; /** *************** *** 43,304 **** public MailForumTest(String name) { super(name); } - private void listAllProjects() { - try { - List list = HibernateUtil.findAll(Project.class); - System.out - .println("MailForumsTest.testListForums()->list size od project list:" - + list.size()); - list = HibernateUtil.findAll(Role.class); - System.out - .println("MailForumsTest.testListForums()->list size of all roles in db:" - + list.size()); - - } catch (HibernateException e) { - System.err - .println("MailForumsTest.testListForums()->Could not retrieve any projects" - + e); - } - - }// end listAllProjects() - - /** - * @author pieter20 Jul 31, 2005 Setup the default db - */ - public void setupTestDb() { - // setup the default test db. - testDbSchema = new TestDBSetup(); - } - - /** - * @author pieter20 Jul 31, 2005 Create's a project that will be used - * throughout the test - * @return object of type Project - */ - private Project createProject() { - Project project = testDbSchema.setupDefaultProject(); - try { - HibernateUtil.saveOrUpdate(project); - } catch (HibernateException e) { - System.err - .println("MailForumsTest.testListForums()->Project not saved" - + e); - } - - assertNotNull(project); - return project; - } - - /** - * @author pieter20 Aug 3, 2005 Using the project module: Projects - * @return - */ - private Project createPublicProject(Map requestMap, CoefficientContext ctx, - String module) { - // TODO: Try to uses the project module later. Not using it now as it - // complicates the testing. Seperation of concerns. - // requestMap.put("shortName", "test"); - // requestMap.put("name", "Testing Project"); - // requestMap.put("homePage", "none"); - // requestMap.put("description", "This project is used to test"); - // requestMap.put("isPrivate", "off"); - // - // ArrayList mods = new ArrayList(); - // mods.add(module); - // requestMap.put("modules", mods); - // - // requestMap.put("module", "project"); - // requestMap.put("op", "createProject"); - // - // - // ctx = new CoefficientTestingContext(new HashMap(), requestMap, - // new HashMap()); - // - // Object result = null; - // // call method: - // try { - // result = invokeOpOnModule(ctx); - // } catch (Exception e) { - // System.err.println(e); - // } - // // checks if the user has been created - // assertNotNull(result); - return null; - } - - private CoefficientUser createUserObject() { - CoefficientUser user = new CoefficientUser(); - user.setFullName("Tester"); - user.setEmail("pv...@cs..."); - user.setPassword("test"); - user.setUserName("test"); - user.setLanguage(Locale.US); - user.setTimeZone(TimeZone.getDefault()); - user.setActive(true); - return user; - } - - /** - * @author pieter20 Jul 31, 2005 Create a user for this test TODO: Should i - * sent through CoefficientTestingContext or the interface: - * CoefficientContext - * @param requestMap - * @param ctx - * @param project - */ - private void createUser(CoefficientTestingContext ctx, Project project) { - HashMap requestMap = (HashMap) ctx.getRequestData(); - // set user - // this could be done by calling the module UserAdmin - requestMap.put("fullName", "Pieter van Zyl"); - requestMap.put("email", "pv...@cs..."); - requestMap.put("password1", "green"); - requestMap.put("userName", "pvzyl"); - requestMap.put("language", Locale.US); - requestMap.put("timeZone", TimeZone.getDefault()); - requestMap.put("active", new Boolean(true)); - // Note: systemRole can not be populated using the BeanUtils. - // We do not cater for the Role object in: - // BaseCoefficientContext.setProperties(.. - - requestMap.put("module", "UserAdmin"); - requestMap.put("op", "saveUser"); - - // this will force the user to be added to the context. - - ctx.setRequestData(requestMap); - - ctx.setProject(project); - - Object result = null; - // call method: - try { - result = invokeOpOnModule(ctx); - } catch (Exception e) { - System.err.println(e); - } - // checks if the user has been created - assertNotNull(result); - - }// end createUser - - /** - * @author pieter20 Jul 31, 2005 Create a user for this test TODO: Should i - * sent through CoefficientTestingContext or the interface: - * CoefficientContext - * @param requestMap - * @param ctx - * @param project - */ - private void createUserNotUsingModule(CoefficientTestingContext ctx, - Project project) { - HashMap requestMap = (HashMap) ctx.getRequestData(); - // set user - // this could be done by calling the module UserAdmin - - requestMap.put("password1", "green"); - - // Note: systemRole can not be populated using the BeanUtils. - // We do not cater for the Role object in: - // BaseCoefficientContext.setProperties(.. - - requestMap.put("module", "UserAdmin"); - requestMap.put("op", "saveUser"); - requestMap.put("password1", "green"); - - ctx.setRequestData(requestMap); - - ctx.setProject(project); - - Object result = null; - // call method: - try { - result = invokeOpOnModule(ctx); - } catch (Exception e) { - System.err.println(e); - } - // checks if the user has been created - assertNotNull(result); - - }// end createUser - - /** - * @author pieter20 Jul 31, 2005 Associate a user with a project. The user - * is specified as a parameter in the requestMap. - * @param requestMap - * @param ctx - * @param project - */ - private void addUserToProject(CoefficientTestingContext ctx, Project project) { - HashMap requestMap = (HashMap) ctx.getRequestData(); - // associate member/user with project. Use MemberAdmin module's method: - // addMember - requestMap.put("module", "MemberAdmin"); - requestMap.put("op", "addMember"); - - ctx.setRequestData(requestMap); - ctx.setProject(project); - - Object result = null; - // call method: - try { - result = invokeOpOnModule(ctx); - } catch (Exception e) { - System.err.println(e); - } - // checks if the user/member has been associated with this project: - assertNotNull(result); - - }// end addUserToProject() - - private void loginUser(CoefficientTestingContext ctx) { - HashMap requestMap = (HashMap) ctx.getRequestData(); - // login using the new user - requestMap.put("username", "pvzyl"); - requestMap.put("password", "green"); - requestMap.put("module", "Security"); - requestMap.put("op", "login"); - - ctx.setRequestData(requestMap); - - Object result = null; - // call method: - try { - result = invokeOpOnModule(ctx); - } catch (Exception e) { - System.err.println(e); - } - // checks if the login was successfull - assertNotNull(result); - assertTrue(ctx.isError()); - - } - - private HashMap setupBasics() { - HashMap currentSetupMap = new HashMap(); - - // setup the default test db. - setupTestDb(); - - // creates a default project without going through the project module. - Project testProject = createProject(); - currentSetupMap.put(CURRENT_PROJECT, testProject); - CoefficientTestingContext ctx = new CoefficientTestingContext( - new HashMap(), new HashMap(), new HashMap()); - - createUser(ctx, testProject); - // login user by calling tHe nodule or - // creating the coefficient user object on my side - loginUser(ctx); - - // associate member/user with project. Use MemberAdmin module's method: - // addMember: - addUserToProject(ctx, testProject); - currentSetupMap.put(CURRENT_CONTEXT, ctx); - return currentSetupMap; - - }// end setupBasics - private boolean checkExistence(String className) { try { --- 30,37 ---- public MailForumTest(String name) { super(name); + testDbSchema = TestDBSetup.getInstance(); + currentSetupMap = testDbSchema.getCurrentSetupMap();//contains the current context and state } private boolean checkExistence(String className) { try { *************** *** 323,333 **** } public void testForumCreation() { ! HashMap currentSetupMap = setupBasics(); ! Map requestMap = null; CoefficientTestingContext ctx = null; ! ctx = (CoefficientTestingContext) currentSetupMap.get(CURRENT_CONTEXT); requestMap = ctx.getRequestData(); --- 56,72 ---- } + /** + * @author pieter20 + * Aug 5, 2005 + * Tests to see if the MailForum module can create a new forum + */ public void testForumCreation() { ! System.out ! .println("MailForumsTest.testForumCreation()-> starting testing"); Map requestMap = null; CoefficientTestingContext ctx = null; ! ctx = (CoefficientTestingContext) currentSetupMap ! .get(CoefficientTestCase.CURRENT_CONTEXT); requestMap = ctx.getRequestData(); *************** *** 395,407 **** /** ! * @author pieter20 Jul 19, 2005 Test to see if the Forum lists the correct ! * amount of forums */ public void testListingOfForums() { ! HashMap currentSetupMap = setupBasics(); Map requestMap = null; CoefficientTestingContext ctx = null; ! ctx = (CoefficientTestingContext) currentSetupMap.get(CURRENT_CONTEXT); requestMap = ctx.getRequestData(); --- 134,149 ---- /** ! * @author pieter20 Jul 19, 2005 Test to see if the Mailforum module ! * can list a forum. */ public void testListingOfForums() { ! ! System.out ! .println("MailForumsTest.testListingOfForums()-> starting testing"); Map requestMap = null; CoefficientTestingContext ctx = null; ! ctx = (CoefficientTestingContext) currentSetupMap ! .get(CoefficientTestCase.CURRENT_CONTEXT); requestMap = ctx.getRequestData(); *************** *** 429,433 **** int exist = ctx.getPage().getCenter().indexOf("forumid"); System.out ! .println("MailForumsTest.testListForums()-> contains forum: " + exist); } catch (Exception e) { --- 171,175 ---- int exist = ctx.getPage().getCenter().indexOf("forumid"); System.out ! .println("MailForumsTest.testListingOfForums()-> contains forum: " + exist); } catch (Exception e) { |