Sunday 15 July 2012

How can I pass a variable from ant to a java file -



How can I pass a variable from ant to a java file -

i have test cases in ant , each 1 of them pings url, have java class doing work of pinging url , taking care of things need test case , compiling , running java class ant build file.

the url different test cases want pass url ant file java class having problem doing that, have suggestions how can pass variable ant java class. right passing url in java file 1 test case don't want create different java files test cases different url each time.

this testcase 1 target calls ping target:

<target name="01"> <description> @testlogic.group type="category" values="mats" incremental response info stress test, multi-thread model </description> <antcall target="pingohsjava"> <param name="out.log" value="tiapwt01.log"/> <param name="ohs.name" value="ohs1"/> <param name="url" value="/waiter/servlet/servletstressmulti?mode=1"/> <param name="para1" value="1"/> <param name="para2" value="10"/> <param name="para3" value="100"/> <param name="para4" value="10"/> </antcall> <fail message="test failed found.. failing"> <condition> <resourcecontains resource="${tiapwt.base.dir}/common/output/tiapwt_content.txt" substring="failed"/> </condition> </fail> </target>

this ping target:

<target name="pingohsjava"> <property name="srcdir" location="${functional.base.dir}/tiapwt/common/java" /> <path id="classpath.test"> <pathelement location="/scratch/skaneria/dwnld/junit-4.10.jar" /> </path> <property name="lib.dir" value="../common/jars" /> <taskdef resource="org/testlogic/toolkit/asserts/antlib.xml"> <classpath> <fileset dir="${lib.dir}" includes="tlt-asserts-0.3.jar" /> </classpath> </taskdef> <delete verbose="true"> <fileset dir="${srcdir}" includes="**/*.class" /> </delete> <property name="urlping" value="http://${admin_host}:${apache_port}${url}"/> <trycatch property="pingoutput"> <try> <javac srcdir="${srcdir}" destdir="${srcdir}"> <classpath refid="classpath.test"/> </javac> <java classname="httpurlconnectionexample" fork="true" failonerror="true"> <classpath path="${srcdir}"/> </java> </try> <finally> <echo file="${twork.dir}/${out.log}" append="false"> url: ${urlping} parameter 1 : mode=${para1} parameter 2 : iterations=${para2} parameter 3 : initial=${para3} parameter 4 : increment=${para4} ------------------------------------------ ${pingoutput} </echo> </finally> </trycatch> </target>

and snippet java class uses url:

private void sendget() throws exception { string url = "http://slc06mwj.us.oracle.com:7777/waiter/servlet/servletstressmulti?mode=1&iterations=10&initial=100&increment=10000"; url obj = new url(url); httpurlconnection con = (httpurlconnection) obj.openconnection(); // optional default con.setrequestmethod("get"); //add request header con.setrequestproperty("user-agent", user_agent); try{ int responsecode = con.getresponsecode(); system.out.println("\nsending 'get' request url : " + url); system.out.println("response code : " + responsecode); system.out.println("response message : " + con.getresponsemessage()); } catch(exception e){ system.out.println("error"); }

java ant parameter-passing

No comments:

Post a Comment