-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathApiTester.java
More file actions
208 lines (177 loc) · 8.52 KB
/
ApiTester.java
File metadata and controls
208 lines (177 loc) · 8.52 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
Copyright 2020 Twitter, Inc.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
https://openapi-generator.tech
Do not edit the class manually.
*/
package com.twitter.clientlib.integration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import com.twitter.clientlib.ApiException;
import com.twitter.clientlib.TwitterCredentialsBearer;
import com.twitter.clientlib.TwitterCredentialsOAuth2;
import com.twitter.clientlib.api.TwitterApi;
import com.twitter.clientlib.model.*;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
abstract public class ApiTester {
protected TwitterApi apiInstance;
protected final Integer maxResults = 15;
// Tweets
protected final Set<String> tweetFields = new HashSet<>(
Arrays.asList("author_id", "id", "created_at"));
protected Set<String> expansions = new HashSet<>(Collections.singletonList("author_id"));
protected String tweetId = "20";
protected String tweetIdNotFound = "12119879112120";
protected String tweetIdPopular = "1354143047324299264";
// Users
protected final Set<String> userFields = new HashSet<>(Collections.singletonList("username"));
protected final String userId = System.getenv("YOUR_TWITTER_USER_ID");
protected final String popularUserId = "250831586";
protected final String userNotExists = "9999999999999";
protected final List<String> usersIds = Arrays.asList(popularUserId);
protected final List<String> usersIdsNotFound = Arrays.asList(userNotExists);
protected final Set<String> excludedTweetFields = new HashSet<>(Arrays.asList(
"non_public_metrics", "promoted_metrics", "organic_metrics", "created_at"));
protected final Set<String> excludedUserFields = new HashSet<>(Arrays.asList(
"url", "profile_image_url", "description", "created_at"));
protected void initApiInstance() {
apiInstance = new TwitterApi(new TwitterCredentialsOAuth2(System.getenv("TWITTER_OAUTH2_CLIENT_ID"),
System.getenv("TWITTER_OAUTH2_CLIENT_SECRET"),
System.getenv("TWITTER_OAUTH2_ACCESS_TOKEN"),
System.getenv("TWITTER_OAUTH2_REFRESH_TOKEN")));
}
protected void initApiInstanceBearer() {
apiInstance = new TwitterApi(new TwitterCredentialsBearer(System.getenv("TWITTER_BEARER_TOKEN")));
}
protected void checkApiExceptionProblem(
ApiException e, Class problemType, String message, String title, String detail
) {
Assertions.assertTrue(
e.getErrorObject().getProblem().getClass().getName().equals(problemType.getName()));
InvalidRequestProblem problem = (InvalidRequestProblem) e.getErrorObject().getProblem();
Assertions.assertNotNull(problem.getErrors());
Assertions.assertNotNull(problem.getErrors().get(0));
Assertions.assertNotNull(problem.getErrors().get(0).getMessage());
Assertions.assertTrue(problem.getErrors().get(0).getMessage().contains(message));
Assertions.assertEquals(problem.getTitle(), title);
Assertions.assertEquals(problem.getDetail(), detail);
}
protected void checkErrors(boolean assertTrue, List<Problem> errors) {
boolean hasErrors = errors != null && errors.size() > 0;
if (assertTrue) {
Assertions.assertTrue(hasErrors);
} else {
Assertions.assertFalse(hasErrors);
}
}
protected void checkTweetData(Tweet tweet) {
Assertions.assertNotNull(tweet);
Assertions.assertNotNull(tweet.getText());
Assertions.assertNotNull(tweet.getAuthorId());
Assertions.assertNotNull(tweet.getCreatedAt());
}
protected void checkTweetDataExclude(Tweet tweet) {
Assertions.assertNotNull(tweet);
Assertions.assertNotNull(tweet.getText());
Assertions.assertNotNull(tweet.getAuthorId());
Assertions.assertNull(tweet.getCreatedAt());
Assertions.assertNull(tweet.getNonPublicMetrics());
Assertions.assertNull(tweet.getPromotedMetrics());
Assertions.assertNull(tweet.getOrganicMetrics());
}
protected void checkTweetIncludes(Expansions expansions) {
Assertions.assertNotNull(expansions);
Assertions.assertNotNull(expansions.getUsers());
Assertions.assertNotNull(expansions.getUsers().get(0));
Assertions.assertNotNull(expansions.getUsers().get(0).getUsername());
}
protected void checkUserData(User user) {
Assertions.assertNotNull(user);
Assertions.assertNotNull(user.getId());
Assertions.assertNotNull(user.getUsername());
Assertions.assertNotNull(user.getName());
}
protected void checkUserDataExclude(User user) {
Assertions.assertNotNull(user);
Assertions.assertNotNull(user.getId());
Assertions.assertNotNull(user.getUsername());
Assertions.assertNotNull(user.getName());
Assertions.assertNull(user.getCreatedAt());
Assertions.assertNull(user.getDescription());
Assertions.assertNull(user.getUrl());
Assertions.assertNull(user.getProfileImageUrl());
}
protected void checkSpaceData(Space space) {
Assertions.assertNotNull(space);
Assertions.assertNotNull(space.getId());
Assertions.assertNotNull(space.getCreatedAt());
Assertions.assertNotNull(space.getCreatorId());
Assertions.assertNotNull(space.getTitle());
}
protected void checkListData(ModelList list) {
Assertions.assertNotNull(list);
Assertions.assertNotNull(list.getId());
Assertions.assertNotNull(list.getCreatedAt());
Assertions.assertNotNull(list.getDescription());
Assertions.assertNotNull(list.getOwnerId());
Assertions.assertNotNull(list.getFollowerCount());
}
protected void checkComplianceJobData(ComplianceJob complianceJob) {
Assertions.assertNotNull(complianceJob);
Assertions.assertNotNull(complianceJob.getType());
Assertions.assertNotNull(complianceJob.getId());
Assertions.assertNotNull(complianceJob.getCreatedAt());
}
protected void checkModelListData(ModelList modelList) {
Assertions.assertNotNull(modelList);
Assertions.assertNotNull(modelList.getName());
Assertions.assertNotNull(modelList.getId());
Assertions.assertNotNull(modelList.getCreatedAt());
}
protected void checkResourceNotFoundProblem(
Problem problem, String value, String title, String parameter
) {
Assertions.assertTrue(problem instanceof ResourceNotFoundProblem);
ResourceNotFoundProblem resourceNotFoundProblem = (ResourceNotFoundProblem) problem;
Assertions.assertTrue(resourceNotFoundProblem.getTitle().equals(title));
Assertions.assertEquals(parameter, resourceNotFoundProblem.getParameter());
Assertions.assertEquals(value, resourceNotFoundProblem.getValue());
}
protected void checkGenericProblem(Problem problem, String detail, String title, Integer status) {
Assertions.assertTrue(problem instanceof GenericProblem);
GenericProblem genericProblem = (GenericProblem) problem;
Assertions.assertTrue(genericProblem.getTitle().equals(title));
Assertions.assertEquals(detail, genericProblem.getDetail());
Assertions.assertEquals(status, genericProblem.getStatus());
}
protected void checkInvalidRequestProblem(
Problem problem, String detail, String title, String firstErrorMessage
) {
Assertions.assertTrue(problem instanceof InvalidRequestProblem);
InvalidRequestProblem invalidRequestProblem = (InvalidRequestProblem) problem;
Assertions.assertTrue(invalidRequestProblem.getTitle().equals(title));
Assertions.assertEquals(detail, invalidRequestProblem.getDetail());
Assertions.assertEquals(firstErrorMessage, invalidRequestProblem.getErrors().get(0).getMessage());
}
protected void checkDuplicateRuleProblem(Problem problem, String detail, String value) {
Assertions.assertTrue(problem instanceof DuplicateRuleProblem);
DuplicateRuleProblem duplicateProblem = (DuplicateRuleProblem) problem;
Assertions.assertTrue(duplicateProblem.getTitle().equals("DuplicateRule"));
// Assertions.assertEquals(detail, duplicateProblem.getDetail());
Assertions.assertEquals(value, duplicateProblem.getValue());
}
}