-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordpressApiManager.java
109 lines (99 loc) · 3.3 KB
/
WordpressApiManager.java
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package wp;
import io.qameta.allure.Step;
import io.qameta.allure.restassured.AllureRestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.json.JSONObject;
import pojo.Posts;
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.preemptive;
import static props.ConfigurationManager.config;
/**
* The type Word press.
*/
public final class WordpressApiManager {
/**
* The constant URL.
*/
private static final String URL = config().wpUrl();
/**
* The REQUEST_SPEC.
*/
private static final RequestSpecification REQUEST_SPEC = new RequestSpecBuilder()
.setAuth(preemptive().basic(config().wpUsername(), config().wpPassword()))
.setBaseUri(URL)
.setContentType(ContentType.JSON)
.addFilter(new AllureRestAssured())
.build();
/**
* Delete posts validatable response.
* @param postID the post id
* @return the validatable response
*/
@Step("delete post from WP")
public static ValidatableResponse deletePosts(final int postID) {
return given()
.spec(REQUEST_SPEC)
.queryParam("rest_route", "/wp/v2/posts/" + postID)
.when()
.delete()
.then();
}
/**
* Update post title validatable response.
* @param postID the post id
* @param content the content
* @return the validatable response
*/
@Step("update post in WP")
public static ValidatableResponse updatePostTitle(final int postID, final String content) {
JSONObject requestParams = new JSONObject();
requestParams.put("title", content);
return given()
.spec(REQUEST_SPEC)
.queryParam("rest_route", "/wp/v2/posts/" + postID)
.and()
.body(requestParams.toMap())
.when()
.patch()
.then();
}
/**
* Create post int.
* @param title the title
* @param content the content
* @return the int
*/
@Step("create post in WP")
public static ValidatableResponse createPost(final String title, final String content) {
return given()
.spec(REQUEST_SPEC)
.queryParam("rest_route", "/wp/v2/posts/")
.queryParam("title", title)
.queryParam("content", content)
.queryParam("status", "publish")
.when()
.post()
.then();
}
/**
* Read wp post posts.
* @param postID the post id
* @return the posts
*/
@Step("read WP post")
public static Posts readPost(final int postID) {
return given()
.spec(REQUEST_SPEC)
.queryParam("rest_route", "/wp/v2/posts/" + postID)
.when()
.patch()
.then()
.extract().as(Posts.class);
}
private WordpressApiManager() {
throw new IllegalStateException("Utility class");
}
}