From: Pieter v. Z. <pv...@us...> - 2005-08-05 09:13:42
|
Update of /cvsroot/coefficient/mailForum/src-test/za/org/coefficient/modules/mailforum In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12684/modules/mailForum/src-test/za/org/coefficient/modules/mailforum Modified Files: MailForumTest.java Log Message: added in MailForumTest: testForumCreation(), setupBasics(), checkExistence(to test if and object was created in the db) added CURRENT_CONTEXT and CURRENT_PROJECT. I am now using ONE context object as I am setting up the test case. added loginUser to login the user and set the user in the session. Index: MailForumTest.java =================================================================== RCS file: /cvsroot/coefficient/mailForum/src-test/za/org/coefficient/modules/mailforum/MailForumTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MailForumTest.java 2 Aug 2005 07:13:41 -0000 1.1 --- MailForumTest.java 5 Aug 2005 09:13:33 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- package za.org.coefficient.modules.mailforum; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; *************** *** 13,17 **** --- 14,20 ---- 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; *************** *** 20,24 **** import za.org.coefficient.testing.CoefficientTestingContext; import za.org.coefficient.testing.TestDBSetup; ! /** --- 23,27 ---- import za.org.coefficient.testing.CoefficientTestingContext; import za.org.coefficient.testing.TestDBSetup; ! import za.org.coefficient.util.ejb.SecurityUtil; /** *************** *** 29,32 **** --- 32,39 ---- private TestDBSetup testDbSchema = null; + private static String CURRENT_CONTEXT = "CURRENT_CONTEXT"; + + private static String CURRENT_PROJECT = "CURRENT_PROJECT"; + /** * Jul 19, 2005 *************** *** 85,95 **** /** ! * @author pieter20 Jul 31, 2005 Create a user for this test * @param requestMap * @param ctx * @param project */ ! private void createUser(Map requestMap, CoefficientContext ctx, ! Project project) { // set user // this could be done by calling the module UserAdmin --- 92,153 ---- /** ! * @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 *************** *** 107,114 **** requestMap.put("module", "UserAdmin"); requestMap.put("op", "saveUser"); requestMap.put("password1", "green"); ! ctx = new CoefficientTestingContext(new HashMap(), requestMap, ! new HashMap()); ctx.setProject(project); --- 165,212 ---- 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); *************** *** 133,138 **** * @param project */ ! private void addUserToProject(Map requestMap, CoefficientContext ctx, ! Project project) { // associate member/user with project. Use MemberAdmin module's method: // addMember --- 231,236 ---- * @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 *************** *** 140,145 **** requestMap.put("op", "addMember"); ! ctx = new CoefficientTestingContext(new HashMap(), requestMap, ! new HashMap()); ctx.setProject(project); --- 238,242 ---- requestMap.put("op", "addMember"); ! ctx.setRequestData(requestMap); ctx.setProject(project); *************** *** 156,164 **** }// end addUserToProject() ! /** ! * @author pieter20 Jul 19, 2005 ! * Test to see if the Forum lists the correct amount of forums ! */ ! public void testListForums() { // setup the default test db. --- 253,281 ---- }// 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. *************** *** 167,179 **** // creates a default project without going through the project module. Project testProject = createProject(); ! listAllProjects(); ! Map requestMap = new HashMap(); ! CoefficientTestingContext ctx = null; - createUser(requestMap, ctx, testProject); // associate member/user with project. Use MemberAdmin module's method: // addMember: ! addUserToProject(requestMap, ctx, testProject); // add all parameters that are need into the context map --- 284,408 ---- // 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 { ! List list = HibernateUtil.findAll(Class.forName(className)); ! ! System.out.println("MailForumsTest.checkExistence()->list size:" ! + list.size()); ! // System.out ! // .println("MailForumsTest.checkExistence()->list contains: " ! // + name + " : " + list.contains(name)); ! // return list.contains(name); ! return (list.size() == 1); ! } catch (HibernateException e) { ! System.err ! .println("MailForumsTest.checkExistence()->Could not retrieve any objects" ! + e); ! } catch (ClassNotFoundException e) { ! e.printStackTrace(); ! } ! return false; ! ! } ! ! public void testForumCreation() { ! HashMap currentSetupMap = setupBasics(); ! ! Map requestMap = null; ! CoefficientTestingContext ctx = null; ! ! ctx = (CoefficientTestingContext) currentSetupMap.get(CURRENT_CONTEXT); ! requestMap = ctx.getRequestData(); ! ! // if the context is null something went wrong!! ! assertNotNull(requestMap); ! // set project ! requestMap.put("mailAddressSnippet", ""); ! requestMap.put("fullName", "Test Forum List"); ! requestMap.put("mailSubjectPrefix", "test-forum"); ! requestMap.put("description", " This forum is used for testing"); ! requestMap.put("requireMembershipToView", "true"); ! requestMap.put("requireMembershipToPost", "true"); ! requestMap.put("moderated", "false"); ! requestMap.put("openSubscription", "false");// setRequirePermissionToSubscribe ! requestMap.put("footer", " Test Forum Footer"); ! requestMap.put("maxMessageSize", "1000"); ! requestMap.put("maxAttachmentSize", "0"); ! ! requestMap.put("module", "MailForum"); ! requestMap.put("op", "forumSaveAction"); ! ! ctx.setRequestData(requestMap); ! // ctx.setProject(testProject); ! ! Object result = null; ! // call method: ! try { ! result = invokeOpOnModule(ctx); ! } catch (Exception e) { ! System.err.println(e); ! } ! // the list should be empty and not null: ! assertNotNull(result); ! // check to see if a certain tag is present in the result wich is a page ! // object containing an ! // html string ! if (result instanceof CoefficientTestingContext) { ! ctx = (CoefficientTestingContext) result; ! try { ! int fullNameExist = ctx.getPage().getCenter().indexOf( ! "fullName"); ! int forumIdExist = ctx.getPage().getCenter().indexOf("forumid"); ! System.out ! .println("MailForumsTest.testForumCreation()-> contains fullName str: " ! + fullNameExist ! + " contains forumid str: " ! + forumIdExist); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! ! } else { ! System.out ! .println("MailForumTest.testForumCreation()->We are only interested in CoefficientTestingContext objects!!!!"); ! ! }// end if tag check ! // OR white box testing: ! boolean existsInDb = checkExistence("org.dithaka.messaging.Forum"); ! assertTrue(existsInDb); ! System.out ! .println("MailForumsTest.testForumCreation()-> exists in db: " ! + existsInDb); ! ! } ! ! /** ! * @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(); // add all parameters that are need into the context map *************** *** 181,187 **** requestMap.put("module", "MailForum"); requestMap.put("op", "forumList"); ! ctx = new CoefficientTestingContext(new HashMap(), requestMap, ! new HashMap()); ! ctx.setProject(testProject); Object result = null; --- 410,414 ---- requestMap.put("module", "MailForum"); requestMap.put("op", "forumList"); ! ctx.setRequestData(requestMap); Object result = null; *************** *** 194,198 **** // the list should be empty and not null: assertNotNull(result); ! if (result instanceof CoefficientTestingContext) { ctx = (CoefficientTestingContext) result; --- 421,427 ---- // the list should be empty and not null: assertNotNull(result); ! // check to see if a certain tag is present in the result wich is a page ! // object containing an ! // html string if (result instanceof CoefficientTestingContext) { ctx = (CoefficientTestingContext) result; *************** *** 212,215 **** } ! } } --- 441,445 ---- } ! }// end test case: testListForums ! } |