Skip to content

Commit c7d726b

Browse files
authored
Updating to dropbox-api-spec. July 13, 2022. (#400)
* Updating to latest api spec, July 13, 2022 * Added basic logging to help debugging integration tests. Debugging and stability for Tagging.
1 parent 032148f commit c7d726b

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

scripts/run-integration-tests

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ echo "Running integration tests..."
5151
gradle clean
5252
gradle check
5353

54-
# prepare examples to be run
55-
android_gradle clean
56-
android_gradle assemble
57-
5854
# Run integration tests against major HTTP requestor implementations
59-
for requestor in "StandardHttpRequestor" "OkHttpRequestor" "OkHttp3Requestor" ; do
60-
gradle -Pcom.dropbox.test.httpRequestor="${requestor}" -Pcom.dropbox.test.authInfoFile="${AUTH_FILE}" integrationTest proguardTest
55+
for requestor in "OkHttpRequestor" "OkHttp3Requestor" "StandardHttpRequestor" ; do
56+
gradle -Pcom.dropbox.test.httpRequestor="${requestor}" -Pcom.dropbox.test.authInfoFile="${AUTH_FILE}" integrationTest --info
57+
gradle -Pcom.dropbox.test.httpRequestor="${requestor}" -Pcom.dropbox.test.authInfoFile="${AUTH_FILE}" proguardTest
6158
done
6259

60+
# prepare examples to be run
61+
android_gradle clean
62+
android_gradle assemble

src/test/java/com/dropbox/core/ITUtil.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.squareup.okhttp.OkHttpClient;
2020

21+
import okhttp3.Request;
22+
import okhttp3.Response;
2123
import org.testng.annotations.AfterSuite;
2224
import org.testng.annotations.BeforeSuite;
2325

@@ -48,11 +50,13 @@ public final class ITUtil {
4850
new LocalURLFetchServiceTestConfig());
4951

5052
public static DbxRequestConfig.Builder newRequestConfig() {
53+
HttpRequestor httpRequestor = newHttpRequestor();
54+
System.out.println("Using HttpRequestor of type: " + httpRequestor.getClass().getSimpleName());
5155
return DbxRequestConfig.newBuilder("sdk-integration-test")
5256
// enable auto-retry to avoid flakiness
5357
.withAutoRetryEnabled(MAX_RETRIES)
5458
.withUserLocaleFrom(Locale.US)
55-
.withHttpRequestor(newHttpRequestor());
59+
.withHttpRequestor(httpRequestor);
5660
}
5761

5862
/**
@@ -98,13 +102,25 @@ public static HttpRequestor newHttpRequestor() {
98102
public static OkHttpRequestor newOkHttpRequestor() {
99103
OkHttpClient httpClient = OkHttpRequestor.defaultOkHttpClient().clone();
100104
httpClient.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
105+
httpClient.interceptors().add(chain -> {
106+
com.squareup.okhttp.Request request = chain.request();
107+
com.squareup.okhttp.Response response = chain.proceed(request);
108+
System.out.println(response.code() + " | " + request.method() + " | " + request.url() + " | X-Dropbox-Request-Id: " + response.header("X-Dropbox-Request-Id"));
109+
return response;
110+
});
101111
return new OkHttpRequestor(httpClient);
102112
}
103113

104114
public static OkHttp3Requestor newOkHttp3Requestor() {
105115
okhttp3.OkHttpClient httpClient = OkHttp3Requestor.defaultOkHttpClient().newBuilder()
106-
.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS)
107-
.build();
116+
.addInterceptor(chain -> {
117+
Request request = chain.request();
118+
Response response = chain.proceed(request);
119+
System.out.println(response.code() + " | " + request.method() + " | " + request.url() + " | X-Dropbox-Request-Id: " + response.header("X-Dropbox-Request-Id"));
120+
return response;
121+
})
122+
.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS)
123+
.build();
108124
return new OkHttp3Requestor(httpClient);
109125
}
110126

src/test/java/com/dropbox/core/v2/files/TagObjectIT.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,36 @@ private List<TagObject> getTagsForPath(DbxClientV2 client, String dropboxPath) t
2222
assertEquals(1, pathToTags.size()); // There is only one path (the one we asked for)
2323
PathToTags pathToTag = pathToTags.get(0);
2424
assertEquals(dropboxPath, pathToTag.getPath()); // This is the path we are looking for
25-
System.out.println("Path to Tags: " + pathToTag.getTags());
2625
return pathToTag.getTags();
2726
}
2827

2928
@Test
3029
public void testTagging() throws Exception {
3130
DbxClientV2 client = ITUtil.newClientV2();
3231

33-
int randomInt = new Random().nextInt();
34-
35-
36-
byte[] contents = ("Tagging Test " + randomInt).getBytes();
37-
String dropboxPath = ITUtil.path(getClass(), "/tagging-test-" + randomInt + ".txt");
32+
byte[] contents = ("Tagging Test").getBytes();
33+
String dropboxPath = ITUtil.path(getClass(), "/tagging-test.txt");
3834

3935
// Upload File
4036
client.files().uploadBuilder(dropboxPath)
4137
.withMode(WriteMode.OVERWRITE)
4238
.uploadAndFinish(new ByteArrayInputStream(contents));
39+
Thread.sleep(1000);
4340

4441
// Add Tag "a" to file
4542
client.files().tagsAdd(dropboxPath, "a");
46-
assertEquals("a", getTagsForPath(client, dropboxPath).get(0).getUserGeneratedTagValue().getTagText());
43+
Thread.sleep(1000);
44+
45+
List<TagObject> tagsWithA = getTagsForPath(client, dropboxPath);
46+
assertEquals("a", tagsWithA.get(0).getUserGeneratedTagValue().getTagText());
47+
Thread.sleep(1000);
4748

48-
// Add Tag "b" to file
49-
client.files().tagsAdd(dropboxPath, "b");
50-
List<TagObject> tagsAandB = getTagsForPath(client, dropboxPath);
51-
assertEquals(2, tagsAandB.size());
52-
assertEquals("a", tagsAandB.get(0).getUserGeneratedTagValue().getTagText());
53-
assertEquals("b", tagsAandB.get(1).getUserGeneratedTagValue().getTagText());
5449

5550
// Remove Tag "a" from file
5651
client.files().tagsRemove(dropboxPath, "a");
57-
List<TagObject> tagsJustB = getTagsForPath(client, dropboxPath);
58-
assertEquals(1, tagsJustB.size());
59-
assertEquals("b", tagsJustB.get(0).getUserGeneratedTagValue().getTagText());
60-
61-
// Remove Tag "b" from file
62-
client.files().tagsRemove(dropboxPath, "b");
6352
List<TagObject> tagsNone = getTagsForPath(client, dropboxPath);
6453
assertEquals(0, tagsNone.size());
54+
Thread.sleep(1000);
6555

6656
// Cleanup, delete our test directory.
6757
client.files().deleteV2(dropboxPath);

0 commit comments

Comments
 (0)