# The Grinder 3.2
# HTTP script recorded by TCPProxy at Feb 20, 2009 6:33:57 PM

#from net.grinder.script import Test
from net.grinder.script import Test as StandardTest

def Test(number, description):
    # Adjust to the appropriate offset.
    TEST_NUMBER_OFFSET = 20000
    return StandardTest(number + TEST_NUMBER_OFFSET, description)

from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
from HTTPClient import NVPair
connectionDefaults = HTTPPluginControl.getConnectionDefaults()
httpUtilities = HTTPPluginControl.getHTTPUtilities()

import grinder_common as gc

# To use a proxy server, uncomment the next line and set the host and port.
# connectionDefaults.setProxyServer("localhost", 8001)

# These definitions at the top level of the file are evaluated once,
# when the worker process is started.

connectionDefaults.defaultHeaders = \
  ( NVPair('Accept-Language', 'en-us,en;q=0.5'),
    NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
    NVPair('Accept-Encoding', 'gzip,deflate'),
    NVPair('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6'), )

headers0= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'), )

headers1= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/login.jsp'), )

headers2= \
  ( NVPair('Accept', '*/*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/dashboard'), )

headers3= \
  ( NVPair('Accept', 'text/javascript, text/html, application/xml, text/xml, */*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/dashboard'),
    NVPair('Cache-Control', 'no-cache'), )

headers4= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/dashboard'), )

headers5= \
  ( NVPair('Accept', '*/*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case?caseNumber=09RCT011660'), )

headers6= \
  ( NVPair('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5'),
    NVPair('Referer', 'http://localhost:8080/sustain/menus/tree.css'), )

headers7= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case?caseNumber=09RCT011660'), )

headers8= \
  ( NVPair('Accept', '*/*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case?id=17999&caseId=17999&formId=113'), )

headers9= \
  ( NVPair('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5'),
    NVPair('Referer', 'http://localhost:8080/sustain/common/css/base.css'), )

headers10= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case?id=17999&caseId=17999&formId=113'), )

headers11= \
  ( NVPair('Accept', '*/*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case/insert?parentId=17999&parentEntity=com.sustain.cases.model.Party&caseId=17999&parentField=warrants&formCode=IN-Warrant'), )

headers12= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case/insert?parentId=17999&parentEntity=com.sustain.cases.model.Party&caseId=17999&parentField=warrants&formCode=IN-Warrant'), )

