Skip to content

Commit 2ba1c7b

Browse files
committed
version2
1 parent 42e507a commit 2ba1c7b

13 files changed

Lines changed: 75 additions & 28 deletions

File tree

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<version>3.9</version>
3939
</dependency>
4040

41+
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
42+
<dependency>
43+
<groupId>com.googlecode.json-simple</groupId>
44+
<artifactId>json-simple</artifactId>
45+
<version>1.1.1</version>
46+
</dependency>
4147

4248
</dependencies>
4349
</project>

src/test/java/javaTest/ExcelOperation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,33 @@ public static void readExcel(String filePath, String fileName, String sheetName)
3030
workbook = new HSSFWorkbook(inputStream);
3131
HSSFSheet sheet = (HSSFSheet) workbook.getSheetAt(0);
3232

33-
System.out.println("Total APIs are : "+ sheet.getLastRowNum());
33+
System.out.println("******************Total APIs are : "+ sheet.getLastRowNum()+" ******************");
3434
for(int i=1; i<=sheet.getLastRowNum();i++) {
3535

3636
reqUrl = sheet.getRow(i).getCell(1).toString();
3737
method = sheet.getRow(i).getCell(2).toString();
3838

39-
System.out.println("Processing "+ i +reqUrl+" "+method);
39+
System.out.println("Processing "+i+") " +reqUrl+" "+method);
4040

4141
//call to method which sends request
4242
if(sendRequest.testResponseCode(reqUrl,sheet.getRow(i).getCell(2).toString(),Double.parseDouble(sheet.getRow(i).getCell(3).toString()))==0) {
4343
FileOutputStream f2 = new FileOutputStream(file);
4444
HSSFCell cell = sheet.getRow(i).createCell(4);
4545
cell.setCellValue("PASS");
46-
System.out.println("writing PASS"+cell.getRowIndex() +" : " + cell.getColumnIndex());
46+
System.out.println("PASS");
4747
workbook.write(f2);
4848
f2.close();
49+
System.out.println("******************************************************");
4950
}
5051
else {
5152
FileOutputStream f2 = new FileOutputStream(file);
5253
HSSFCell cell = sheet.getRow(i).createCell(4);
54+
System.out.println("FAIL");
5355
cell.setCellValue("FAIL");
5456
workbook.write(f2);
5557
f2.close();
58+
System.out.println("******************************************************");
5659
}
57-
5860
}
5961
}
6062
}

src/test/java/javaTest/sendRequest.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,61 @@
22

33
import static io.restassured.RestAssured.get;
44

5+
import org.json.simple.JSONObject;
6+
import org.testng.annotations.Test;
7+
8+
import io.restassured.RestAssured;
59
import io.restassured.response.Response;
10+
import io.restassured.specification.RequestSpecification;
611

