Skip to content

Commit

Permalink
chore: fixed BoxCommentIT tests (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
antusus authored Nov 10, 2022
1 parent 29e9b75 commit f16515d
Showing 1 changed file with 61 additions and 39 deletions.
100 changes: 61 additions & 39 deletions src/intTest/java/com/box/sdk/BoxCommentIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,116 @@

import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount;
import static com.box.sdk.CleanupTools.deleteFile;
import static com.box.sdk.UniqueTestFolder.getUniqueFolder;
import static com.box.sdk.UniqueTestFolder.randomizeName;
import static com.box.sdk.UniqueTestFolder.removeUniqueFolder;
import static com.box.sdk.UniqueTestFolder.setupUniqeFolder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class BoxCommentIT {

@BeforeClass
public static void setup() {
setupUniqeFolder();
}

@AfterClass
public static void tearDown() {
removeUniqueFolder();
}
@Test
public void replyToCommentSucceeds() {
BoxAPIConnection api = jwtApiForServiceAccount();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
String fileName = "[replyToCommentSucceeds] Test File.txt";
BoxFolder rootFolder = getUniqueFolder(api);
String fileName = randomizeName("[replyToCommentSucceeds] Test File.txt");
byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
String firstMessage = "First message";
String replyMessage = "Reply message";

InputStream uploadStream = new ByteArrayInputStream(fileBytes);
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

BoxComment.Info firstCommentInfo = uploadedFile.addComment(firstMessage);
BoxComment firstComment = firstCommentInfo.getResource();

BoxComment.Info replyCommentInfo = firstComment.reply(replyMessage);

assertThat(replyCommentInfo.getMessage(), is(equalTo(replyMessage)));
assertThat(replyCommentInfo.getIsReplyComment(), is(true));
assertThat(replyCommentInfo.getItem().getID(), is(equalTo(uploadedFile.getID())));

deleteFile(uploadedFile);
try {
BoxComment.Info firstCommentInfo = uploadedFile.addComment(firstMessage);
BoxComment firstComment = firstCommentInfo.getResource();

BoxComment.Info replyCommentInfo = firstComment.reply(replyMessage);

assertThat(replyCommentInfo.getMessage(), is(equalTo(replyMessage)));
assertThat(replyCommentInfo.getIsReplyComment(), is(true));
assertThat(replyCommentInfo.getItem().getID(), is(equalTo(uploadedFile.getID())));
} finally {
deleteFile(uploadedFile);
}
}

@Test
public void getCommentInfoSucceeds() {
BoxAPIConnection api = jwtApiForServiceAccount();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
String fileName = "[getCommentInfoSucceeds] Test File.txt";
BoxFolder rootFolder = getUniqueFolder(api);
String fileName = randomizeName("[getCommentInfoSucceeds] Test File.txt");
byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
String message = "Comment message";

InputStream uploadStream = new ByteArrayInputStream(fileBytes);
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
BoxComment.Info commentInfo = uploadedFile.addComment(message);
BoxComment comment = commentInfo.getResource();
commentInfo = comment.getInfo();

assertThat(commentInfo.getMessage(), is(equalTo(message)));
assertThat(commentInfo.getItem().getID(), is(equalTo(uploadedFile.getID())));

deleteFile(uploadedFile);
try {
BoxComment.Info commentInfo = uploadedFile.addComment(message);
BoxComment comment = commentInfo.getResource();
commentInfo = comment.getInfo();

assertThat(commentInfo.getMessage(), is(equalTo(message)));
assertThat(commentInfo.getItem().getID(), is(equalTo(uploadedFile.getID())));
} finally {
deleteFile(uploadedFile);
}
}

@Test
public void changeCommentMessageSucceeds() {
BoxAPIConnection api = jwtApiForServiceAccount();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
String fileName = "[changeCommentMessageSucceeds] Test File.txt";
BoxFolder rootFolder = getUniqueFolder(api);
String fileName = randomizeName("[changeCommentMessageSucceeds] Test File.txt");
byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
String originalMessage = "Original message";
String changedMessage = "Changed message";

InputStream uploadStream = new ByteArrayInputStream(fileBytes);
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
BoxComment.Info commentInfo = uploadedFile.addComment(originalMessage);
BoxComment comment = commentInfo.getResource();
commentInfo = comment.changeMessage(changedMessage);

assertThat(commentInfo.getMessage(), is(equalTo(changedMessage)));

deleteFile(uploadedFile);
try {
BoxComment.Info commentInfo = uploadedFile.addComment(originalMessage);
BoxComment comment = commentInfo.getResource();
commentInfo = comment.changeMessage(changedMessage);

assertThat(commentInfo.getMessage(), is(equalTo(changedMessage)));
} finally {
deleteFile(uploadedFile);
}
}

@Test
public void deleteCommentSucceeds() {
BoxAPIConnection api = jwtApiForServiceAccount();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
String fileName = "[deleteCommentSucceeds] Test File.txt";
BoxFolder rootFolder = getUniqueFolder(api);
String fileName = randomizeName("[deleteCommentSucceeds] Test File.txt");
byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
String message = "Comment message";

InputStream uploadStream = new ByteArrayInputStream(fileBytes);
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
BoxComment.Info commentInfo = uploadedFile.addComment(message);
BoxComment comment = commentInfo.getResource();
comment.delete();

deleteFile(uploadedFile);
try {
BoxComment.Info commentInfo = uploadedFile.addComment(message);
BoxComment comment = commentInfo.getResource();
comment.delete();
} finally {
deleteFile(uploadedFile);
}
}
}

0 comments on commit f16515d

Please sign in to comment.