[jboss-svn-commits] JBL Code SVN: r12182 - labs/jbossforums/branches/tests/main/src.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 28 13:22:37 EDT 2007


Author: adamw
Date: 2007-05-28 13:22:37 -0400 (Mon, 28 May 2007)
New Revision: 12182

Modified:
   labs/jbossforums/branches/tests/main/src/globals.py
   labs/jbossforums/branches/tests/main/src/main.py
   labs/jbossforums/branches/tests/main/src/view_main.py
   labs/jbossforums/branches/tests/main/src/view_post.py
Log:
Viewing a random post in a random forum

Modified: labs/jbossforums/branches/tests/main/src/globals.py
===================================================================
--- labs/jbossforums/branches/tests/main/src/globals.py	2007-05-28 16:44:31 UTC (rev 12181)
+++ labs/jbossforums/branches/tests/main/src/globals.py	2007-05-28 17:22:37 UTC (rev 12182)
@@ -1,8 +1,6 @@
 from HTTPClient import NVPair
 from net.grinder.plugin.http import HTTPPluginControl
 
-print "XXX"
-
 connectionDefaults = HTTPPluginControl.getConnectionDefaults()
 httpUtilities = HTTPPluginControl.getHTTPUtilities()
 
@@ -12,4 +10,8 @@
     NVPair('Accept-Language', 'en-us,en;q=0.5'),
     NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'), )
 
-url0 = 'http://localhost:8080'
\ No newline at end of file
+# Host of the tested forums instance
+url0 = 'http://localhost:8080'
+
+# How many times (max.) the "next page" link will be clicked when viewing a post
+next_clicks_range = 1
\ No newline at end of file

Modified: labs/jbossforums/branches/tests/main/src/main.py
===================================================================
--- labs/jbossforums/branches/tests/main/src/main.py	2007-05-28 16:44:31 UTC (rev 12181)
+++ labs/jbossforums/branches/tests/main/src/main.py	2007-05-28 17:22:37 UTC (rev 12182)
@@ -3,6 +3,7 @@
 from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
 from HTTPClient import NVPair
 import time
+import random
 
 from globals import *
 
@@ -16,4 +17,6 @@
 
 class TestRunner:
     def __call__(self):
-        viewMain()
\ No newline at end of file
+        viewMain()
+        forum_id = random.choice(viewMain.forums_ids)
+        viewPost(forum_id)
\ No newline at end of file

Modified: labs/jbossforums/branches/tests/main/src/view_main.py
===================================================================
--- labs/jbossforums/branches/tests/main/src/view_main.py	2007-05-28 16:44:31 UTC (rev 12181)
+++ labs/jbossforums/branches/tests/main/src/view_main.py	2007-05-28 17:22:37 UTC (rev 12182)
@@ -6,8 +6,13 @@
 from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
 from HTTPClient import NVPair
 
+import re
+
 from globals import *
 
+forum_id_regexp_string = """JBossForumsWindow(?:\;jsessionid=[^\?]*)?\?action=1\&v=f\&f=(\d+)"""
+forum_id_regexp = re.compile(forum_id_regexp_string)
+
 main_headers0= \
   ( NVPair('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'), )
 
@@ -156,28 +161,6 @@
   def page1(self):
     """GET forums (main_requests 101-137)."""
     result = main_request101.GET('/portal/portal/default/forums')
-    self.token_jsessionid = \
-      httpUtilities.valueFromBodyURI('jsessionid') # '7126763EC15566CAF3AC3E048AA9DA82'
-    # 2 different values for token_windowstate found in response, using the first one.
-    self.token_windowstate = \
-      httpUtilities.valueFromBodyURI('windowstate') # 'minimized'
-    self.token_action = \
-      httpUtilities.valueFromBodyURI('action') # '1'
-    # 3 different values for token_v found in response, using the first one.
-    self.token_v = \
-      httpUtilities.valueFromBodyURI('v') # 'c'
-    self.token_c = \
-      httpUtilities.valueFromBodyURI('c') # '1'
-    self.token_f = \
-      httpUtilities.valueFromBodyURI('f') # '1'
-    self.token_p = \
-      httpUtilities.valueFromBodyURI('p') # '12'
-    self.token__id10jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id10jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
-    self.token_jsf_tree_64 = \
-      httpUtilities.valueFromHiddenInput('jsf_tree_64') # 'rO0ABXNyAEdvcmcuYXBhY2hlLm15ZmFjZXMuYXBw...'
-    self.token_jsf_viewid = \
-      httpUtilities.valueFromHiddenInput('jsf_viewid') # '/views/index.xhtml'
 
     main_request102.GET('/portal-ajax/dyna/style.css')
 
