[Webtest] Re: testing JSON web services

Soula, William Soula, William" <wsoula@pointserve.com
Wed, 10 Sep 2008 06:56:46 -0500


--_000_93B3B6122B906D44BC7E8B8CEFB0DBBB18451F2756SGPEXCHANGEpo_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Have you tried using ant's <sql> task?  I run webtest through ant but I bel=
ieve this should also work if you use the bat files?  I created a macro whe=
re I can pass in the connection info and sql to run, I've included it below=
 as an example, if you want to run an actual file you just set the src attr=
ibute of the <sql> task http://ant.apache.org/manual/CoreTasks/sql.html:
<macrodef name=3D"runSQL">
  <attribute name=3D"server"/>
  <attribute name=3D"database"/>
  <attribute name=3D"sql" default=3D""/>
  <attribute name=3D"login"/>
  <attribute name=3D"DBpassword"/>
  <sequential>
   <sql
      driver=3D"net.sourceforge.jtds.jdbc.Driver"
      url=3D"jdbc:jtds:sqlserver://@{server}/@{database}:1433"
      userid=3D"@{login}"
      password=3D"@{DBpassword}"
     >
     <classpath>
      <pathelement location=3D"../lib/jtds.jar"/>
     </classpath>
     @{sql}
    </sql>
    </sequential>
   </macrodef>

Hope this helps,
Will

________________________________
From: webtest-admin@lists.canoo.com [mailto:webtest-admin@lists.canoo.com] =
On Behalf Of Tokutan
Sent: Tuesday, September 09, 2008 6:28 PM
To: webtest@lists.canoo.com
Subject: [Webtest] Re: testing JSON web services

Hi Marc,

Thanks for replying. From what i have gathered, Web services is a rest-base=
d and outputting JSON as the expected output. I have played around with web=
test with invoke contentfile and Webtest does recognise the output. However=
, at the moment management is more inclined to use JMETER for this purpose =
as we need to connect to mysql via JDBC in order to clean up the database p=
rior to running the test. I find JMETER to be really basic in terms of func=
tional web testing as it is more towards performance testing

