Commit 32127757 authored by Lakshmi Chaitanya's avatar Lakshmi Chaitanya

First Commit

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="RestAssured-Project" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>RestAssured-Project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.thegoate</groupId>
<artifactId>restassured</artifactId>
<version>0.15.8.202201171722</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
import io.restassured.http.ContentType;
import org.json.simple.JSONObject;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.when;
public class PostMethod {
@Test
public void test_1_post() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "Raghav");
map.put("job", "Teacher");
System.out.println(map);
JSONObject request = new JSONObject();
request.put("name", "Raghav");
request.put("job", "Teacher");
System.out.println(request);
System.out.println(request.toJSONString());
given().
header("Content-Type", "application/json").
contentType(ContentType.JSON).
accept(ContentType.JSON).
body(request.toJSONString()).
when().
post("https://reqres.in/api/users").
then().
statusCode(201);
}
@Test
public void test_2_put() {
JSONObject request = new JSONObject();
request.put("name", "Raghav");
request.put("job", "Teacher");
System.out.println(request);
System.out.println(request.toJSONString());
given().
header("Content-Type", "application/json").
contentType(ContentType.JSON).
accept(ContentType.JSON).
body(request.toJSONString()).
when().
put("https://reqres.in/api/users").
then().
statusCode(200);
}
@Test
public void test_3_patch() {
JSONObject request = new JSONObject();
request.put("name", "Raghav");
request.put("job", "Teacher");
System.out.println(request);
System.out.println(request.toJSONString());
given().
header("Content-Type", "application/json").
contentType(ContentType.JSON).
accept(ContentType.JSON).
body(request.toJSONString()).
when().
patch("https://reqres.in/api/users").
then().
statusCode(200).
log().all();
}
@Test
public void test_4_delete() {
when().
delete("https://reqres.in/api/users/2").
then().
statusCode(204).
log().all();
}
}
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.testng.Assert;
import org.testng.annotations.Test;
public class restAPI {
@Test
public void GetDetails()
{
Response response = RestAssured.get("https://reqres.in/api/users?page=2");
System.out.println("Response : "+response.asString());
System.out.println("Status Code : "+response.getStatusCode());
System.out.println("Body : "+response.getBody().asString());
System.out.println("Time taken : "+response.getTime());
System.out.println("Header : "+response.getHeader("content-type"));
int statusCode =response.getStatusCode();
Assert.assertEquals(statusCode,200);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment