Skip to content

Commit 032148f

Browse files
authored
Workaround if an object is named "Tag", make it a "TagObject" to avoid compile errors. Fixes https://jira.dropboxer.net/browse/WEBSERVDB-18031 (#396)
Updating Target SDK API Versions. Added integration test for Tags. Make sure we do a cleanup after tests. Updated checks/javadoc and improved naming of variables. Reverting some of my aggressive test changes.
1 parent 57af1e4 commit 032148f

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

generator/java.stoneg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ def __init__(self, fq_name, generics=()):
339339
assert isinstance(fq_name, six.text_type), repr(fq_name)
340340
assert isinstance(generics, Sequence), repr(generics)
341341

342+
# Find/Replace ".Tag" with ".TagObject" due to name conflict WEBSERVDB-18031
343+
if fq_name.endswith(".Tag"):
344+
fq_name = fq_name.replace(".Tag", ".TagObject")
345+
342346
self._fq_name = fq_name
343347
self._generics = generics
344348

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.dropbox.core.v2.files;
2+
3+
import com.dropbox.core.DbxException;
4+
import com.dropbox.core.ITUtil;
5+
import com.dropbox.core.v2.DbxClientV2;
6+
import org.testng.annotations.Test;
7+
8+
import java.io.ByteArrayInputStream;
9+
import java.util.List;
10+
import java.util.Random;
11+
12+
import static org.testng.AssertJUnit.assertEquals;
13+
14+
/**
15+
* Tests to ensure that the "Tag" related APIs are working. This is important because we have a name conflict
16+
* resolution of changing Tag -> TagObject, and we want to ensure it's working as expected.
17+
*/
18+
public class TagObjectIT {
19+
20+
private List<TagObject> getTagsForPath(DbxClientV2 client, String dropboxPath) throws DbxException {
21+
List<PathToTags> pathToTags = client.files().tagsGet(List.of(dropboxPath)).getPathsToTags();
22+
assertEquals(1, pathToTags.size()); // There is only one path (the one we asked for)
23+
PathToTags pathToTag = pathToTags.get(0);
24+
assertEquals(dropboxPath, pathToTag.getPath()); // This is the path we are looking for
25+
System.out.println("Path to Tags: " + pathToTag.getTags());
26+
return pathToTag.getTags();
27+
}
28+
29+
@Test
30+
public void testTagging() throws Exception {
31+
DbxClientV2 client = ITUtil.newClientV2();
32+
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");
38+
39+
// Upload File
40+
client.files().uploadBuilder(dropboxPath)
41+
.withMode(WriteMode.OVERWRITE)
42+
.uploadAndFinish(new ByteArrayInputStream(contents));
43+
44+
// Add Tag "a" to file
45+
client.files().tagsAdd(dropboxPath, "a");
46+
assertEquals("a", getTagsForPath(client, dropboxPath).get(0).getUserGeneratedTagValue().getTagText());
47+
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());
54+
55+
// Remove Tag "a" from file
56+
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");
63+
List<TagObject> tagsNone = getTagsForPath(client, dropboxPath);
64+
assertEquals(0, tagsNone.size());
65+
66+
// Cleanup, delete our test directory.
67+
client.files().deleteV2(dropboxPath);
68+
}
69+
}

0 commit comments

Comments
 (0)