@@ -251,7 +234,8 @@
 
     main_request137.GET('/portal-core/themes/renaissance/images/portlet-bottom-right.gif')
 
-    print result.text
+    # From the result, reading available forum numbers.
+    self.forums_ids = forum_id_regexp.findall(result.text)  
 
     return result
 
@@ -260,9 +244,9 @@
 
   def __call__(self):
     """This method is called for every run performed by the worker thread."""
-    all()
+    self.all()
 
-def instrumentMethod(test, method_name, c=MainPage):
+def instrumentMethod(test, method_name, c=ViewMain):
   """Instrument a method with the given Test."""
   unadorned = getattr(c, method_name)
   import new

Modified: labs/jbossforums/branches/tests/main/src/view_post.py
===================================================================
--- labs/jbossforums/branches/tests/main/src/view_post.py	2007-05-28 16:44:31 UTC (rev 12181)
+++ labs/jbossforums/branches/tests/main/src/view_post.py	2007-05-28 17:22:37 UTC (rev 12182)
@@ -6,8 +6,17 @@
 from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
 from HTTPClient import NVPair
 
+import re
+import random
+
 from globals import *
 
+page_id_regexp_string = """\&page=\d+\"\>Next\<\/a\>"""
+page_id_regexp = re.compile(page_id_regexp_string)
+
+topic_id_regexp_string = """JBossForumsWindow(?:\;jsessionid=[^\?]*)?\?action=1\&v=t\&t=(\d+)"""
+topic_id_regexp = re.compile(topic_id_regexp_string)
+
 post_headers0= \
   ( NVPair('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'), )
 
@@ -62,7 +71,7 @@
 post_request206 = HTTPRequest(url=url0, headers=post_headers2)
 post_request206 = Test(2206, 'GET folder_sticky.gif').wrap(post_request206)
 
-post_request301 = HTTPRequest(url=url0, headers=headers3)
+post_request301 = HTTPRequest(url=url0, headers=post_headers3)
 post_request301 = Test(2301, 'GET JBossForumsWindow').wrap(post_request301)
 
 post_request302 = HTTPRequest(url=url0, headers=post_headers3)
@@ -97,76 +106,22 @@
   def page1(self):
     """GET forums (post_request 101)."""
     result = post_request101.GET('/portal/portal/default/forums')
-    # 2 different values for token_windowstate found in response, using the first one.
-    self.token_windowstate = \
-      httpUtilities.valueFromBodyURI('windowstate') # 'minimized'
-    # 2 different values for token_jsessionid found in response, using the first one.
-    self.token_jsessionid = \
-      httpUtilities.valueFromBodyURI('jsessionid') # 'B9B81FEF67E80F326D126CA922F87D88'
-    self.token_action = \
-      httpUtilities.valueFromBodyURI('action') # '1'
-    # 4 different values for token_v found in response, using the first one.
-    self.token_v = \
-      httpUtilities.valueFromBodyURI('v') # 'c'
-    self.token_c = \
-      httpUtilities.valueFromBodyURI('c') # '1'
-    # 2 different values for token_f found in response, using the first one.
-    self.token_f = \
-      httpUtilities.valueFromBodyURI('f') # '1'
-    self.token_p = \
-      httpUtilities.valueFromBodyURI('p') # '14'
-    self.token__id10jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id10jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
-    self.token_jsf_tree_64 = \
-      httpUtilities.valueFromHiddenInput('jsf_tree_64') # 'rO0ABXNyAEdvcmcuYXBhY2hlLm15ZmFjZXMuYXBw...'
-    self.token_jsf_viewid = \
-      httpUtilities.valueFromHiddenInput('jsf_viewid') # '/views/index.xhtml'
 
     return result
 