I need to present to the management the benefit of using Webtest for this w=
eb services testing. I have managed to use SQLunit to connect mysql via JDB=
C , however I have not figured out how to incorporate SQLUnit inside webtes=
t script (I have just managed to run SQL unit individually by telling it to=
 output webtest report by this command:ant sqlunit-nested canoo2html -Dtest=
dir=3Dtestwedi -Dlog.format=3Dcanoo -Doutput.file=3Dresults.xml -Dwebtest.s=
tyle=3DWebTestReport

Lets say I have the following simple webtest script:

<!DOCTYPE project SYSTEM "../dtd/Project.dtd">

<project default=3D"test">


    <target name=3D"test">


        <dataDriven tableContainer=3D"testsip.xls" table=3D"testjson">


        <webtest name=3D"check soap">
        <config haltonerror=3D"false" haltonfailure=3D"false"  >

         <option name=3D"ThrowExceptionOnScriptError"
        value=3D"false"
        />
              <option name=3D"ThrowExceptionOnFailingStatusCode"
        value=3D"false"
        />
        <header name=3D"User-Agent" value=3D"Mozilla/5.0 (Windows; U; Windo=
ws NT 5.1; en-US; rv:1.8.1.14<http://1.8.1.14>) Gecko/20080404 Firefox/2.0.=
0.14<http://2.0.0.14>"/>

     </config>




   <invoke method=3D"GET" url=3D"${URL}"/>

     <applyFilters>

        <matchLinesFilter regex=3D"\d"/>
        </applyFilters>


          <verifyContent referenceFile=3D"json.html"/>


</webtest>
</dataDriven>
</target>
</project>

And I have the following simple SQLunit script:

  <test name=3D"Checking returned value from customer"
          failure-message=3D"Returned value check for customer failed">
    <sql>
      <stmt>SELECT category_alias_name FROM Fads_ForQARnD.category_alias_to=
_c1_category_mappings where category_alias_name =3D'Banking'</stmt>

    </sql>
    <result>
      <resultset id=3D"1">
        <row id=3D"1">
          <col id=3D"1" name=3D"category_alias_name" type=3D"VARCHAR">Banki=
ng</col>
        </row>
      </resultset>
    </result>

How can i incorporate SQLunit script inside webtest script so webtest will =
run SQLunit script firstly and then running subsequent webtest script?

Thanks
  </test>

--_000_93B3B6122B906D44BC7E8B8CEFB0DBBB18451F2756SGPEXCHANGEpo_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.6000.16705" name=3DGENERATOR></HEAD>
<BODY>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D834155311-10092008><FONT face=3DA=
rial=20
color=3D#0000ff size=3D2>Have you tried using ant's &lt;sql&gt; task?&nbsp;=
 I run=20
webtest through ant but I believe this should also work if you use the bat=
=20
files?&nbsp; I created a macro where I can pass in the connection info and =
sql=20
to run, I've included it below as an example, if you want to run an actual =
file=20
you just set the src attribute of the &lt;sql&gt; task <A=20
href=3D"http://ant.apache.org/manual/CoreTasks/sql.html">http://ant.apache.=
org/manual/CoreTasks/sql.html</A>:</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D834155311-10092008><FONT face=3DA=
rial=20
color=3D#0000ff size=3D2>&lt;macrodef name=3D"runSQL"&gt;<BR>&nbsp;&nbsp;&l=
t;attribute=20
name=3D"server"/&gt;<BR>&nbsp;&nbsp;&lt;attribute=20
name=3D"database"/&gt;<BR>&nbsp;&nbsp;&lt;attribute name=3D"sql"=20
default=3D""/&gt;<BR>&nbsp;&nbsp;&lt;attribute=20
name=3D"login"/&gt;<BR>&nbsp;&nbsp;&lt;attribute=20
name=3D"DBpassword"/&gt;<BR>&nbsp;&nbsp;&lt;sequential&gt;<BR>&nbsp;&nbsp;&=
nbsp;&lt;sql<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;driver=3D"net.sourceforge.jtds.jdbc.Driver"<BR>&nbsp;&nbsp;&nbsp;&nbs=
p;=20
&nbsp;url=3D"jdbc:jtds:sqlserver://@{server}/@{database}:1433"<BR>&nbsp;&nb=
sp;&nbsp;&nbsp;=20
&nbsp;userid=3D"@{login}"<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;password=3D"@{DBpassword}"<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&lt;classpath&gt;<BR>&nbsp;&nbsp;&nb=
sp;=20
&nbsp;&nbsp;&lt;pathelement=20
location=3D"../lib/jtds.jar"/&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&lt;/classpath&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;@{sql}<BR>&nbsp;&nbsp;&nbsp; &lt;/sql&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;/sequential&gt;<BR>&nbsp;&nbsp; &lt;/macrodef&gt;</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D834155311-10092008><FONT face=3DA=
rial=20
color=3D#0000ff size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D834155311-10092008><FONT face=3DA=
rial=20
color=3D#0000ff size=3D2>Hope this helps,</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D834155311-10092008><FONT face=3DA=
rial=20
color=3D#0000ff size=3D2>Will</FONT></SPAN></DIV><BR>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dleft>
<HR tabIndex=3D-1>
<FONT face=3DTahoma size=3D2><B>From:</B> webtest-admin@lists.canoo.com=20
[mailto:webtest-admin@lists.canoo.com] <B>On Behalf Of=20
</B>Tokutan<BR><B>Sent:</B> Tuesday, September 09, 2008 6:28 PM<BR><B>To:</=
B>=20
webtest@lists.canoo.com<BR><B>Subject:</B> [Webtest] Re: testing JSON web=20
services<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=3Dltr>Hi Marc,<BR><BR>Thanks for replying. From what i have gather=
ed, Web=20
services is a rest-based and outputting JSON as the expected output. I have=
=20
played around with webtest with invoke contentfile and Webtest does recogni=
se=20
the output. However, at the moment management is more inclined to use JMETE=
R for=20
this purpose as we need to connect to mysql via JDBC in order to clean up t=
he=20
database prior to running the test. I find JMETER to be really basic in ter=
ms of=20
functional web testing as it is more towards performance testing<BR><BR>I n=
eed=20
to present to the management the benefit of using Webtest for this web serv=
ices=20
testing. I have managed to use SQLunit to connect mysql via JDBC , however =
I=20
have not figured out how to incorporate SQLUnit inside webtest script (I ha=
ve=20
just managed to run SQL unit individually by telling it to output webtest r=
eport=20
by this command:ant sqlunit-nested canoo2html -Dtestdir=3Dtestwedi=20
-Dlog.format=3Dcanoo -Doutput.file=3Dresults.xml -Dwebtest.style=3DWebTestR=
eport=20
<BR><BR>Lets say I have the following simple webtest script:<BR><BR>&lt;!DO=
CTYPE=20
project SYSTEM "../dtd/Project.dtd"&gt;<BR><BR>&lt;project=20
default=3D"test"&gt;<BR><BR><BR>&nbsp;&nbsp;&nbsp; &lt;target=20
name=3D"test"&gt;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;dataDriven=20
tableContainer=3D"testsip.xls" table=3D"testjson"&gt;<BR>&nbsp;&nbsp;&nbsp;=
=20
&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;webtest name=3D"check=20
soap"&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;config=20
haltonerror=3D"false" haltonfailure=3D"false"&nbsp; &gt;<BR><BR>&nbsp;&nbsp=
;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&lt;option=20
name=3D"ThrowExceptionOnScriptError"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p;=20
value=3D"false"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
/&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;=20
&lt;option name=3D"ThrowExceptionOnFailingStatusCode"<BR>&nbsp;&nbsp;&nbsp;=
=20
&nbsp;&nbsp;&nbsp; value=3D"false"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
=20
/&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;header name=3D"User-Agen=
t"=20
value=3D"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:<A=20
href=3D"http://1.8.1.14">1.8.1.14</A>) Gecko/20080404 Firefox/<A=20
href=3D"http://2.0.0.14">2.0.0.14</A>"/&gt; <BR><BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&lt;/config&gt;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; &lt;invoke=20
method=3D"GET" url=3D"${URL}"/&gt;<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;applyFilters&gt;<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;matchLinesFilter=20
regex=3D"\d"/&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/applyFilters&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
<BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &lt;verifyContent=20
referenceFile=3D"json.html"/&gt; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;=20
<BR><BR>&lt;/webtest&gt;<BR>&lt;/dataDriven&gt;<BR>&lt;/target&gt;<BR>&lt;/=
project&gt;<BR><BR>And=20
I have the following simple SQLunit script:<BR><BR>&nbsp; &lt;test=20
name=3D"Checking returned value from=20
customer"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
failure-message=3D"Returned value check for customer=20
failed"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;sql&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
&lt;stmt&gt;SELECT category_alias_name FROM=20
Fads_ForQARnD.category_alias_to_c1_category_mappings where category_alias_n=
ame=20
=3D'Banking'&lt;/stmt&gt;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
&lt;/sql&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;result&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;resultset=20
id=3D"1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;row=20
id=3D"1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;=
col=20
id=3D"1" name=3D"category_alias_name"=20
type=3D"VARCHAR"&gt;Banking&lt;/col&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
&lt;/row&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/resultset&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/result&gt;<BR><BR>How can i=20
incorporate SQLunit script inside webtest script so webtest will run SQLuni=
t=20
script firstly and then running subsequent webtest=20
script?<BR><BR>Thanks<BR>&nbsp; &lt;/test&gt;<BR></DIV></BODY></HTML>

--_000_93B3B6122B906D44BC7E8B8CEFB0DBBB18451F2756SGPEXCHANGEpo_--