Completed changes related running test scripts

This commit is contained in:
rpidikiti 2011-08-09 14:30:13 -07:00
parent 31a2ef5ddb
commit 8347fa3a37
11 changed files with 248 additions and 30 deletions

View File

@ -1,4 +1,11 @@
#!/bin/bash #!/bin/bash
if [ $# -ne 4 ]
then
echo "Error in $0 - Invalid Argument Count"
echo "Syntax: $0 location_of_service api_key package_name library_root"
exit
fi
echo "" > classpath.txt echo "" > classpath.txt
for file in `ls lib`; for file in `ls lib`;
do echo -n 'lib/' >> classpath.txt; do echo -n 'lib/' >> classpath.txt;
@ -12,5 +19,5 @@ for file in `ls build`;
done done
export CLASSPATH=$(cat classpath.txt):conf/java/templates export CLASSPATH=$(cat classpath.txt):conf/java/templates
export JAVA_OPTS="${JAVA_OPTS} -DrulePath=data -Dproperty=Xmx2g -DloggerPath=$BUILD_COMMON/test-config/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -Dproperty=Xmx2g"
java $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS $JAVA_OPTS -cp $CLASSPATH com.wordnik.swagger.codegen.config.java.JavaLibCodeGen "$@" java $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS $JAVA_OPTS -cp $CLASSPATH com.wordnik.swagger.codegen.config.java.JavaLibCodeGen "$@"

17
bin/runjavaTestCase.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "" > classpath.txt
for file in `ls lib`;
do echo -n 'lib/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done
for file in `ls build`;
do echo -n 'build/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done
#first argument to the command line script give location of the library jar file
export CLASSPATH=$(cat classpath.txt)$2
export JAVA_OPTS="${JAVA_OPTS} -DrulePath=data -Dproperty=Xmx2g -DloggerPath=$BUILD_COMMON/test-config/log4j.properties"
java $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS $JAVA_OPTS -cp $CLASSPATH "$@"

View File

@ -0,0 +1,22 @@
#!/bin/bash
if [ $# -ne 7 ]
then
echo "Error in $0 - Invalid Argument Count"
echo "Syntax: $0 location_of_client_library location_of_service api_key test_script_location test_data_location test_data_class_name api_classes_package_name"
exit
fi
echo "" > classpath.txt
for file in `ls lib`;
do echo -n 'lib/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done
for file in `ls build`;
do echo -n 'build/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done
export CLASSPATH=$(cat classpath.txt)$7
echo $CLASSPATH
export JAVA_OPTS="${JAVA_OPTS} -Dproperty=Xmx2g "
java $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS $JAVA_OPTS -cp $CLASSPATH com.wordnik.swagger.testframework.APITestRunner "$@" JAVA

111
conf/java/sample/build.xml Normal file
View File

@ -0,0 +1,111 @@
<?xml version="1.0"?>
<project name="swagger-sample-java-lib" xmlns:ivy="antlib:org.apache.ivy.ant" default="build.all" basedir=".">
<property environment="env" />
<property name="version.identifier" value="1.0" />
<property name="artifact.ext" value="jar" />
<property name="organization" value="wordnik" />
<property name="module" value="${ant.project.name}" />
<!-- default dirs for the build -->
<mkdir dir="lib"/>
<mkdir dir="lib/ext"/>
<condition property="scala.home" value="${env.SCALA_HOME}">
<isset property="env.SCALA_HOME" />
</condition>
<path id="scala.classpath">
<fileset dir="${scala.home}/lib">
<include name="scala**.jar" />
</fileset>
</path>
<ivy:settings file="ivysettings.xml" />
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<fileset dir="lib">
<include name="scala**.jar" />
</fileset>
<fileset dir="${scala.home}/lib">
<include name="scala**.jar" />
</fileset>
</classpath>
</taskdef>
<!-- this is the output module -->
<property name="module" value="${ant.project.name}" />
<target name="build.all" depends="clean, resolve, fastcompile" description="builds the module (default target)" />
<target name="clean" description="cleans the project folder">
<mkdir dir="build" />
<echo message="deleting build files" />
<delete quiet="true">
<fileset dir="build">
<include name="*.jar" />
<include name="*.xml" />
</fileset>
</delete>
<delete dir="build/main" quiet="true" />
<delete dir="dist" quiet="true" />
<!-- libraries handled by ivy -->
<echo message="deleting libs handled by ivy" />
<delete>
<fileset dir="lib">
<include name="*.jar" />
<include name="*.zip" />
</fileset>
</delete>
</target>
<!-- copies ONLY the swagger-sample jar to dist-->
<target name="fastdist" depends="fastcompile">
<copy todir="dist/lib">
<fileset dir="build">
<include name="*.jar" />
</fileset>
</copy>
</target>
<!-- copies all dependencies into the lib folder -->
<target name="resolve" description="retreive dependencies with ivy">
<ivy:retrieve pattern="${basedir}/lib/[artifact]-[revision].[ext]" conf="build" />
</target>
<target name="fastcompile" description="builds the module without artifact resolution or cleaning">
<delete quiet="true" file="build/${organization}-${artifact}-*.${artifact.ext}" />
<mkdir dir="build" />
<mkdir dir="build/main" />
<mkdir dir="build/main/java" />
<javac srcdir="src/main/java" debug="true" destdir="build/main/java">
<classpath>
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<fileset dir="lib/ext">
<include name="*.jar" />
</fileset>
<pathelement location="build/main/java" />
</classpath>
</javac>
<jar jarfile="build/${module}-${version.identifier}.${artifact.ext}">
<fileset dir="build/main/java" />
</jar>
</target>
<!-- cleans up the dist -->
<target name="dist.clean" description="cleans the distribution folder">
<delete quiet="true" dir="dist" />
<delete quiet="true" file="dist.zip" />
</target>
<target name="dependency.tree" description="builds a graphml dependency diagram for viewing with yEd">
<ivy:report conf="build" graph="true" todir="." outputpattern="[artifact]-[revision].[ext]" />
</target>
</project>

31
conf/java/sample/ivy.xml Normal file
View File

@ -0,0 +1,31 @@
<ivy-module version="2.0">
<info organisation="wordnik" module="sample-java-lib"/>
<configurations>
<conf name="build" description="build wordnik-java"/>
<conf name="test" visibility="public"/>
<conf name="source" visibility="public"/>
<conf name="pom" visibility="public"/>
</configurations>
<dependencies>
<!-- jersey dependencies -->
<dependency org="junit" name="junit" rev="4.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-json" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-client" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-server" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-core" rev="1.4" conf="build->default"/>
<dependency org="asm" name="asm-parent" rev="3.1" conf="build->default"/>
<dependency org="commons-beanutils" name="commons-beanutils" rev="1.8.0" conf="build->default"/>
<dependency org="org.antlr" name="stringtemplate" rev="3.2" conf="build->default"/>
<!-- jackson jars -->
<dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.7.1" conf="build->default"/>
<dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.7.1" conf="build->default"/>
<dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.7.1" conf="build->default"/>
<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.2" conf="test->default">
<exclude org="asm" name="asm-tree"/>
<exclude org="asm" name="asm"/>
</dependency>
</dependencies>
</ivy-module>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
<settings defaultResolver="chained" />
<property name="ivy.checksums" value=""/>
<property name="ivy.local.default.root" value="${ivy.default.ivy.user.dir}/local"
override="false" />
<property name="ivy.local.default.ivy.pattern"
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
override="false" />
<property name="ivy.local.default.artifact.pattern"
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
override="false" />
<resolvers>
<chain name="chained" returnFirst="true">
<filesystem name="local">
<ivy pattern="${ivy.local.default.root}/${ivy.local.default.ivy.pattern}" />
<artifact pattern="${ivy.local.default.root}/${ivy.local.default.artifact.pattern}" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" />
<ibiblio name="javanet" root="http://download.java.net/maven/2/" m2compatible="true" />
</chain>
</resolvers>
</ivysettings>

View File

@ -1,12 +1,12 @@
{ {
"userList":[ "userList":[
{ {
"userName":"testuser1", "username":"testuser1",
"password":"password1", "password":"password1",
"email":"test1@dummy.com" "email":"test1@dummy.com"
}, },
{ {
"userName":"testuser2", "username":"testuser2",
"password":"password2", "password":"password2",
"email":"test2@dummy.com" "email":"test2@dummy.com"
} }

View File

@ -145,7 +145,7 @@
"assertions" : [ "assertions" : [
{ {
"actualOutput" : "${output(1.3).username}", "actualOutput" : "${output(1.3).username}",
"condition" : "!=", "condition" : "==",
"expectedOutput" : "${input.userList[0].username}" "expectedOutput" : "${input.userList[0].username}"
} }
] ]
@ -240,7 +240,7 @@
] ]
}, },
{ {
"name" : "PLace order", "name" : "Place order",
"id" : 2, "id" : 2,
"resourceId" : 14, "resourceId" : 14,
"input" : { "input" : {

View File

@ -40,13 +40,15 @@ public class JavaLibCodeGen extends LibraryCodeGenerator {
JavaLibCodeGen codeGenerator = new JavaLibCodeGen(configPath); JavaLibCodeGen codeGenerator = new JavaLibCodeGen(configPath);
codeGenerator.generateCode(); codeGenerator.generateCode();
} }
if(args.length == 6) { if(args.length == 4) {
String apiServerURL = args[0]; String apiServerURL = args[0];
String apiKey = args[1]; String apiKey = args[1];
String modelPackageName = args[2]; String packageName = args[2];
String apiPackageName = args[3]; String libraryHome = args[3];
String classOutputDir = args[4];
String libraryHome = args[5]; String modelPackageName = packageName+".model";
String apiPackageName = packageName+".api";
String classOutputDir = libraryHome + "/src/main/java/" + packageName.replace(".","/");
JavaLibCodeGen codeGenerator = new JavaLibCodeGen(apiServerURL, apiKey, modelPackageName, JavaLibCodeGen codeGenerator = new JavaLibCodeGen(apiServerURL, apiKey, modelPackageName,
apiPackageName, classOutputDir, libraryHome); apiPackageName, classOutputDir, libraryHome);
codeGenerator.generateCode(); codeGenerator.generateCode();

View File

@ -80,7 +80,8 @@ public class APITestRunner {
* Arg[4] --> test data class name (class to which test data file will be deserialized) * Arg[4] --> test data class name (class to which test data file will be deserialized)
* Arg[5] --> package where API classes are available * Arg[5] --> package where API classes are available
* Arg[6] --> Language to execute test cases * Arg[6] --> Language to execute test cases
* Arg[7] --> Optional test cases id. provide this if you need to execute only one test case * Arg[7] --> Library location
* Arg[8] --> Optional test cases id. provide this if you need to execute only one test case
* *
* @param args * @param args
* @throws Exception * @throws Exception
@ -93,17 +94,19 @@ public class APITestRunner {
String testDataLocation = args[3]; String testDataLocation = args[3];
String testDataClass = args[4]; String testDataClass = args[4];
String apiPackageName = args[5]; String apiPackageName = args[5];
String language = args[6]; String libraryLocation = args[6];
String language = args[7];
String suiteId = "0"; String suiteId = "0";
if(args.length > 7){ if(args.length > 8){
suiteId = args[7]; suiteId = args[8];
} }
ApiKeyAuthTokenBasedSecurityHandler securityHandler = new ApiKeyAuthTokenBasedSecurityHandler(apiKey, ""); ApiKeyAuthTokenBasedSecurityHandler securityHandler = new ApiKeyAuthTokenBasedSecurityHandler(apiKey, "");
APIInvoker.initialize(securityHandler, apiServer, true); APIInvoker.initialize(securityHandler, apiServer, true);
APITestRunner runner = new APITestRunner(); APITestRunner runner = new APITestRunner();
runner.initialize(testScriptLocation, testDataLocation, testDataClass); runner.initialize(testScriptLocation, testDataLocation, testDataClass);
runner.runTests(apiServer, apiPackageName, runner.getTestPackage(), language, new Integer(suiteId), apiPackageName, securityHandler); runner.runTests(apiServer, apiPackageName, runner.getTestPackage(), language, new Integer(suiteId), apiPackageName, securityHandler, libraryLocation);
} }
public void initialize(String testScriptLocation, String testDataLocation, String testDataClass) throws Exception { public void initialize(String testScriptLocation, String testDataLocation, String testDataClass) throws Exception {
@ -152,7 +155,8 @@ public class APITestRunner {
* @param testPackage * @param testPackage
*/ */
private void runTests(String apiServer, String apiPackageName, TestPackage testPackage, String language, int suiteId, private void runTests(String apiServer, String apiPackageName, TestPackage testPackage, String language, int suiteId,
String libraryPackageName, ApiKeyAuthTokenBasedSecurityHandler securityHandler) throws Exception { String libraryPackageName, ApiKeyAuthTokenBasedSecurityHandler securityHandler,
String libraryLocation) throws Exception {
/** /**
* Logic: * Logic:
* *
@ -231,7 +235,7 @@ public class APITestRunner {
String[] externalCommand = constructExternalCommand(apiServer, apiPackageName, String[] externalCommand = constructExternalCommand(apiServer, apiPackageName,
securityHandler.getApiKey(), authToken, securityHandler.getApiKey(), authToken,
resource.getPath(), resource.getHttpMethod(), resource.getSuggestedMethodName(), resource.getPath(), resource.getHttpMethod(), resource.getSuggestedMethodName(),
queryPathParameters.toString(), postData, language); queryPathParameters.toString(), postData, language, libraryLocation);
//print the command //print the command
System.out.println("Test Case :" + testCasePath); System.out.println("Test Case :" + testCasePath);
for(String arg : externalCommand){ for(String arg : externalCommand){
@ -502,11 +506,12 @@ public class APITestRunner {
*/ */
private String[] constructExternalCommand(String apiServer, String apiPackageName, String apiKey, String authToken, private String[] constructExternalCommand(String apiServer, String apiPackageName, String apiKey, String authToken,
String resource, String httpMethod, String suggestedMethodName, String queryAndPathParams, String resource, String httpMethod, String suggestedMethodName, String queryAndPathParams,
String postData, String language) { String postData, String language, String libraryLocation) {
List<String> command = new ArrayList<String>(); List<String> command = new ArrayList<String>();
if(language.equals(JAVA)){ if(language.equals(JAVA)){
command.add("./bin/runjava.sh"); command.add("./bin/runjavaTestCase.sh");
command.add("com.wordnik.swagger.testframework.JavaTestCaseExecutor"); command.add("com.wordnik.swagger.testframework.JavaTestCaseExecutor");
command.add( libraryLocation );
}else if (language.equals(PYTHON)){ }else if (language.equals(PYTHON)){
command.add("../python/runtest.py "); command.add("../python/runtest.py ");
}else if (language.equals(ANDROID)){ }else if (language.equals(ANDROID)){

View File

@ -38,24 +38,24 @@ public class JavaTestCaseExecutor {
JavaTestCaseExecutor runner = new JavaTestCaseExecutor(); JavaTestCaseExecutor runner = new JavaTestCaseExecutor();
String apiServer = args[0]; String apiServer = args[1];
String servicePackageName = args[1]; String servicePackageName = args[2];
String apiKey = args[2]; String apiKey = args[3];
String authToken = args[3]; String authToken = args[4];
String resource = args[4]; String resource = args[5];
String httpMethod = args[5]; String httpMethod = args[6];
String suggestedMethodName = args[6]; String suggestedMethodName = args[7];
Map<String, String> queryAndPathParameters = new HashMap<String, String>(); Map<String, String> queryAndPathParameters = new HashMap<String, String>();
String postData = null; String postData = null;
if(args.length > 7 && args[7].length() > 0){ if(args.length > 8 && args[8].length() > 0){
String[] qpTuple = args[7].split("~"); String[] qpTuple = args[8].split("~");
for(String tuple: qpTuple){ for(String tuple: qpTuple){
String[] nameValue = tuple.split("="); String[] nameValue = tuple.split("=");
queryAndPathParameters.put(nameValue[0], nameValue[1]); queryAndPathParameters.put(nameValue[0], nameValue[1]);
} }
} }
if(args.length > 8 ){ if(args.length > 9 ){
postData = args[8]; postData = args[9];
} }
queryAndPathParameters.put("authToken", authToken); queryAndPathParameters.put("authToken", authToken);