-  def page2(self):
+  def page2(self, forum_id):
     """GET JBossForumsWindow (post_requests 201-206)."""
-    self.token_v = \
-      'f'
-    
+
     # Expecting 302 'Moved Temporarily'
-    result = post_request201.GET('/portal/portal/default/forums/JBossForumsWindow;jsessionid=' +
-      self.token_jsessionid +
-      '?action=' +
-      self.token_action +
-      '&v=' +
-      self.token_v +
-      '&f=' +
-      self.token_f)
-    self.token_action = \
-      httpUtilities.valueFromLocationURI('action') # '2'
+    post_request201.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=1' +
+      '&v=f' +
+      '&f=' + forum_id)
 
-    grinder.sleep(11)
-    post_request202.GET('/portal/portal/default/forums/JBossForumsWindow' +
-      '?action=' +
-      self.token_action +
-      '&f=' +
-      self.token_f +
-      '&v=' +
-      self.token_v)
-    # 1 different values for token_windowstate found in response; the first matched
-    # the last known value of token_windowstate - don't update the variable.
-    self.token_action = \
-      httpUtilities.valueFromBodyURI('action') # '1'
-    # 38 different values for token_v found in response, using the first one.
-    self.token_v = \
-      httpUtilities.valueFromBodyURI('v') # 'c'
-    self.token_page = \
-      httpUtilities.valueFromBodyURI('page') # '1'
-    # 19 different values for token_t found in response, using the first one.
-    self.token_t = \
-      httpUtilities.valueFromBodyURI('t') # '3'
-    # 9 different values for token_p found in response; the first matched
-    # the last known value of token_p - don't update the variable.
-    self.token__id9jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id9jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
-    self.token_jsf_viewid = \
-      httpUtilities.valueFromHiddenInput('jsf_viewid') # '/views/forums/viewforum_body.xhtml'
+    result = post_request202.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=2' +
+      '&f=' + forum_id +
+      '&v=f')
 
     post_request203.GET('/portal-forums/subSilver/images/folder_new_hot.gif')
 
@@ -178,95 +133,39 @@
 
     return result
 
-  def page3(self):
+  def page3(self, forum_id, page_id):
     """GET JBossForumsWindow (post_requests 301-303)."""
-    self.token_v = \
-      'f'
-    
+  
     # Expecting 302 'Moved Temporarily'
-    result = post_request301.GET('/portal/portal/default/forums/JBossForumsWindow' +
-      '?action=' +
-      self.token_action +
-      '&v=' +
-      self.token_v +
-      '&f=' +
-      self.token_f +
-      '&page=' +
-      self.token_page)
-    self.token_action = \
-      httpUtilities.valueFromLocationURI('action') # '2'
+    post_request301.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=1' +
+      '&v=f' +
+      '&f=' + forum_id +
+      '&page=' + str(page_id))
 
-    post_request302.GET('/portal/portal/default/forums/JBossForumsWindow' +
-      '?action=' +
-      self.token_action +
-      '&f=' +
-      self.token_f +
-      '&page=' +
-      self.token_page +
-      '&v=' +
-      self.token_v)
-    # 1 different values for token_windowstate found in response; the first matched
-    # the last known value of token_windowstate - don't update the variable.
-    self.token_action = \
-      httpUtilities.valueFromBodyURI('action') # '1'
-    # 14 different values for token_v found in response, using the first one.
-    self.token_v = \
-      httpUtilities.valueFromBodyURI('v') # 'c'
-    self.token_page = \
-      httpUtilities.valueFromBodyURI('page') # '0'
-    # 3 different values for token_t found in response, using the first one.
-    self.token_t = \
-      httpUtilities.valueFromBodyURI('t') # '4'
-    # 2 different values for token_p found in response, using the first one.
-    self.token_p = \
-      httpUtilities.valueFromBodyURI('p') # '4'
+    result = post_request302.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=2' +
+      '&f=' + forum_id +
+      '&page=' + str(page_id) +
+      '&v=f')
 
     post_request303.GET('/portal-forums/subSilver/images/folder_announce.gif')
 
     return result
 
