Skip to content

Commit

Permalink
#342 added test cases
Browse files Browse the repository at this point in the history
updated code to correct object conversion
  • Loading branch information
cjayswal committed May 26, 2020
1 parent ba2bd6c commit 24d07c0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import com.qmetry.qaf.automation.core.AutomationError;
import com.qmetry.qaf.automation.step.client.AbstractScenarioFileParser;
Expand Down Expand Up @@ -258,7 +259,7 @@ private void setExamples(Object[] cols, ArrayList<List<Object>> examplesTable) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (int k = 0; k < keys.size(); k++) {
Object val = examplesTable.get(i).get(k);
map.put(keys.get(k), null!=val?val.toString().trim():null);
map.put(keys.get(k), val);
}
dataMapList.add(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import com.qmetry.qaf.automation.core.AutomationError;
import com.qmetry.qaf.automation.step.client.AbstractScenarioFileParser;
Expand Down Expand Up @@ -299,7 +300,7 @@ private void setExamples(Object[] cols, ArrayList<List<Object>> examplesTable) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (int k = 0; k < keys.size(); k++) {
Object val = examplesTable.get(i).get(k);
map.put(keys.get(k), null!=val?val.toString().trim():null);
map.put(keys.get(k), val);
}
dataMapList.add(map);
}
Expand Down
10 changes: 7 additions & 3 deletions src/com/qmetry/qaf/automation/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,14 @@ public static <T> T eval(String expression, Map<? extends String, ? extends Obje
* @return Object
*/
public static Object toObject(String string) {
if(null!=string){
return JSONObject.stringToValue(string);
if(null==string || JSONObject.NULL==string){
return null;
}
return null;
Object val = JSONObject.stringToValue(string);
if(null==val || JSONObject.NULL==val){
return null;
}
return val;
}

private static String ensuerStringQuated(String data, char seperator) {
Expand Down
31 changes: 31 additions & 0 deletions test/resources/features/ExampleTest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,34 @@ Examples:
| space | " " | 5 |


Scenario: Embedded Examples step call
Then it can have "<age>" status "<married>" of "<name>"
Examples:

| description| name | married | age |
| go right | uname | true | 5 |
| go right | "uname "| false | 0 |
| check null | null | null | null |
| check null | "null" | "null" | "null" |
| check empty | | | |
| check number | " 12345" | true | 0 |


@dataFile:resources/testdata2.txt
Scenario: External test data step call
Then it can have "<age>" status "<married>" of "<name>"

#empty or null not allowed for Primitive types step argument
Scenario: Embedded Examples step call primptive
And it should have <age> status "<married>" of "<name>"
Examples:

| description| name | married | age |
| go right | uname | true | 5 |
| go right | uname | false | 0 |
| empty string | | false | 0 |
| null string | null | false | 0 |




8 changes: 8 additions & 0 deletions test/resources/testdata2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#empty or null not allowed for Primitive types step argument
description, name , married , age
csv go right , uname , true , 5
csv go right , "uname ", false , 0
csv check null , null , null , null
csv check null , "null" , "null" , "null"
csv check empty , , ,

Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,16 @@ public void itShouldHaveEntriesInData(Map<String, Object> entries, Map<String, O
Validator.verifyThat("contains entry " + entry, data, Matchers.hasEntry(entry.getKey(),entry.getValue()));
}
}

@QAFTestStep(description = "it should have {age} status {married} of {name}")
public void acceptTestDataWithPrimitive (int age, boolean mstatus, String name ) {
System.out.println("acceptTestDataWithPrimitive age: " + age + " status: " + mstatus+" name: "+name );
System.out.println("acceptTestDataWithPrimitive is Name not null: " + (null!=name? "yes":"No"));
}
@QAFTestStep(description = "it can have {age} status {married} of {name}")
public void acceptTestDataWithClass(Integer age, Boolean mstatus, String name ) {
System.out.println("acceptTestDataWithClass age: " + age + " status: " + mstatus+" name: "+name );
System.out.println("acceptTestDataWithClass is Name not null: " + (null!=name? "yes":"No"));

}
}

0 comments on commit 24d07c0

Please sign in to comment.