Skip to content

Commit b7d3490

Browse files
authored
Change MentionEntity.id to be not mandatory. (#29)
* Change MentionEntity.id to be not mandatory. * Add integration tests.
1 parent 926c988 commit b7d3490

File tree

15 files changed

+455
-240
lines changed

15 files changed

+455
-240
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Add this dependency to your project's POM:
6060
<dependency>
6161
<groupId>com.twitter</groupId>
6262
<artifactId>twitter-api-java-sdk</artifactId>
63-
<version>2.0.0</version>
63+
<version>2.0.1</version>
6464
</dependency>
6565
```
6666

@@ -75,7 +75,7 @@ mavenLocal() // Needed if the 'twitter-api-java-sdk' jar has been publishe
7575
}
7676
7777
dependencies {
78-
implementation "com.twitter:twitter-api-java-sdk:2.0.0"
78+
implementation "com.twitter:twitter-api-java-sdk:2.0.1"
7979
}
8080
```
8181

@@ -89,7 +89,7 @@ mvn clean package
8989

9090
Then manually install the following JARs:
9191

92-
* `target/twitter-api-java-sdk-2.0.0.jar`
92+
* `target/twitter-api-java-sdk-2.0.1.jar`
9393
* `target/lib/*.jar`
9494

9595
## Twitter Credentials
@@ -120,7 +120,8 @@ You can use the following objects in order to set the credentials:
120120

121121
```java
122122

123-
TwitterApi apiInstance = new TwitterApi(new TwitterCredentialsOAuth2(System.getenv("TWITTER_OAUTH2_CLIENT_ID"),
123+
TwitterApi apiInstance = new TwitterApi(new TwitterCredentialsOAuth2(
124+
System.getenv("TWITTER_OAUTH2_CLIENT_ID"),
124125
System.getenv("TWITTER_OAUTH2_CLIENT_SECRET"),
125126
System.getenv("TWITTER_OAUTH2_ACCESS_TOKEN"),
126127
System.getenv("TWITTER_OAUTH2_REFRESH_TOKEN")));
@@ -152,7 +153,8 @@ public class TwitterApiExample {
152153
* Check the 'security' tag of the required APIs in https://api.twitter.com/2/openapi.json in order
153154
* to use the right credential object.
154155
*/
155-
TwitterApi apiInstance = new TwitterApi(new TwitterCredentialsOAuth2(System.getenv("TWITTER_OAUTH2_CLIENT_ID"),
156+
TwitterApi apiInstance = new TwitterApi(new TwitterCredentialsOAuth2(
157+
System.getenv("TWITTER_OAUTH2_CLIENT_ID"),
156158
System.getenv("TWITTER_OAUTH2_CLIENT_SECRET"),
157159
System.getenv("TWITTER_OAUTH2_ACCESS_TOKEN"),
158160
System.getenv("TWITTER_OAUTH2_REFRESH_TOKEN")));

docs/MentionEntity.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|------------ | ------------- | ------------- | -------------|
1010
|**end** | **Integer** | Index (zero-based) at which position this entity ends. The index is exclusive. | |
1111
|**start** | **Integer** | Index (zero-based) at which position this entity starts. The index is inclusive. | |
12-
|**id** | **String** | Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. | |
12+
|**id** | **String** | Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. | [optional] |
1313
|**username** | **String** | The Twitter handle (screen name) of this user. | |
1414

1515

docs/MentionFields.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Represent the portion of text recognized as a User mention, and its start and en
88

99
| Name | Type | Description | Notes |
1010
|------------ | ------------- | ------------- | -------------|
11-
|**id** | **String** | Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. | |
11+
|**id** | **String** | Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. | [optional] |
1212
|**username** | **String** | The Twitter handle (screen name) of this user. | |
1313

1414

examples/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>com.twitter</groupId>
1818
<artifactId>twitter-api-java-sdk</artifactId>
19-
<version>2.0.0</version>
19+
<version>2.0.1</version>
2020
<scope>compile</scope>
2121
</dependency>
2222
</dependencies>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>twitter-api-java-sdk</artifactId>
66
<packaging>jar</packaging>
77
<name>twitter-api-java-sdk</name>
8-
<version>2.0.0</version>
8+
<version>2.0.1</version>
99
<url>https://github.com/twitterdev/twitter-api-java-sdk</url>
1010
<description>Twitter API v2 available endpoints</description>
1111
<scm>

src/main/java/com/twitter/clientlib/ApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void init() {
225225
json = new JSON();
226226

227227
// Set default User-Agent.
228-
setUserAgent("twitter-api-java-sdk/2.0.0");
228+
setUserAgent("twitter-api-java-sdk/2.0.1");
229229

230230
authentications = new HashMap<String, Authentication>();
231231
}

src/main/java/com/twitter/clientlib/JSON.java

+212-212
Large diffs are not rendered by default.

src/main/java/com/twitter/clientlib/model/MentionEntity.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public MentionEntity id(String id) {
137137
* Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.
138138
* @return id
139139
**/
140-
@javax.annotation.Nonnull
141-
@ApiModelProperty(example = "2244994945", required = true, value = "Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.")
140+
@javax.annotation.Nullable
141+
@ApiModelProperty(example = "2244994945", value = "Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.")
142142

143143
public String getId() {
144144
return id;
@@ -233,7 +233,6 @@ private String toIndentedString(Object o) {
233233
openapiRequiredFields = new HashSet<String>();
234234
openapiRequiredFields.add("end");
235235
openapiRequiredFields.add("start");
236-
openapiRequiredFields.add("id");
237236
openapiRequiredFields.add("username");
238237
}
239238

src/main/java/com/twitter/clientlib/model/MentionFields.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public MentionFields id(String id) {
8080
* Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.
8181
* @return id
8282
**/
83-
@javax.annotation.Nonnull
84-
@ApiModelProperty(example = "2244994945", required = true, value = "Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.")
83+
@javax.annotation.Nullable
84+
@ApiModelProperty(example = "2244994945", value = "Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.")
8585

8686
public String getId() {
8787
return id;
@@ -168,7 +168,6 @@ private String toIndentedString(Object o) {
168168

169169
// a set of required properties/fields (JSON key names)
170170
openapiRequiredFields = new HashSet<String>();
171-
openapiRequiredFields.add("id");
172171
openapiRequiredFields.add("username");
173172
}
174173

src/test/java/com/twitter/clientlib/integration/ApiBookmarksTester.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void createDeleteTweetErrorTest() throws ApiException {
141141
apiInstance.bookmarks().postUsersIdBookmarks(req, userId).execute();
142142
});
143143
checkGenericProblem(exception.getErrorObject().getProblem(),
144-
"You are not permitted to bookmark this Tweet.", "Forbidden",
145-
403);
144+
"You cannot bookmark a Tweet that does not exist.", "Bad Request",
145+
400);
146146
}
147147
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright 2020 Twitter, Inc.
3+
SPDX-License-Identifier: Apache-2.0
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
18+
https://openapi-generator.tech
19+
Do not edit the class manually.
20+
*/
21+
22+
23+
package com.twitter.clientlib.integration;
24+
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.TestInstance;
28+
29+
import com.twitter.clientlib.ApiException;
30+
import com.twitter.clientlib.model.*;
31+
32+
import static org.junit.jupiter.api.Assertions.assertFalse;
33+
import static org.junit.jupiter.api.Assertions.assertNotNull;
34+
import static org.junit.jupiter.api.Assertions.assertThrows;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
37+
38+
39+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
40+
public class ApiComplianceTester extends ApiTester {
41+
42+
String complianceJobByID = "1537616980307456001"; //1382081613278814209
43+
String complianceJobByIDNotFound = "998837616980307456099"; //1382081613278814209
44+
45+
@BeforeAll
46+
public void init() {
47+
initApiInstanceBearer();
48+
}
49+
50+
public CreateComplianceJobResponse createCompliance() throws ApiException {
51+
CreateComplianceJobRequest req = new CreateComplianceJobRequest();
52+
req.setType(CreateComplianceJobRequest.TypeEnum.TWEETS);
53+
return apiInstance.compliance().createBatchComplianceJob(req)
54+
.execute();
55+
}
56+
57+
@Test
58+
public void getBatchComplianceJobJobTest() throws ApiException {
59+
String id = createCompliance().getData().getId();
60+
Get2ComplianceJobsIdResponse result = apiInstance.compliance().getBatchComplianceJob(id).execute();
61+
checkErrors(false, result.getErrors());
62+
checkComplianceJobData(result.getData());
63+
}
64+
65+
@Test
66+
public void getBatchComplianceJobErrorTest() throws ApiException {
67+
ApiException exception = assertThrows(ApiException.class, () -> {
68+
Get2ComplianceJobsIdResponse result = apiInstance.compliance().getBatchComplianceJob(complianceJobByIDNotFound).execute();
69+
});
70+
checkApiExceptionProblem(exception, InvalidRequestProblem.class,
71+
"The `id` query parameter value [" + complianceJobByIDNotFound + "] does not match ^[0-9]{1,19}$",
72+
"Invalid Request", "One or more parameters to your request was invalid.");
73+
}
74+
75+
// ComplianceJobStatus should have "expired value
76+
// @Test
77+
// public void listBatchComplianceJobsTest() throws ApiException {
78+
// Get2ComplianceJobsResponse result = apiInstance.compliance().listBatchComplianceJobs(
79+
// CreateComplianceJobRequest.TypeEnum.TWEETS.getValue()).execute();
80+
// checkErrors(false, result.getErrors());
81+
// assertNotNull(result.getData());
82+
// checkComplianceJobData(result.getData().get(0));
83+
// }
84+
85+
@Test
86+
public void listBatchComplianceJobsErrorTest() throws ApiException {
87+
ApiException exception = assertThrows(ApiException.class, () -> {
88+
apiInstance.compliance().listBatchComplianceJobs("DUMMY").execute();
89+
});
90+
checkApiExceptionProblem(exception, InvalidRequestProblem.class,
91+
"The `type` query parameter value [" + "DUMMY" + "] is not one of [tweets,users]",
92+
"Invalid Request", "One or more parameters to your request was invalid.");
93+
}
94+
95+
@Test
96+
public void createBatchComplianceJobTest() throws ApiException {
97+
CreateComplianceJobResponse result = createCompliance();
98+
checkErrors(false, result.getErrors());
99+
assertNotNull(result.getData());
100+
assertNotNull(result.getData().getId());
101+
assertNotNull(result.getData().getType());
102+
}
103+
}

src/test/java/com/twitter/clientlib/integration/ApiListsTester.java

+57
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import static org.junit.jupiter.api.Assertions.assertFalse;
3838
import static org.junit.jupiter.api.Assertions.assertNotNull;
39+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3940
import static org.junit.jupiter.api.Assertions.assertNull;
4041
import static org.junit.jupiter.api.Assertions.assertThrows;
4142
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -577,12 +578,14 @@ public void listUserFollowUserNotExistsTest() throws ApiException {
577578

578579
@Test
579580
public void listUserPinTest() throws ApiException {
581+
listUserFollowTest();
580582
ListPinnedRequest request = new ListPinnedRequest();
581583
request.setListId(listId);
582584
ListPinnedResponse result = apiInstance.lists().listUserPin(request, userId).execute();
583585
checkErrors(false, result.getErrors());
584586
assertNotNull(result.getData());
585587
assertTrue(result.getData().getPinned());
588+
listUserUnfollowTest();
586589
}
587590

588591
@Test
@@ -634,4 +637,58 @@ public void listUserUnpinUserNotFoundTest() throws ApiException {
634637
"The `id` query parameter value [" + userNotExists + "] must be the same as the authenticating user",
635638
"Invalid Request", "One or more parameters to your request was invalid.");
636639
}
640+
641+
@Test
642+
public void listUserPinnedListsTest() throws ApiException {
643+
Get2UsersIdPinnedListsResponse result = apiInstance.lists().listUserPinnedLists(userId)
644+
.userFields(userFields)
645+
.listFields(listFields)
646+
.execute();
647+
checkErrors(false, result.getErrors());
648+
assertNotNull(result.getData());
649+
checkModelListData(result.getData().get(0));
650+
assertNull(result.getIncludes());
651+
}
652+
653+
@Test
654+
public void listUserPinnedListsErrorTest() throws ApiException {
655+
ApiException exception = assertThrows(ApiException.class, () -> {
656+
apiInstance.lists().listUserPinnedLists(userNotExists)
657+
.userFields(userFields)
658+
.listFields(listFields)
659+
.execute();
660+
});
661+
checkApiExceptionProblem(exception, InvalidRequestProblem.class,
662+
"The `id` query parameter value [" + userNotExists + "] must be the same as the authenticating user",
663+
"Invalid Request", "One or more parameters to your request was invalid.");
664+
}
665+
666+
@Test
667+
public void listUserUnfollowTest() throws ApiException {
668+
ListFollowedResponse result = apiInstance.lists().listUserUnfollow(userId, listId)
669+
.execute();
670+
checkErrors(false, result.getErrors());
671+
assertNotNull(result.getData());
672+
assertNotEquals(Boolean.TRUE, result.getData().getFollowing());
673+
}
674+
675+
@Test
676+
public void listUserUnfollowUserNotFoundTest() throws ApiException {
677+
ApiException exception = assertThrows(ApiException.class, () -> {
678+
apiInstance.lists().listUserUnfollow(userNotExists, listId)
679+
.execute();
680+
});
681+
checkApiExceptionProblem(exception, InvalidRequestProblem.class,
682+
"The `id` query parameter value [" + userNotExists + "] must be the same as the authenticating user",
683+
"Invalid Request", "One or more parameters to your request was invalid.");
684+
}
685+
686+
@Test
687+
public void listUserUnfollowListNotFoundTest() throws ApiException {
688+
ListFollowedResponse result = apiInstance.lists().listUserUnfollow(userId, listIdNotFound)
689+
.execute();
690+
checkErrors(false, result.getErrors());
691+
assertNotNull(result.getData());
692+
assertFalse(result.getData().getFollowing());
693+
}
637694
}

src/test/java/com/twitter/clientlib/integration/ApiTester.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,7 @@
3434
import com.twitter.clientlib.TwitterCredentialsBearer;
3535
import com.twitter.clientlib.TwitterCredentialsOAuth2;
3636
import com.twitter.clientlib.api.TwitterApi;
37-
import com.twitter.clientlib.model.DuplicateRuleProblem;
38-
import com.twitter.clientlib.model.Expansions;
39-
import com.twitter.clientlib.model.GenericProblem;
40-
import com.twitter.clientlib.model.InvalidRequestProblem;
41-
import com.twitter.clientlib.model.ModelList;
42-
import com.twitter.clientlib.model.Problem;
43-
import com.twitter.clientlib.model.ResourceNotFoundProblem;
44-
import com.twitter.clientlib.model.Space;
45-
import com.twitter.clientlib.model.Tweet;
46-
import com.twitter.clientlib.model.User;
37+
import com.twitter.clientlib.model.*;
4738

4839

4940
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
@@ -138,6 +129,20 @@ protected void checkListData(ModelList list) {
138129
Assertions.assertNotNull(list.getFollowerCount());
139130
}
140131

132+
protected void checkComplianceJobData(ComplianceJob complianceJob) {
133+
Assertions.assertNotNull(complianceJob);
134+
Assertions.assertNotNull(complianceJob.getType());
135+
Assertions.assertNotNull(complianceJob.getId());
136+
Assertions.assertNotNull(complianceJob.getCreatedAt());
137+
}
138+
139+
protected void checkModelListData(ModelList modelList) {
140+
Assertions.assertNotNull(modelList);
141+
Assertions.assertNotNull(modelList.getName());
142+
Assertions.assertNotNull(modelList.getId());
143+
Assertions.assertNotNull(modelList.getCreatedAt());
144+
}
145+
141146
protected void checkResourceNotFoundProblem(
142147
Problem problem, String value, String title, String parameter
143148
) {

src/test/java/com/twitter/clientlib/integration/ApiTweetTester.java

+25
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,31 @@ public void usersIdLikeUserNotFoundTest() throws ApiException {
402402
"Invalid Request", "One or more parameters to your request was invalid.");
403403
}
404404

405+
@Test
406+
public void usersIdTimelineTest() throws ApiException {
407+
Get2UsersIdTimelinesReverseChronologicalResponse result = apiInstance.tweets().usersIdTimeline(userId)
408+
.userFields(userFields)
409+
.tweetFields(tweetFields)
410+
.execute();
411+
checkErrors(false, result.getErrors());
412+
assertNotNull(result.getData());
413+
checkTweetData(result.getData().get(0));
414+
assertNull(result.getIncludes());
415+
}
416+
417+
@Test
418+
public void usersIdTimelineErrorTest() throws ApiException {
419+
ApiException exception = assertThrows(ApiException.class, () -> {
420+
apiInstance.tweets().usersIdTimeline(userNotExists)
421+
.userFields(userFields)
422+
.tweetFields(tweetFields)
423+
.execute();
424+
});
425+
checkApiExceptionProblem(exception, InvalidRequestProblem.class,
426+
"The `id` query parameter value [" + userNotExists + "] must be the same as the authenticating user [" + userId + "]",
427+
"Invalid Request", "One or more parameters to your request was invalid.");
428+
}
429+
405430
/* Does not work for now
406431
Streaming
407432
*/

0 commit comments

Comments
 (0)