-
Notifications
You must be signed in to change notification settings - Fork 0
/
code (2).txt
86 lines (61 loc) · 2.4 KB
/
code (2).txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
rest api publish
ask for review
prepare material
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import static io.restassured.RestAssured.given;
//rahulonlinetutor@gmail.com
//https://mvnrepository.com/artifact/com.github.scribejava/scribejava-core/2.5.3
//https://mvnrepository.com/artifact/com.github.scribejava/scribejava-apis/2.5.3
public class basics9 {
String ConsumerKey="ztXsFr0ipQTIDue4MD20s4aL3";
String ConsumerSecret="kuOlC5wB1DZ8ahgOsEos1zLa7C4fLmlpSSB5QEJmFFEX70CT2n";
String Token="917476985835851778-vOmu4mScebK0zi7hTPXgprO9A7BMLsw";
String TokenSecret="tCw78M48rJC2mNWpNvZJuXhGUqFgQ8mqowdsjrDbwbQLs";
String id;
@Test
public void getLatestTweet()
{
RestAssured.baseURI="https://api.twitter.com/1.1/statuses";
Response res= given().auth().oauth(ConsumerKey, ConsumerSecret, Token, TokenSecret)
.queryParam("count", "1")
.when().get("/home_timeline.json").then().extract().response();
String response =res.asString();
System.out.println(response);
JsonPath js= new JsonPath(response);
System.out.println(js.get("text"));
System.out.println(js.get("id"));
}
@Test
public void createTweet()
{
RestAssured.baseURI="https://api.twitter.com/1.1/statuses";
Response res= given().auth().oauth(ConsumerKey, ConsumerSecret, Token, TokenSecret)
.queryParam("status", "I am creating this tweet with Automation")
.when().post("/update.json").then().extract().response();
String response =res.asString();
System.out.println(response);
JsonPath js= new JsonPath(response);
System.out.println("Below is the tweet added");
//System.out.println(js.get("text"));
System.out.println(js.get("id"));
id=js.get("id").toString();
}
@Test
public void E2E()
{
createTweet();
RestAssured.baseURI="https://api.twitter.com/1.1/statuses";
Response res= given().auth().oauth(ConsumerKey, ConsumerSecret, Token, TokenSecret)
.when().post("/destroy/"+id+".json").then().extract().response();
String response =res.asString();
System.out.println(response);
JsonPath js= new JsonPath(response);
//System.out.println(js.get("text"));
System.out.println("Tweet which got deleted with automation is below");
System.out.println(js.get("text"));
System.out.println(js.get("truncated"));
}
}