712
public class sendRequest {
813

14+
@Test
915
public static int testResponseCode(String reqUrl, String methodName, double expectedCode) {
10-
System.out.println(reqUrl);
11-
System.out.println(expectedCode);
16+
System.out.println("method : "+methodName);
17+
18+
System.out.println("expected code is :- "+expectedCode);
1219
Response resp = null;
13-
int code;
20+
int code = 0;
21+
RestAssured.baseURI =reqUrl;
22+
RequestSpecification request = RestAssured.given();
1423

1524
if(methodName.equalsIgnoreCase("get")) {
1625
resp = get(reqUrl);
1726
}
18-
code = resp.getStatusCode();
27+
else if(methodName.equalsIgnoreCase("post")) {
28+
JSONObject requestParams = new JSONObject();
29+
requestParams.put("name", "morpheus");
30+
requestParams.put("job", "leader");
31+
32+
request.header("Content-Type", "application/json");
33+
34+
request.body(requestParams.toJSONString());
35+
36+
resp = request.post();
37+
}else if(methodName.equalsIgnoreCase("put")) {
38+
39+
JSONObject requestParams = new JSONObject();
40+
requestParams.put("name", "morpheus");
41+
requestParams.put("job", "zion resident");
42+
43+
request.header("Content-Type", "application/json");
44+
45+
request.body(requestParams.toJSONString());
46+
47+
resp = request.put();
48+
}else if(methodName.equalsIgnoreCase("delete")) {
1949

50+
request.header("Content-Type", "application/json");
51+
52+
resp = request.delete();
53+
}
54+
System.out.println(methodName+" method :"+ code);
55+
if(resp != null) {
56+
code = resp.getStatusCode();
57+
58+
}
59+
2060
if(code == Math.round(expectedCode)) {
2161
return 0;
2262
}
@@ -26,5 +66,4 @@ public static int testResponseCode(String reqUrl, String methodName, double expe
2666

2767
}
2868

29-
3069
}
48 Bytes
Binary file not shown.
1.59 KB
Binary file not shown.

test-output/Default suite/Default test.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ <h2 align='center'>Default test</h2><table border='1' align="center">
5757
<tr>
5858
<td>Tests passed/Failed/Skipped:</td><td>1/0/0</td>
5959
</tr><tr>
60-
<td>Started on:</td><td>Mon Dec 17 00:22:06 IST 2018</td>
60+
<td>Started on:</td><td>Mon Dec 17 23:54:09 IST 2018</td>
6161
</tr>
62-
<tr><td>Total time:</td><td>8 seconds (8726 ms)</td>
62+
<tr><td>Total time:</td><td>12 seconds (12691 ms)</td>
6363
</tr><tr>
6464
<td>Included groups:</td><td></td>
6565
</tr><tr>
@@ -77,8 +77,8 @@ <h2 align='center'>Default test</h2><table border='1' align="center">
7777
<tr>
7878
<td title='javaTest.JavaTest.testResponseCode()'><b>testResponseCode</b><br>Test class: javaTest.JavaTest</td>
7979
<td></td>
80-
<td>8</td>
81-
<td>javaTest.JavaTest@23ceabc1</td></tr>
80+
<td>12</td>
81+
<td>javaTest.JavaTest@58651fd0</td></tr>
8282
</table><p>
8383
</body>
8484
</html>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- Generated by org.testng.reporters.JUnitXMLReporter -->
3-
<testsuite hostname="SAGAR" name="Default test" tests="1" failures="0" timestamp="16 Dec 2018 18:52:15 GMT" time="8.726" errors="0">
4-
<testcase name="testResponseCode" time="8.701" classname="javaTest.JavaTest"/>
3+
<testsuite hostname="SAGAR" name="Default test" tests="1" failures="0" timestamp="17 Dec 2018 18:24:22 GMT" time="12.691" errors="0">
4+
<testcase name="testResponseCode" time="12.672" classname="javaTest.JavaTest"/>
55
</testsuite> <!-- Default test -->

test-output/emailable-report.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
<body>
3232
<table cellspacing="0" cellpadding="0" class="result">
3333
<tr><th>Test</th><th class="numi">Methods<br/>Passed</th><th class="numi">Scenarios<br/>Passed</th><th class="numi"># skipped</th><th class="numi"># failed</th><th class="numi">Total<br/>Time</th><th class="numi">Included<br/>Groups</th><th class="numi">Excluded<br/>Groups</th></tr>
34-
<tr><td style="text-align:left;padding-right:2em">Default test</td><td class="numi">1</td><td class="numi">1</td><td class="numi">0</td><td class="numi">0</td><td class="numi">8.7 seconds</td><td class="numi"></td><td class="numi"></td></tr>
34+
<tr><td style="text-align:left;padding-right:2em">Default test</td><td class="numi">1</td><td class="numi">1</td><td class="numi">0</td><td class="numi">0</td><td class="numi">12.7 seconds</td><td class="numi"></td><td class="numi"></td></tr>
3535
</table>
3636
<table cellspacing="0" cellpadding="0" class="passed" id="summary">
3737
<tr><th>Class</th><th>Method</th><th># of<br/>Scenarios</th><th>Start</th><th>Time<br/>(ms)</th></tr>
3838
<tr><th colspan="4">Default test &#8212; passed</th></tr>
39-
<tr class="passedodd"><td rowspan="1">javaTest.JavaTest</td><td><a href="#m1"><b>testResponseCode</b> </a></td><td class="numi">1</td><td>1544986326780</td><td class="numi">8701</td></tr>
39+
<tr class="passedodd"><td rowspan="1">javaTest.JavaTest</td><td><a href="#m1"><b>testResponseCode</b> </a></td><td class="numi">1</td><td>1545071049521</td><td class="numi">12672</td></tr>
4040
</table>
4141
<h1>Default test</h1>
4242
<h2 id="m1">javaTest.JavaTest:testResponseCode</h2>

test-output/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<ul>
4949
<li>
5050
<a href="#" class="navigator-link " panel-name="test-xml-Default_suite">
51-
<span>C:\Users\sagar\AppData\Local\Temp\testng-eclipse--1178585895\testng-customsuite.xml</span>
51+
<span>C:\Users\sagar\AppData\Local\Temp\testng-eclipse--519285495\testng-customsuite.xml</span>
5252
</a> <!-- navigator-link -->
5353
</li>
5454
<li>
@@ -134,7 +134,7 @@
134134
</div> <!-- panel Default_suite -->
135135
<div panel-name="test-xml-Default_suite" class="panel">
136136
<div class="main-panel-header rounded-window-top">
137-
<span class="header-content">C:\Users\sagar\AppData\Local\Temp\testng-eclipse--1178585895\testng-customsuite.xml</span>
137+
<span class="header-content">C:\Users\sagar\AppData\Local\Temp\testng-eclipse--519285495\testng-customsuite.xml</span>
138138
</div> <!-- main-panel-header rounded-window-top -->
139139
<div class="main-panel-content rounded-window-bottom">
140140
<pre>
@@ -189,12 +189,12 @@
189189
data.setCell(0, 0, 0)
190190
data.setCell(0, 1, 'testResponseCode')
191191
data.setCell(0, 2, 'javaTest.JavaTest')
192-
data.setCell(0, 3, 8701);
192+
data.setCell(0, 3, 12672);
193193
window.suiteTableData['Default_suite']= { tableData: data, tableDiv: 'times-div-Default_suite'}
194194
return data;
195195
}
196196
</script>
197-
<span class="suite-total-time">Total running time: 8 seconds</span>
197+
<span class="suite-total-time">Total running time: 12 seconds</span>
198198
<div id="times-div-Default_suite">
199199
</div> <!-- times-div-Default_suite -->
200200
</div> <!-- times-div -->
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
3-
<testsuite hostname="SAGAR" name="javaTest.JavaTest" tests="1" failures="0" timestamp="16 Dec 2018 18:52:15 GMT" time="8.701" errors="0">
4-
<testcase name="testResponseCode" time="8.701" classname="javaTest.JavaTest"/>
3+
<testsuite hostname="SAGAR" name="javaTest.JavaTest" tests="1" failures="0" timestamp="17 Dec 2018 18:24:22 GMT" time="12.672" errors="0">
4+
<testcase name="testResponseCode" time="12.672" classname="javaTest.JavaTest"/>
55
</testsuite> <!-- javaTest.JavaTest -->

0 commit comments

Comments
 (0)