Skip to content

Commit

Permalink
Workaround if an object is named "Tag", make it a "TagObject" to avoi…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
handstandsam authored Jul 12, 2022
1 parent 57af1e4 commit 032148f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions generator/java.stoneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ def __init__(self, fq_name, generics=()):
assert isinstance(fq_name, six.text_type), repr(fq_name)
assert isinstance(generics, Sequence), repr(generics)

# Find/Replace ".Tag" with ".TagObject" due to name conflict WEBSERVDB-18031
if fq_name.endswith(".Tag"):
fq_name = fq_name.replace(".Tag", ".TagObject")

self._fq_name = fq_name
self._generics = generics

Expand Down
69 changes: 69 additions & 0 deletions src/test/java/com/dropbox/core/v2/files/TagObjectIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.dropbox.core.v2.files;

import com.dropbox.core.DbxException;
import com.dropbox.core.ITUtil;
import com.dropbox.core.v2.DbxClientV2;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Random;

import static org.testng.AssertJUnit.assertEquals;

/**
* Tests to ensure that the "Tag" related APIs are working. This is important because we have a name conflict
* resolution of changing Tag -> TagObject, and we want to ensure it's working as expected.
*/
public class TagObjectIT {

private List<TagObject> getTagsForPath(DbxClientV2 client, String dropboxPath) throws DbxException {
List<PathToTags> pathToTags = client.files().tagsGet(List.of(dropboxPath)).getPathsToTags();
assertEquals(1, pathToTags.size()); // There is only one path (the one we asked for)
PathToTags pathToTag = pathToTags.get(0);
assertEquals(dropboxPath, pathToTag.getPath()); // This is the path we are looking for
System.out.println("Path to Tags: " + pathToTag.getTags());
return pathToTag.getTags();
}

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

int randomInt = new Random().nextInt();


byte[] contents = ("Tagging Test " + randomInt).getBytes();
String dropboxPath = ITUtil.path(getClass(), "/tagging-test-" + randomInt + ".txt");

// Upload File
client.files().uploadBuilder(dropboxPath)
.withMode(WriteMode.OVERWRITE)
.uploadAndFinish(new ByteArrayInputStream(contents));

// Add Tag "a" to file
client.files().tagsAdd(dropboxPath, "a");
assertEquals("a", getTagsForPath(client, dropboxPath).get(0).getUserGeneratedTagValue().getTagText());

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

// Remove Tag "a" from file
client.files().tagsRemove(dropboxPath, "a");
List<TagObject> tagsJustB = getTagsForPath(client, dropboxPath);
assertEquals(1, tagsJustB.size());
assertEquals("b", tagsJustB.get(0).getUserGeneratedTagValue().getTagText());

// Remove Tag "b" from file
client.files().tagsRemove(dropboxPath, "b");
List<TagObject> tagsNone = getTagsForPath(client, dropboxPath);
assertEquals(0, tagsNone.size());

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

0 comments on commit 032148f

Please sign in to comment.