-  def page4(self):
+  def page4(self, forum_id, topic_id):
     """GET JBossForumsWindow (post_requests 401-406)."""
-    self.token_v = \
-      't'
     
     # Expecting 302 'Moved Temporarily'
-    result = post_request401.GET('/portal/portal/default/forums/JBossForumsWindow' +
-      '?action=' +
-      self.token_action +
-      '&v=' +
-      self.token_v +
-      '&t=' +
-      self.token_t)
-    self.token_action = \
-      httpUtilities.valueFromLocationURI('action') # '2'
+    post_request401.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=1' +
+      '&v=t' +
+      '&t=' + topic_id)
 
-    post_request402.GET('/portal/portal/default/forums/JBossForumsWindow' +
-      '?action=' +
-      self.token_action +
-      '&t=' +
-      self.token_t +
-      '&v=' +
-      self.token_v)
-    # 1 different values for token_windowstate found in response; the first matched
-    # the last known value of token_windowstate - don't update the variable.
-    self.token_action = \
-      httpUtilities.valueFromBodyURI('action') # '1'
-    # 8 different values for token_v found in response, using the first one.
-    self.token_v = \
-      httpUtilities.valueFromBodyURI('v') # 'c'
-    self.token_uid = \
-      httpUtilities.valueFromBodyURI('uid') # '1'
-    self.token__id15jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id15jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
-    self.token_jsf_viewid = \
-      httpUtilities.valueFromHiddenInput('jsf_viewid') # '/views/topics/viewtopic_body.xhtml'
-    self.token__id42jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id42jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
-    self.token_jsf_tree_64 = \
-      httpUtilities.valueFromHiddenInput('jsf_tree_64') # 'rO0ABXNyAEdvcmcuYXBhY2hlLm15ZmFjZXMuYXBw...'
-    self.token__id60jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT = \
-      httpUtilities.valueFromHiddenInput('_id60jbpns_2fdefault_2fforums_2fJBossForumsWindowsnpbj_SUBMIT') # '1'
+    result = post_request402.GET('/portal/portal/default/forums/JBossForumsWindow' +
+      '?action=2' +
+      '&t=' + topic_id +
+      '&v=t')
 
     post_request403.GET('/portal-core/themes/renaissance/images/favicon.ico')
 
@@ -278,15 +177,32 @@
 
     return result
 
-  def all(self):
-    self.page1()      # GET forums (post_request 101)
-    self.page2()      # GET JBossForumsWindow (post_requests 201-206)
-    self.page3()      # GET JBossForumsWindow (post_requests 301-303)
-    self.page4()      # GET JBossForumsWindow (post_requests 401-406)
+  def all(self, forum_id):
+    # Getting the main forums page
+    self.page1()   
+       
+    # Entering the selected forum
+    result = self.page2(forum_id)
+    
+    # Browsing the pages a random number of times (from 0 to 4) and until next pages exist
+    next_page_clicks = random.randint(0, next_clicks_range)
+    print next_page_clicks
+    for i in range(1, next_page_clicks):
+        if page_id_regexp.search(result.text) == None:
+            break
+        
+        result = self.page3(forum_id, i)
 
-  def __call__(self):
+    # Getting topic numbers
+    self.topic_ids = topic_id_regexp.findall(result.text)
+    
+    # Getting a random topic
+    topic_id = random.choice(self.topic_ids)
+    self.page4(forum_id, topic_id)
+
+  def __call__(self, forum_id):
     """This method is called for every run performed by the worker thread."""
-    all()
+    self.all(forum_id)
 
 def instrumentMethod(test, method_name, c=ViewPost):
   """Instrument a method with the given Test."""




More information about the jboss-svn-commits mailing list