Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
gradle/
gradlew
gradlew.bat
.gradle/
gradle.properties
build/
Expand Down
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,24 @@ task sourcesJar(type: Jar) {
task integrationTest(type: Test) {
description 'Runs the integration tests.'
group 'Verification'

testLogging.showStandardStreams = true
useJUnit {
includeCategories 'com.box.sdk.IntegrationTest'

}
}

task integrationTestJWT(type: Test) {
description 'Runs the JWT based integration tests.'
group 'Verification'
testLogging.showStandardStreams = true
useJUnit {
includeCategories 'com.box.sdk.IntegrationTestJWT'

}
}


jacocoTestReport.dependsOn(integrationTest);

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -124,6 +136,7 @@ artifacts {
test {
useJUnit {
excludeCategories 'com.box.sdk.IntegrationTest'
excludeCategories 'com.box.sdk.IntegrationTestJWT'
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/box/sdk/BoxFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,13 @@ public void uploadVersion(InputStream fileContent, String fileContentSHA1, Date
request.putField("content_modified_at", modified);
}

BoxAPIResponse response;
BoxJSONResponse response;
if (listener == null) {
response = request.send();
response = (BoxJSONResponse) request.send();
} else {
response = request.send(listener);
response = (BoxJSONResponse) request.send(listener);
}
response.disconnect();
response.getJSON();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/box/sdk/BoxFileVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void promote() {
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "POST");
request.setBody(jsonObject.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
response.disconnect();
this.parseJSON(JsonObject.readFrom(response.getJSON()));
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/box/sdk/BoxAPIConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void successfullySavesAndRestoresConnection() {
}

@Test
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void developerEditionAppAuthWorks() {
final String enterpriseId = TestConfig.getEnterpriseID();
final String clientId = TestConfig.getClientID();
Expand Down Expand Up @@ -253,7 +253,7 @@ public void developerEditionAppAuthWorks() {
}

@Test
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void developerEditionAppUserWorks() {
final String enterpriseId = TestConfig.getEnterpriseID();
final String clientId = TestConfig.getClientID();
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/box/sdk/BoxCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,6 @@ public void getCollectionItemsSucceeds() {

uploadedFile.setCollections(favorites);
assertThat(favorites, hasItem(Matchers.<BoxItem.Info>hasProperty("ID", equalTo(uploadedFile.getID()))));
uploadedFile.delete();
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/box/sdk/BoxFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public void addTaskSucceeds() {
byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
String taskMessage = "Non-empty message";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
Date dueAt = new Date();
Date dueAt = new Date(new Date().getTime() + (1000 * 24 * 60 * 60));

InputStream uploadStream = new ByteArrayInputStream(fileBytes);
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/box/sdk/BoxTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ public void updateInfoSucceeds() {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, 1);
Date dueAt = calendar.getTime();

BoxTask.Info taskInfo = uploadedFile.addTask(BoxTask.Action.REVIEW, originalMessage, dueAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class BoxTransactionalAPIConnectionTest {
@Test
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void successfullyCreatesTransactionalConnection() {
final String transactionalAccessToken = TestConfig.getTransactionalAccessToken();

Expand All @@ -22,7 +22,7 @@ public void successfullyCreatesTransactionalConnection() {
}

@Test
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void successfullyCreatesEmbedLinkWithTransactionalConnection() {
final String transactionalAccessToken = TestConfig.getTransactionalAccessToken();

Expand Down Expand Up @@ -55,7 +55,7 @@ public void successfullyCreatesEmbedLinkWithTransactionalConnection() {
}

@Test
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void successfullyCreatesEmbedLinkWithResourceScopedTransactionalConnection() {
final String transactionalAccessToken = TestConfig.getTransactionalAccessToken();

Expand Down Expand Up @@ -83,7 +83,7 @@ public void successfullyCreatesEmbedLinkWithResourceScopedTransactionalConnectio
}

@Test(expected = BoxAPIException.class)
@Category(IntegrationTest.class)
@Category(IntegrationTestJWT.class)
public void throwsWhenAttemptingToCreatesEmbedLinkWithAnotherFilesResourceScopedTransactionalConnection() {
final String transactionalAccessToken = TestConfig.getTransactionalAccessToken();

Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/box/sdk/BoxUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,10 @@ public void getCurrentUserInfoIsCorrect() throws InterruptedException {
@Category(IntegrationTest.class)
public void createAndDeleteEnterpriseUserSucceeds() {
BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
final String login = "login@box.com";
// Since deleting users happens in a separate process in the backend
// it is really an asynchronous call. So we have to use a new user in
// this test in case the previous user's deletion hasn't completed.
final String login = "login2@boz.com";
final String name = "non-empty name";

BoxUser.Info createdUserInfo = BoxUser.createEnterpriseUser(api, login, name);
Expand Down Expand Up @@ -998,7 +1001,7 @@ public void getMembershipsHasCorrectMemberships() {
@Category(IntegrationTest.class)
public void updateInfoSucceeds() {
BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
final String login = "login@box.com";
final String login = "login3@boz.com";
final String originalName = "original name";
final String updatedName = "updated name";

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/box/sdk/BoxWebHookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void createWebHookFileSucceeds() throws IOException {
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

try {
URL address = new URL("https://0.0.0.0");
URL address = new URL("https://www.google.com");
BoxWebHook.Info info = BoxWebHook.create(uploadedFile, address,
BoxWebHook.Trigger.FILE_PREVIEWED, BoxWebHook.Trigger.FILE_LOCKED);

Expand All @@ -489,7 +489,7 @@ public void createWebHookFolderSucceeds() throws IOException {
BoxFolder folder = rootFolder.createFolder(folderName).getResource();

try {
URL address = new URL("https://0.0.0.0");
URL address = new URL("https://www.google.com");
BoxWebHook.Info info = BoxWebHook.create(folder, address,
BoxWebHook.Trigger.FOLDER_DOWNLOADED, BoxWebHook.Trigger.FOLDER_COPIED);

Expand Down Expand Up @@ -518,7 +518,7 @@ public void listWebHooksSucceeds() throws IOException {
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

try {
URL address = new URL("https://0.0.0.0");
URL address = new URL("https://www.google.com");
BoxWebHook.Info info = BoxWebHook.create(uploadedFile, address, BoxWebHook.Trigger.FILE_PREVIEWED);
Iterable<BoxWebHook.Info> webhooks = BoxWebHook.all(api);

Expand All @@ -545,11 +545,11 @@ public void updateWebHookInfoSucceeds() throws IOException {
BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

try {
URL address = new URL("https://0.0.0.0");
URL address = new URL("https://www.google.com");
BoxWebHook webHook = BoxWebHook.create(uploadedFile, address,
BoxWebHook.Trigger.FILE_PREVIEWED, BoxWebHook.Trigger.FILE_LOCKED).getResource();

URL newAddress = new URL("https://0.0.0.1");
URL newAddress = new URL("https://www.yahoo.com");

BoxWebHook.Info newInfo = webHook.new Info();
newInfo.setTriggers(BoxWebHook.Trigger.FILE_UNLOCKED);
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/box/sdk/EventStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class EventStreamTest {
@Category(IntegrationTest.class)
public void receiveEventsForFolderCreateAndFolderDelete() throws InterruptedException {
final LinkedBlockingQueue<BoxEvent> observedEvents = new LinkedBlockingQueue<BoxEvent>();

BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
EventStream stream = new EventStream(api);
stream.addListener(new EventListener() {
Expand Down Expand Up @@ -60,7 +59,12 @@ public boolean onException(Throwable e) {
boolean deletedEventFound = false;
while (!createdEventFound || !deletedEventFound) {
BoxEvent event = observedEvents.poll(1, TimeUnit.MINUTES);
BoxResource source = event.getSourceInfo().getResource();
BoxResource.Info sourceInfo = event.getSourceInfo();
// Some events may not have sourceInfo
if (sourceInfo == null) {
continue;
}
BoxResource source = sourceInfo.getResource();
if (source instanceof BoxFolder) {
BoxFolder sourceFolder = (BoxFolder) source;
if (sourceFolder.getID().equals(expectedID)) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/box/sdk/IntegrationTestJWT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.box.sdk;

/**
* Created by dmaynard on 2/9/17.
*/
public interface IntegrationTestJWT {
}
3 changes: 2 additions & 1 deletion src/test/java/com/box/sdk/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class TestConfig {

private TestConfig() { }

public static void setLogLevel(String levelString) {
public static Logger enableLogger(String levelString) {
Level level = Level.parse(levelString);
Logger logger = Logger.getLogger("com.box.sdk");
logger.setLevel(level);
Expand All @@ -43,6 +43,7 @@ public static void setLogLevel(String levelString) {
handler.setLevel(level);
logger.addHandler(handler);
}
return logger;
}

public static String getAccessToken() {
Expand Down