headers13= \
  ( NVPair('Accept', '*/*'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/case?id=17999&formId=113&caseId=17999'), )

url0 = 'http://localhost:8080'

# Create an HTTPRequest for each request, then replace the
# reference to the HTTPRequest with an instrumented version.
# You can access the unadorned instance using request101.__target__.
# open home page
request101 = HTTPRequest(url=url0, headers=headers0)
request101 = Test(101, 'GET /').wrap(request101)

request102 = HTTPRequest(url=url0, headers=headers0)
request102 = Test(102, 'GET dashboard').wrap(request102)

request103 = HTTPRequest(url=url0, headers=headers0)
request103 = Test(103, 'GET login.jsp').wrap(request103)

# login
request201 = HTTPRequest(url=url0, headers=headers1)
request201 = Test(201, 'GET j_security_check').wrap(request201)

request202 = HTTPRequest(url=url0, headers=headers1)
request202 = Test(202, 'GET dashboard').wrap(request202)

request203 = HTTPRequest(url=url0, headers=headers2)
request203 = Test(203, 'GET engine.js').wrap(request203)

request204 = HTTPRequest(url=url0, headers=headers2)
request204 = Test(204, 'GET userNoteManagerAjax.js').wrap(request204)

request301 = HTTPRequest(url=url0, headers=headers3)
request301 = Test(301, 'POST history').wrap(request301)

# open case 09RCT011660
request401 = HTTPRequest(url=url0, headers=headers4)
request401 = Test(401, 'POST navigation').wrap(request401)

request402 = HTTPRequest(url=url0, headers=headers4)
request402 = Test(402, 'GET case').wrap(request402)

request403 = HTTPRequest(url=url0, headers=headers5)
request403 = Test(403, 'GET engine.js').wrap(request403)

request404 = HTTPRequest(url=url0, headers=headers5)
request404 = Test(404, 'GET userNoteManagerAjax.js').wrap(request404)

request501 = HTTPRequest(url=url0, headers=headers5)
request501 = Test(501, 'GET forms_js.jsp').wrap(request501)

request601 = HTTPRequest(url=url0, headers=headers5)
request601 = Test(601, 'GET citystateupdate_js.jsp').wrap(request601)

# open warrants/Bail tab
request701 = HTTPRequest(url=url0, headers=headers7)
request701 = Test(701, 'GET case').wrap(request701)

request702 = HTTPRequest(url=url0, headers=headers8)
request702 = Test(702, 'GET engine.js').wrap(request702)

request703 = HTTPRequest(url=url0, headers=headers8)
request703 = Test(703, 'GET userNoteManagerAjax.js').wrap(request703)

request801 = HTTPRequest(url=url0, headers=headers8)
request801 = Test(801, 'GET forms_js.jsp').wrap(request801)

request901 = HTTPRequest(url=url0, headers=headers8)
request901 = Test(901, 'GET citystateupdate_js.jsp').wrap(request901)

request902 = HTTPRequest(url=url0, headers=headers9)
request902 = Test(902, 'GET cti-view-person.gif').wrap(request902)

# seelct defendent bullet under warrants
# open new warrant page
request1001 = HTTPRequest(url=url0, headers=headers10)
request1001 = Test(1001, 'GET insert').wrap(request1001)

request1002 = HTTPRequest(url=url0, headers=headers11)
request1002 = Test(1002, 'GET engine.js').wrap(request1002)

request1003 = HTTPRequest(url=url0, headers=headers11)
request1003 = Test(1003, 'GET userNoteManagerAjax.js').wrap(request1003)

request1101 = HTTPRequest(url=url0, headers=headers11)
request1101 = Test(1101, 'GET forms_js.jsp').wrap(request1101)

request1201 = HTTPRequest(url=url0, headers=headers11)
request1201 = Test(1201, 'GET citystateupdate_js.jsp').wrap(request1201)

# submit warrant save & back
request1301 = HTTPRequest(url=url0, headers=headers12)
request1301 = Test(1301, 'POST insert').wrap(request1301)

request1302 = HTTPRequest(url=url0, headers=headers12)
request1302 = Test(1302, 'GET case').wrap(request1302)

request1303 = HTTPRequest(url=url0, headers=headers13)
request1303 = Test(1303, 'GET engine.js').wrap(request1303)

request1304 = HTTPRequest(url=url0, headers=headers13)
request1304 = Test(1304, 'GET userNoteManagerAjax.js').wrap(request1304)

request1401 = HTTPRequest(url=url0, headers=headers13)
request1401 = Test(1401, 'GET forms_js.jsp').wrap(request1401)

request1501 = HTTPRequest(url=url0, headers=headers13)
request1501 = Test(1501, 'GET citystateupdate_js.jsp').wrap(request1501)

headersLogout= \
  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', 'http://localhost:8080/sustain/cms/dashboard'), )

requestLogout = HTTPRequest(url=url0, headers=headersLogout)
requestLogout = Test(1, 'GET j_sustain_logout').wrap(requestLogout)


class TestRunner:
  """A TestRunner instance is created for each worker thread."""

  # A method for each recorded page.
  def page1(self):
    """GET / (requests 101-103)."""
    
    # Expecting 302 'Moved Temporarily'
    result = request101.GET('/sustain/')

    grinder.sleep(10)
    
    # Expecting 302 'Moved Temporarily'
    request102.GET('/sustain/cms/dashboard')

    request103.GET('/sustain/login.jsp')

    return result

  def page2(self):
    """GET j_security_check (requests 201-204)."""
    self.token_j_username = \
      self.user_data['UserName'] # 'admin'
    self.token_j_password = \
      self.user_data['Password'] # 'pass'
    self.token_btnSubmit = \
      '++Login++'
    
    # Expecting 302 'Moved Temporarily'
    result = request201.GET('/sustain/j_security_check' +
      '?j_username=' +
      self.token_j_username +
      '&j_password=' +
      self.token_j_password +
      '&btnSubmit=' +
      self.token_btnSubmit)

    request202.GET('/sustain/cms/dashboard')
    #self.token_dispatch = \
    #  httpUtilities.valueFromBodyURI('dispatch') # 'onView'
    self.token_orgapachestrutstaglibhtmlTOKEN = \
      httpUtilities.valueFromHiddenInput('org.apache.struts.taglib.html.TOKEN') # '11a8673bd31e4c9dabdbd467340e9c7c'

    grinder.sleep(10)
    request203.GET('/sustain/dwr/engine.js', None,
      ( NVPair('If-Modified-Since', 'Thu, 19 Feb 2009 01:16:08 GMT'),
        NVPair('If-None-Match', '\"1235006168000\"'), ))

    grinder.sleep(10)
    request204.GET('/sustain/dwr/interface/userNoteManagerAjax.js')

    return result

  def page3(self):
    """POST history (request 301)."""
    self.token_dispatch = \
      'portlet'
    self.token_max = \
      '10'
    result = request301.POST('/sustain/cms/case/history' +
      '?dispatch=' +
      self.token_dispatch +
      '&max=' +
      self.token_max,
      '',
      ( NVPair('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'), ))
    # 5 different values for token_caseId found in response, using the first one.
    #self.token_caseId = \
    #  httpUtilities.valueFromBodyURI('caseId') # '17999'

    return result

  def page4(self):
    """POST navigation (requests 401-405)."""
    
    # Expecting 302 'Moved Temporarily'
    result = request401.POST('/sustain/cms/user/navigation',
      ( NVPair('org.apache.struts.taglib.html.TOKEN', self.token_orgapachestrutstaglibhtmlTOKEN),
        NVPair('cmd', self.case_charge_party_data['CaseNumber']), ),
      ( NVPair('Content-Type', 'application/x-www-form-urlencoded'), ))
    #self.token_caseNumber = \
    #  httpUtilities.valueFromLocationURI('caseNumber') # '09RCT011660'
    self.token_caseNumber = self.case_charge_party_data['CaseNumber']

    grinder.sleep(10)
    request402.GET('/sustain/cms/case' +
      '?caseNumber=' +
      self.token_caseNumber)
    # 3 different values for token_dispatch found in response, using the first one.
    #self.token_dispatch = \
    #  httpUtilities.valueFromBodyURI('dispatch') # 'onView'
    self.token_xrefClass = \
      httpUtilities.valueFromBodyURI('xrefClass') # 'com.sustain.cases.model.Case'
    self.token_xrefId = \
      httpUtilities.valueFromBodyURI('xrefId') # '17999'
    self.token_subject = \
      httpUtilities.valueFromBodyURI('subject') # '09RCT011660'
    self.token_body = \
      httpUtilities.valueFromBodyURI('body') # '/sustain/cms/case?caseId=17999'
    # 4 different values for token_id found in response, using the first one.
    #self.token_id = \
    #  httpUtilities.valueFromBodyURI('id') # '17999'
    # 14 different values for token_formId found in response, using the first one.
    #self.token_formId = \
    #  httpUtilities.valueFromBodyURI('formId') # '105'
    self.token_orgapachestrutstaglibhtmlTOKEN = \
      httpUtilities.valueFromHiddenInput('org.apache.struts.taglib.html.TOKEN') # '40ba78428b04764533643f03aaedbc46'

    grinder.sleep(10)
    request403.GET('/sustain/dwr/engine.js', None,
      ( NVPair('If-Modified-Since', 'Thu, 19 Feb 2009 01:16:08 GMT'),
        NVPair('If-None-Match', '\"1235006168000\"'), ))

    grinder.sleep(10)
    request404.GET('/sustain/dwr/interface/userNoteManagerAjax.js')

    return result

  def page5(self):
    """GET forms_js.jsp (request 501)."""
    result = request501.GET('/sustain/common/forms_js.jsp')

    return result

  def page6(self):
    """GET citystateupdate_js.jsp (request 601)."""
    result = request601.GET('/sustain/system/js/citystateupdate_js.jsp')

    return result

  def page7(self):
    """GET case (requests 701-704)."""
    self.token_formId = \
      '113'
    result = request701.GET('/sustain/cms/case' +
      '?id=' +
      self.case_charge_party_data['CaseId'] + 
      '&caseId=' +
      self.case_charge_party_data['CaseId'] + 
      '&formId=' +
      self.token_formId)
    # 2 different values for token_dispatch found in response; the first matched
    # the last known value of token_dispatch - don't update the variable.
    # 21 different values for token_formId found in response, using the first one.
    #self.token_formId = \
    #  httpUtilities.valueFromBodyURI('formId') # '105'
    self.token_orgapachestrutstaglibhtmlTOKEN = \
      httpUtilities.valueFromHiddenInput('org.apache.struts.taglib.html.TOKEN') # '7131164eae097c632492b6e0a5e2a95a'

    grinder.sleep(10)
    request702.GET('/sustain/dwr/engine.js', None,
      ( NVPair('If-Modified-Since', 'Thu, 19 Feb 2009 01:16:08 GMT'),
        NVPair('If-None-Match', '\"1235006168000\"'), ))

    grinder.sleep(10)
    request703.GET('/sustain/dwr/interface/userNoteManagerAjax.js')

    return result

  def page8(self):
    """GET forms_js.jsp (request 801)."""
    result = request801.GET('/sustain/common/forms_js.jsp')

    return result

  def page9(self):
    """GET citystateupdate_js.jsp (requests 901-902)."""
    result = request901.GET('/sustain/system/js/citystateupdate_js.jsp')

    grinder.sleep(10)
    request902.GET('/sustain/common/css/case/cti-view-person.gif', None,
      ( NVPair('If-Modified-Since', 'Wed, 18 Feb 2009 00:53:38 GMT'),
        NVPair('If-None-Match', 'W/\"558-1234918418078\"'), ))

    return result

  def page10(self):
    """GET insert (requests 1001-1004)."""
    self.token_parentId = \
      self.case_charge_party_data['PartyId']
    self.token_parentEntity = \
      'com.sustain.cases.model.Party'
    self.token_parentField = \
      'warrants'
    self.token_formCode = \
      'IN-Warrant'
    result = request1001.GET('/sustain/cms/case/insert' +
      '?parentId=' +
      self.token_parentId +
      '&parentEntity=' +
      self.token_parentEntity +
      '&caseId=' +
      self.case_charge_party_data['CaseId'] + 
      '&parentField=' +
      self.token_parentField +
      '&formCode=' +
      self.token_formCode)
    # 2 different values for token_dispatch found in response; the first matched
    # the last known value of token_dispatch - don't update the variable.
    # 10 different values for token_formId found in response; the first matched
    # the last known value of token_formId - don't update the variable.
    self.token_orgapachestrutstaglibhtmlTOKEN = \
      httpUtilities.valueFromHiddenInput('org.apache.struts.taglib.html.TOKEN') # '9748ca182b267a154c38ba655905010e'
    self.token_submitAction = \
      httpUtilities.valueFromHiddenInput('submitAction') # ''
    self.token_failOnWarnings = \
      httpUtilities.valueFromHiddenInput('failOnWarnings') # 'true'

    grinder.sleep(10)
    request1002.GET('/sustain/dwr/engine.js', None,
      ( NVPair('If-Modified-Since', 'Thu, 19 Feb 2009 01:16:08 GMT'),
        NVPair('If-None-Match', '\"1235006168000\"'), ))

    grinder.sleep(10)
    request1003.GET('/sustain/dwr/interface/userNoteManagerAjax.js')

    return result

  def page11(self):
    """GET forms_js.jsp (request 1101)."""
    result = request1101.GET('/sustain/common/forms_js.jsp')

    return result

  def page12(self):
    """GET citystateupdate_js.jsp (request 1201)."""
    result = request1201.GET('/sustain/system/js/citystateupdate_js.jsp')

    return result

  def page13(self):
    """POST insert (requests 1301-1305)."""
    self.token_dispatch = \
      'onInsert'
    self.token_submitAction = \
      'saveAndBack'
    
    # Expecting 302 'Moved Temporarily'
    result = request1301.POST('/sustain/cms/case/insert' +
      '?dispatch=' +
      self.token_dispatch,
      ( NVPair('org.apache.struts.taglib.html.TOKEN', self.token_orgapachestrutstaglibhtmlTOKEN),
        NVPair('formId', '59'),
        NVPair('parentId', self.token_parentId),
        NVPair('parentEntity', self.token_parentEntity),
        NVPair('parentField', self.token_parentField),
        NVPair('submitAction', self.token_submitAction),
        NVPair('failOnWarnings', self.token_failOnWarnings),
        NVPair('caseId', self.case_charge_party_data['CaseId']),
        NVPair('data(572)', '02/20/09'),
        NVPair('data(573)', '02/20/09'),
        NVPair('data(574)', self.warrant_data['WarrantType']),
        NVPair('data(575)', ''),
        NVPair('data(576)', ''),
        NVPair('data(577)', 'ACT'), ),
      ( NVPair('Content-Type', 'application/x-www-form-urlencoded'), ))
    self.token_formId = \
      httpUtilities.valueFromLocationURI('formId') # '113'

    grinder.sleep(10)
    request1302.GET('/sustain/cms/case' +
      '?id=' +
      self.case_charge_party_data['CaseId'] + 
      '&formId=' +
      self.token_formId +
      '&caseId=' +
      self.case_charge_party_data['CaseId'])
    # 3 different values for token_dispatch found in response, using the first one.
    self.token_dispatch = \
      httpUtilities.valueFromBodyURI('dispatch') # 'onView'
    # 3 different values for token_id found in response; the first matched
    # the last known value of token_id - don't update the variable.
    # 24 different values for token_formId found in response, using the first one.
    #self.token_formId = \
    #  httpUtilities.valueFromBodyURI('formId') # '105'
    self.token_orgapachestrutstaglibhtmlTOKEN = \
      httpUtilities.valueFromHiddenInput('org.apache.struts.taglib.html.TOKEN') # '93e5f58127303c4afa269d462e9402c4'

    grinder.sleep(10)
    request1303.GET('/sustain/dwr/engine.js', None,
      ( NVPair('If-Modified-Since', 'Thu, 19 Feb 2009 01:16:08 GMT'),
        NVPair('If-None-Match', '\"1235006168000\"'), ))

    grinder.sleep(10)
    request1304.GET('/sustain/dwr/interface/userNoteManagerAjax.js')

    return result

  def page14(self):
    """GET forms_js.jsp (request 1401)."""
    result = request1401.GET('/sustain/common/forms_js.jsp')

    return result

  def page15(self):
    """GET citystateupdate_js.jsp (request 1501)."""
    result = request1501.GET('/sustain/system/js/citystateupdate_js.jsp')

    return result

  def pageLogout(self):
    """GET j_sustain_logout (request 1)."""
    
    # Expecting 302 'Moved Temporarily'
    result = requestLogout.GET('/sustain/j_sustain_logout')
    requestLogout.GET('/sustain/login.jsp')

    return result

  def __call__(self):
    """This method is called for every run performed by the worker thread."""
    gc.setup_thread()
    self.user_data = gc.thread_user_data()
    self.case_charge_party_data = gc.read_pool_data('warrant_in')
    self.warrant_data = gc.read_thread_data('grinder_data_warrant')
    
    self.page1()      # GET / (requests 101-103)

    grinder.sleep(10)
    self.page2()      # GET j_security_check (requests 201-204)

    grinder.sleep(10)
    self.page3()      # POST history (request 301)

    grinder.sleep(10)
    self.page4()      # POST navigation (requests 401-405)
    self.page5()      # GET forms_js.jsp (request 501)

    grinder.sleep(10)
    self.page6()      # GET citystateupdate_js.jsp (request 601)

    grinder.sleep(10)
    self.page7()      # GET case (requests 701-704)
    self.page8()      # GET forms_js.jsp (request 801)

    grinder.sleep(10)
    self.page9()      # GET citystateupdate_js.jsp (requests 901-902)

    grinder.sleep(10)
    self.page10()     # GET insert (requests 1001-1004)
    self.page11()     # GET forms_js.jsp (request 1101)

    grinder.sleep(10)
    self.page12()     # GET citystateupdate_js.jsp (request 1201)

    grinder.sleep(10)
    self.page13()     # POST insert (requests 1301-1305)
    self.page14()     # GET forms_js.jsp (request 1401)

    grinder.sleep(10)
    self.page15()     # GET citystateupdate_js.jsp (request 1501)

    grinder.sleep(10)
    self.pageLogout()


def instrumentMethod(test, method_name, c=TestRunner):
  """Instrument a method with the given Test."""
  unadorned = getattr(c, method_name)
  import new
  method = new.instancemethod(test.wrap(unadorned), None, c)
  setattr(c, method_name, method)

# Replace each method with an instrumented version.
# You can call the unadorned method using self.page1.__target__().
instrumentMethod(Test(100, 'Page 1'), 'page1')
instrumentMethod(Test(200, 'Page 2'), 'page2')
instrumentMethod(Test(300, 'Page 3'), 'page3')
instrumentMethod(Test(400, 'Page 4'), 'page4')
instrumentMethod(Test(500, 'Page 5'), 'page5')
instrumentMethod(Test(600, 'Page 6'), 'page6')
instrumentMethod(Test(700, 'Page 7'), 'page7')
instrumentMethod(Test(800, 'Page 8'), 'page8')
instrumentMethod(Test(900, 'Page 9'), 'page9')
instrumentMethod(Test(1000, 'Page 10'), 'page10')
instrumentMethod(Test(1100, 'Page 11'), 'page11')
instrumentMethod(Test(1200, 'Page 12'), 'page12')
instrumentMethod(Test(1300, 'Page 13'), 'page13')
instrumentMethod(Test(1400, 'Page 14'), 'page14')
instrumentMethod(Test(1500, 'Page 15'), 'page15')
instrumentMethod(Test(9999, 'Page Logout'), 'pageLogout')
