You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/03/06 08:36:24 UTC
[4/8] camel git commit: CAMEL-9047: Replace deprecated boxjavalibv2
with box-java-sdk
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2CommentsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2CommentsManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2CommentsManagerIntegrationTest.java
new file mode 100644
index 0000000..39cbf1e
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2CommentsManagerIntegrationTest.java
@@ -0,0 +1,201 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxComment;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2CommentsManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for
+ * {@link org.apache.camel.component.box2.api.Box2CommentsManager} APIs.
+ */
+public class Box2CommentsManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2CommentsManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2CommentsManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_FILE = "/CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_NAME = "CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_COMMENT = "CamelTestFile comment.";
+ private static final String CAMEL_TEST_FILE_CHANGED_COMMENT = "CamelTestFile changed comment.";
+ private static final String CAMEL_TEST_FILE_REPLY_COMMENT = "CamelTestFile changed comment.";
+
+ private BoxFile testFile;
+
+ @Test
+ public void testAddFileComment() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String
+ headers.put("CamelBox2.message", CAMEL_TEST_FILE_COMMENT);
+
+ final com.box.sdk.BoxFile result = requestBodyAndHeaders("direct://ADDFILECOMMENT", null, headers);
+
+ assertNotNull("addFileComment result", result);
+ assertNotNull("addFileComment comments", result.getComments());
+ assertTrue("changeCommentMessage comments size", result.getComments().size() > 0);
+ assertEquals("changeCommentMessage comment message", CAMEL_TEST_FILE_COMMENT,
+ result.getComments().get(0).getMessage());
+ LOG.debug("addFileComment: " + result);
+ }
+
+ @Test
+ public void testChangeCommentMessage() throws Exception {
+
+ BoxComment.Info commentInfo = testFile.addComment(CAMEL_TEST_FILE_COMMENT);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.commentId", commentInfo.getID());
+ // parameter type is String
+ headers.put("CamelBox2.message", CAMEL_TEST_FILE_CHANGED_COMMENT);
+
+ final com.box.sdk.BoxComment result = requestBodyAndHeaders("direct://CHANGECOMMENTMESSAGE", null, headers);
+
+ assertNotNull("changeCommentMessage result", result);
+ assertNotNull("changeCommentMessage message", result.getInfo().getMessage());
+ assertEquals("changeCommentMessage message", CAMEL_TEST_FILE_CHANGED_COMMENT, result.getInfo().getMessage());
+ LOG.debug("changeCommentMessage: " + result);
+ }
+
+ @Test
+ public void testDeleteComment() throws Exception {
+ BoxComment.Info commentInfo = testFile.addComment(CAMEL_TEST_FILE_COMMENT);
+
+ // using String message body for single parameter "commentId"
+ requestBody("direct://DELETECOMMENT", commentInfo.getID());
+
+ List<BoxComment.Info> comments = testFile.getComments();
+ assertNotNull("deleteComment comments", comments);
+ assertEquals("deleteComment comments empty", 0, comments.size());
+ }
+
+ @Test
+ public void testGetCommentInfo() throws Exception {
+
+ BoxComment.Info commentInfo = testFile.addComment(CAMEL_TEST_FILE_COMMENT);
+
+ // using String message body for single parameter "commentId"
+ final com.box.sdk.BoxComment.Info result = requestBody("direct://GETCOMMENTINFO", commentInfo.getID());
+
+ assertNotNull("getCommentInfo result", result);
+ assertEquals("getCommentInfo message", CAMEL_TEST_FILE_COMMENT, result.getMessage());
+ LOG.debug("getCommentInfo: " + result);
+ }
+
+ @Test
+ public void testGetFileComments() throws Exception {
+ testFile.addComment(CAMEL_TEST_FILE_COMMENT);
+
+ // using String message body for single parameter "fileId"
+ @SuppressWarnings("rawtypes")
+ final java.util.List result = requestBody("direct://GETFILECOMMENTS", testFile.getID());
+
+ assertNotNull("getFileComments result", result);
+ assertEquals("getFileComments size", 1, result.size());
+ LOG.debug("getFileComments: " + result);
+ }
+
+ @Test
+ public void testReplyToComment() throws Exception {
+
+ BoxComment.Info commentInfo = testFile.addComment(CAMEL_TEST_FILE_COMMENT);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.commentId", commentInfo.getID());
+ // parameter type is String
+ headers.put("CamelBox2.message", CAMEL_TEST_FILE_REPLY_COMMENT);
+
+ final com.box.sdk.BoxComment result = requestBodyAndHeaders("direct://REPLYTOCOMMENT", null, headers);
+
+ assertNotNull("replyToComment result", result);
+ assertEquals("replyToComment result", CAMEL_TEST_FILE_REPLY_COMMENT, result.getInfo().getMessage());
+ LOG.debug("replyToComment: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for addFileComment
+ from("direct://ADDFILECOMMENT").to("box2://" + PATH_PREFIX + "/addFileComment");
+
+ // test route for changeCommentMessage
+ from("direct://CHANGECOMMENTMESSAGE").to("box2://" + PATH_PREFIX + "/changeCommentMessage");
+
+ // test route for deleteComment
+ from("direct://DELETECOMMENT").to("box2://" + PATH_PREFIX + "/deleteComment?inBody=commentId");
+
+ // test route for getCommentInfo
+ from("direct://GETCOMMENTINFO").to("box2://" + PATH_PREFIX + "/getCommentInfo?inBody=commentId");
+
+ // test route for getFileComments
+ from("direct://GETFILECOMMENTS").to("box2://" + PATH_PREFIX + "/getFileComments?inBody=fileId");
+
+ // test route for replyToComment
+ from("direct://REPLYTOCOMMENT").to("box2://" + PATH_PREFIX + "/replyToComment");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestFile();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestFile();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/addFileComment");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestFile() throws FileNotFoundException {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
+ testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
+ }
+
+ private void deleteTestFile() {
+ testFile.delete();
+ testFile = null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventLogsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventLogsManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventLogsManagerIntegrationTest.java
new file mode 100644
index 0000000..deb502e
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventLogsManagerIntegrationTest.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2EventLogsManagerApiMethod;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for
+ * {@link org.apache.camel.component.box2.api.Box2EventLogsManager} APIs.
+ */
+public class Box2EventLogsManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2EventLogsManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2EventLogsManagerApiMethod.class).getName();
+ private static final long ONE_MINUTE_OF_MILLISECONDS = 1000 * 60;
+
+ @Ignore // Requires enterprise admin account to test
+ @Test
+ public void testGetEnterpriseEvents() throws Exception {
+ Date before = new Date();
+ Date after = new Date();
+ after.setTime(before.getTime() - ONE_MINUTE_OF_MILLISECONDS);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.position", null);
+ // parameter type is java.util.Date
+ headers.put("CamelBox2.after", after);
+ // parameter type is java.util.Date
+ headers.put("CamelBox2.before", before);
+ // parameter type is com.box.sdk.BoxEvent.Type[]
+ headers.put("CamelBox2.types", null);
+
+ @SuppressWarnings("rawtypes")
+ final java.util.List result = requestBodyAndHeaders("direct://GETENTERPRISEEVENTS", null, headers);
+
+ assertNotNull("getEnterpriseEvents result", result);
+ LOG.debug("getEnterpriseEvents: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for getEnterpriseEvents
+ from("direct://GETENTERPRISEEVENTS").to("box2://" + PATH_PREFIX + "/getEnterpriseEvents");
+
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventsManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventsManagerIntegrationTest.java
new file mode 100644
index 0000000..3af1b68
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2EventsManagerIntegrationTest.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2EventsManagerApiMethod;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2EventsManager}
+ * APIs. TODO Move the file to src/test/java, populate parameter values, and
+ * remove @Ignore annotations. The class source won't be generated again if the
+ * generator MOJO finds it under src/test/java.
+ */
+public class Box2EventsManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2EventsManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2EventsManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_FILE = "/CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_NAME = "CamelTestFile.txt";
+
+ private BoxFile testFile;
+
+ @Test
+ public void testListen() throws Exception {
+ try {
+ // generate a file create event
+ createTestFile();
+ } finally {
+ // generate a file delete event
+ deleteTestFile();
+ }
+
+ MockEndpoint mockEndpoint = getMockEndpoint("mock:box2Events");
+ mockEndpoint.expectedMinimumMessageCount(2);
+ mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30, TimeUnit.SECONDS));
+ mockEndpoint.assertIsSatisfied();
+
+ final List<Exchange> exchanges = mockEndpoint.getExchanges();
+ assertNotNull("poll result", exchanges);
+ assertFalse("poll result", exchanges.isEmpty());
+ LOG.debug("poll result: " + exchanges);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+
+ // test route for events
+ from("box2://" + PATH_PREFIX + "/listen?startingPosition=0").to("mock:box2Events");
+
+ }
+ };
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context()
+ .getEndpoint("box2://" + PATH_PREFIX + "/listen?startingPosition=0");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestFile() throws FileNotFoundException {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
+ testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
+ }
+
+ private void deleteTestFile() {
+ try {
+ testFile.delete();
+ } catch (Throwable t) {
+ }
+ testFile = null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FilesManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FilesManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FilesManagerIntegrationTest.java
new file mode 100644
index 0000000..ecf6677
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FilesManagerIntegrationTest.java
@@ -0,0 +1,575 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxAPIException;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFile.ThumbnailFileType;
+import com.box.sdk.BoxFolder;
+import com.box.sdk.BoxItem;
+import com.box.sdk.BoxSharedLink;
+import com.box.sdk.Metadata;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2FilesManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2FilesManager}
+ * APIs.
+ */
+public class Box2FilesManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2FilesManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2FilesManagerApiMethod.class).getName();
+
+ private static final String CAMEL_TEST_FILE = "/CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_NAME = "CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_DESCRIPTION = "CamelTestFile.txt description";
+ private static final String CAMEL_TEST_COPY_FILE_NAME = "CamelTestFile_Copy.txt";
+ private static final String CAMEL_TEST_MOVE_FILE_NAME = "CamelTestFile_Move.txt";
+ private static final String CAMEL_TEST_RENAME_FILE_NAME = "CamelTestFile_Rename.txt";
+ private static final String CAMEL_TEST_UPLOAD_FILE_NAME = "CamelTestFile_Upload.txt";
+
+ private BoxFile testFile;
+
+ @Test
+ public void testCopyFile() throws Exception {
+ com.box.sdk.BoxFile result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String
+ headers.put("CamelBox2.destinationFolderId", "0");
+ // parameter type is String
+ headers.put("CamelBox2.newName", CAMEL_TEST_COPY_FILE_NAME);
+
+ result = requestBodyAndHeaders("direct://COPYFILE", null, headers);
+
+ assertNotNull("copyFile result", result);
+ assertEquals("copyFile name", CAMEL_TEST_COPY_FILE_NAME, result.getInfo().getName());
+ LOG.debug("copyFile: " + result);
+ } finally {
+ if (result != null) {
+ result.delete();
+ }
+ }
+ }
+
+ @Test
+ public void testCreateFileMetadata() throws Exception {
+ Metadata metadata = new Metadata();
+ metadata.add("/foo", "bar");
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.Metadata
+ headers.put("CamelBox2.metadata", metadata);
+ // parameter type is String
+ headers.put("CamelBox2.typeName", null);
+
+ final com.box.sdk.Metadata result = requestBodyAndHeaders("direct://CREATEFILEMETADATA", null, headers);
+
+ assertNotNull("createFileMetadata result", result);
+ assertEquals("createFileMetadata result", "bar", result.get("/foo"));
+ LOG.debug("createFileMetadata: " + result);
+ }
+
+ @Test
+ public void testCreateFileSharedLink() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.BoxSharedLink.Access
+ headers.put("CamelBox2.access", BoxSharedLink.Access.DEFAULT);
+ // parameter type is java.util.Date
+ headers.put("CamelBox2.unshareDate", null);
+ // parameter type is com.box.sdk.BoxSharedLink.Permissions
+ headers.put("CamelBox2.permissions", null);
+
+ final com.box.sdk.BoxSharedLink result = requestBodyAndHeaders("direct://CREATEFILESHAREDLINK", null, headers);
+
+ assertNotNull("createFileSharedLink result", result);
+ LOG.debug("createFileSharedLink: " + result);
+ }
+
+ @Test
+ public void testDeleteFile() throws Exception {
+ // using String message body for single parameter "fileId"
+ requestBody("direct://DELETEFILE", testFile.getID());
+
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ Iterable<BoxItem.Info> it = rootFolder.search("^" + CAMEL_TEST_FILE + "$");
+ int searchResults = sizeOfIterable(it);
+ boolean exists = searchResults > 0 ? true : false;
+ assertEquals("deleteFile exists", false, exists);
+ LOG.debug("deleteFile: exists? " + exists);
+
+ }
+
+ @Test
+ public void testDeleteFileMetadata() throws Exception {
+ testFile.createMetadata(new Metadata());
+
+ // using String message body for single parameter "fileId"
+ requestBody("direct://DELETEFILEMETADATA", testFile.getID());
+
+ try {
+ testFile.getMetadata();
+ } catch (BoxAPIException e) {
+ if (e.getResponseCode() == 404) {
+ // Box API should return a
+ return;
+ }
+ }
+ fail("deleteFileMetadata metadata");
+
+ }
+
+ @Ignore // Requires premium user account to test.
+ @Test
+ public void testDeleteFileVersion() throws Exception {
+ testFile.uploadVersion(getClass().getResourceAsStream(CAMEL_TEST_FILE));
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is Integer
+ headers.put("CamelBox2.version", 0);
+
+ requestBodyAndHeaders("direct://DELETEFILEVERSION", null, headers);
+ boolean onlyOneVersion = testFile.getVersions().size() == 1;
+ assertTrue("deleteFileVersion version deleted", onlyOneVersion);
+ }
+
+ @Test
+ public void testDownloadFile() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is java.io.OutputStream
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ headers.put("CamelBox2.output", output);
+ // parameter type is Long
+ headers.put("CamelBox2.rangeStart", null);
+ // parameter type is Long
+ headers.put("CamelBox2.rangeEnd", null);
+ // parameter type is com.box.sdk.ProgressListener
+ headers.put("CamelBox2.listener", null);
+
+ final java.io.OutputStream result = requestBodyAndHeaders("direct://DOWNLOADFILE", null, headers);
+
+ assertNotNull("downloadFile result", result);
+ LOG.debug("downloadFile: " + result);
+ }
+
+ @Ignore // Requires premium user account to test
+ @Test
+ public void testDownloadPreviousFileVersion() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is Integer
+ headers.put("CamelBox2.version", 0);
+ // parameter type is java.io.OutputStream
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ headers.put("CamelBox2.output", output);
+ // parameter type is com.box.sdk.ProgressListener
+ headers.put("CamelBox2.listener", null);
+
+ final java.io.OutputStream result = requestBodyAndHeaders("direct://DOWNLOADPREVIOUSFILEVERSION", null,
+ headers);
+
+ assertNotNull("downloadPreviousFileVersion result", result);
+ LOG.debug("downloadPreviousFileVersion: " + result);
+ }
+
+ @Test
+ public void testGetDownloadURL() throws Exception {
+ // using String message body for single parameter "fileId"
+ final java.net.URL result = requestBody("direct://GETDOWNLOADURL", testFile.getID());
+
+ assertNotNull("getDownloadURL result", result);
+ LOG.debug("getDownloadURL: " + result);
+ }
+
+ @Test
+ public void testGetFileInfo() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String[]
+ headers.put("CamelBox2.fields", null);
+
+ final com.box.sdk.BoxFile.Info result = requestBodyAndHeaders("direct://GETFILEINFO", null, headers);
+
+ assertNotNull("getFileInfo result", result);
+ LOG.debug("getFileInfo: " + result);
+ }
+
+ @Test
+ public void testGetFileMetadata() throws Exception {
+ testFile.createMetadata(new Metadata());
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String
+ headers.put("CamelBox2.typeName", null);
+
+ final com.box.sdk.Metadata result = requestBodyAndHeaders("direct://GETFILEMETADATA", null, headers);
+
+ assertNotNull("getFileMetadata result", result);
+ LOG.debug("getFileMetadata: " + result);
+ }
+
+ @Test
+ public void testGetFilePreviewLink() throws Exception {
+ // using String message body for single parameter "fileId"
+ final java.net.URL result = requestBody("direct://GETFILEPREVIEWLINK", testFile.getID());
+
+ assertNotNull("getFilePreviewLink result", result);
+ LOG.debug("getFilePreviewLink: " + result);
+ }
+
+ @Test
+ public void testGetFileThumbnail() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.BoxFile.ThumbnailFileType
+ headers.put("CamelBox2.fileType", ThumbnailFileType.JPG);
+ // parameter type is Integer
+ headers.put("CamelBox2.minWidth", 32);
+ // parameter type is Integer
+ headers.put("CamelBox2.minHeight", 32);
+ // parameter type is Integer
+ headers.put("CamelBox2.maxWidth", 32);
+ // parameter type is Integer
+ headers.put("CamelBox2.maxHeight", 32);
+
+ final byte[] result = requestBodyAndHeaders("direct://GETFILETHUMBNAIL", null, headers);
+
+ assertNotNull("getFileThumbnail result", result);
+ LOG.debug("getFileThumbnail: " + result);
+ }
+
+ @Test
+ public void testGetFileVersions() throws Exception {
+ // using String message body for single parameter "fileId"
+ @SuppressWarnings("rawtypes")
+ final java.util.Collection result = requestBody("direct://GETFILEVERSIONS", testFile.getID());
+
+ assertNotNull("getFileVersions result", result);
+ LOG.debug("getFileVersions: " + result);
+ }
+
+ @Test
+ public void testMoveFile() throws Exception {
+ com.box.sdk.BoxFile result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String
+ headers.put("CamelBox2.destinationFolderId", "0");
+ // parameter type is String
+ headers.put("CamelBox2.newName", CAMEL_TEST_MOVE_FILE_NAME);
+
+ result = requestBodyAndHeaders("direct://MOVEFILE", null, headers);
+
+ assertNotNull("moveFile result", result);
+ assertEquals("moveFile name", CAMEL_TEST_MOVE_FILE_NAME, result.getInfo().getName());
+ LOG.debug("moveFile: " + result);
+ } finally {
+ if (result != null) {
+ result.delete();
+ }
+ }
+ }
+
+ @Ignore // Requires premium user account to test
+ @Test
+ public void testPromoteFileVersion() throws Exception {
+ testFile.uploadVersion(getClass().getResourceAsStream(CAMEL_TEST_FILE));
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is Integer
+ headers.put("CamelBox2.version", 1);
+
+ final com.box.sdk.BoxFileVersion result = requestBodyAndHeaders("direct://PROMOTEFILEVERSION", null, headers);
+
+ assertNotNull("promoteFileVersion result", result);
+ LOG.debug("promoteFileVersion: " + result);
+ }
+
+ @Test
+ public void testRenameFile() throws Exception {
+
+ com.box.sdk.BoxFile result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is String
+ headers.put("CamelBox2.newFileName", CAMEL_TEST_RENAME_FILE_NAME);
+
+ result = requestBodyAndHeaders("direct://RENAMEFILE", null, headers);
+
+ assertNotNull("renameFile result", result);
+ assertEquals("renameFile name", CAMEL_TEST_RENAME_FILE_NAME, result.getInfo().getName());
+ LOG.debug("renameFile: " + result);
+ } finally {
+ if (result != null) {
+ result.delete();
+ }
+ }
+ }
+
+ @Test
+ public void testUpdateFileInfo() throws Exception {
+ BoxFile.Info info = testFile.getInfo();
+ info.setDescription(CAMEL_TEST_FILE_DESCRIPTION);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.BoxFile.Info
+ headers.put("CamelBox2.info", info);
+
+ final com.box.sdk.BoxFile result = requestBodyAndHeaders("direct://UPDATEFILEINFO", null, headers);
+
+ assertNotNull("updateFileInfo result", result);
+ assertEquals("updateFileInfo info", CAMEL_TEST_FILE_DESCRIPTION, result.getInfo().getDescription());
+ LOG.debug("updateFileInfo: " + result);
+ }
+
+ @Test
+ public void testUpdateFileMetadata() throws Exception {
+ Metadata metadata = new Metadata();
+ // metadata.add("/foo", "bar");
+ metadata = testFile.createMetadata(metadata);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.Metadata
+ headers.put("CamelBox2.metadata", metadata);
+
+ final com.box.sdk.Metadata result = requestBodyAndHeaders("direct://UPDATEFILEMETADATA", null, headers);
+
+ assertNotNull("updateFileMetadata result", result);
+ LOG.debug("updateFileMetadata: " + result);
+ }
+
+ @Ignore
+ @Test
+ public void testUploadFile() throws Exception {
+ com.box.sdk.BoxFile result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put("CamelBox2.parentFolderId", "0");
+ headers.put("CamelBox2.content", getClass().getResourceAsStream(CAMEL_TEST_FILE));
+ headers.put("CamelBox2.fileName", CAMEL_TEST_UPLOAD_FILE_NAME);
+ headers.put("CamelBox2.created", null);
+ headers.put("CamelBox2.modified", null);
+ headers.put("CamelBox2.size", null);
+ headers.put("CamelBox2.listener", null);
+
+ result = requestBodyAndHeaders("direct://UPLOADFILE", null, headers);
+
+ assertNotNull("uploadFile result", result);
+ LOG.debug("uploadFile: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ result.delete();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testUploadNewFileVersion() throws Exception {
+ com.box.sdk.BoxFile result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is java.io.InputStream
+ headers.put("CamelBox2.fileContent", getClass().getResourceAsStream(CAMEL_TEST_FILE));
+ // parameter type is java.util.Date
+ headers.put("CamelBox2.modified", null);
+ // parameter type is Long
+ headers.put("CamelBox2.fileSize", null);
+ // parameter type is com.box.sdk.ProgressListener
+ headers.put("CamelBox2.listener", null);
+
+ result = requestBodyAndHeaders("direct://UPLOADNEWFILEVERSION", null, headers);
+
+ assertNotNull("uploadNewFileVersion result", result);
+ LOG.debug("uploadNewFileVersion: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ result.delete();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for copyFile
+ from("direct://COPYFILE").to("box2://" + PATH_PREFIX + "/copyFile");
+
+ // test route for createFileMetadata
+ from("direct://CREATEFILEMETADATA").to("box2://" + PATH_PREFIX + "/createFileMetadata");
+
+ // test route for createFileSharedLink
+ from("direct://CREATEFILESHAREDLINK").to("box2://" + PATH_PREFIX + "/createFileSharedLink");
+
+ // test route for deleteFile
+ from("direct://DELETEFILE").to("box2://" + PATH_PREFIX + "/deleteFile?inBody=fileId");
+
+ // test route for deleteFileMetadata
+ from("direct://DELETEFILEMETADATA").to("box2://" + PATH_PREFIX + "/deleteFileMetadata?inBody=fileId");
+
+ // test route for deleteFileVersion
+ from("direct://DELETEFILEVERSION").to("box2://" + PATH_PREFIX + "/deleteFileVersion");
+
+ // test route for downloadFile
+ from("direct://DOWNLOADFILE").to("box2://" + PATH_PREFIX + "/downloadFile");
+
+ // test route for downloadPreviousFileVersion
+ from("direct://DOWNLOADPREVIOUSFILEVERSION")
+ .to("box2://" + PATH_PREFIX + "/downloadPreviousFileVersion");
+
+ // test route for getDownloadURL
+ from("direct://GETDOWNLOADURL").to("box2://" + PATH_PREFIX + "/getDownloadURL?inBody=fileId");
+
+ // test route for getFileInfo
+ from("direct://GETFILEINFO").to("box2://" + PATH_PREFIX + "/getFileInfo");
+
+ // test route for getFileMetadata
+ from("direct://GETFILEMETADATA").to("box2://" + PATH_PREFIX + "/getFileMetadata");
+
+ // test route for getFilePreviewLink
+ from("direct://GETFILEPREVIEWLINK").to("box2://" + PATH_PREFIX + "/getFilePreviewLink?inBody=fileId");
+
+ // test route for getFileThumbnail
+ from("direct://GETFILETHUMBNAIL").to("box2://" + PATH_PREFIX + "/getFileThumbnail");
+
+ // test route for getFileVersions
+ from("direct://GETFILEVERSIONS").to("box2://" + PATH_PREFIX + "/getFileVersions?inBody=fileId");
+
+ // test route for moveFile
+ from("direct://MOVEFILE").to("box2://" + PATH_PREFIX + "/moveFile");
+
+ // test route for promoteFileVersion
+ from("direct://PROMOTEFILEVERSION").to("box2://" + PATH_PREFIX + "/promoteFileVersion");
+
+ // test route for renameFile
+ from("direct://RENAMEFILE").to("box2://" + PATH_PREFIX + "/renameFile");
+
+ // test route for updateFileInfo
+ from("direct://UPDATEFILEINFO").to("box2://" + PATH_PREFIX + "/updateFileInfo");
+
+ // test route for updateFileMetadata
+ from("direct://UPDATEFILEMETADATA").to("box2://" + PATH_PREFIX + "/updateFileMetadata");
+
+ // test route for uploadFile
+ from("direct://UPLOADFILE").to("box2://" + PATH_PREFIX + "/uploadFile");
+
+ // test route for uploadNewFileVersion
+ from("direct://UPLOADNEWFILEVERSION").to("box2://" + PATH_PREFIX + "/uploadNewFileVersion");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestFile();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestFile();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/copyFile");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestFile() throws FileNotFoundException {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
+ testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
+ }
+
+ private void deleteTestFile() {
+ try {
+ testFile.delete();
+ } catch (Throwable t) {
+ }
+ testFile = null;
+ }
+
+ private int sizeOfIterable(Iterable<?> it) {
+ if (it instanceof Collection) {
+ return ((Collection<?>) it).size();
+ } else {
+ int i = 0;
+ for (@SuppressWarnings("unused")
+ Object obj : it) {
+ i++;
+ }
+ return i;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FoldersManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FoldersManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FoldersManagerIntegrationTest.java
new file mode 100644
index 0000000..92a5765
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2FoldersManagerIntegrationTest.java
@@ -0,0 +1,322 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFolder;
+import com.box.sdk.BoxItem;
+import com.box.sdk.BoxSharedLink;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2FoldersManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2FoldersManager}
+ * APIs.
+ */
+public class Box2FoldersManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2FoldersManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2FoldersManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_FOLDER = "CamelTestFolder";
+ private static final String CAMEL_TEST_FOLDER_DESCRIPTION = "This is a description of CamelTestFolder";
+ private static final String CAMEL_TEST_COPY_FOLDER = Box2FoldersManagerIntegrationTest.CAMEL_TEST_FOLDER + "_Copy";
+ private static final String CAMEL_TEST_MOVE_FOLDER = Box2FoldersManagerIntegrationTest.CAMEL_TEST_FOLDER + "_Move";
+ private static final String CAMEL_TEST_RENAME_FOLDER = Box2FoldersManagerIntegrationTest.CAMEL_TEST_FOLDER
+ + "_Rename";
+ private static final String CAMEL_TEST_ROOT_FOLDER_ID = "0";
+ private static final String CAMEL_TEST_DESTINATION_FOLDER_ID = "0";
+
+ private BoxFolder testFolder;
+
+ @Test
+ public void testCreateFolder() throws Exception {
+
+ // delete folder created in test setup.
+ deleteTestFolder();
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.parentFolderId", "0");
+ // parameter type is String
+ headers.put("CamelBox2.folderName", CAMEL_TEST_FOLDER);
+
+ testFolder = requestBodyAndHeaders("direct://CREATEFOLDER", null, headers);
+
+ assertNotNull("createFolder result", testFolder);
+ assertEquals("createFolder folder name", CAMEL_TEST_FOLDER, testFolder.getInfo().getName());
+ LOG.debug("createFolder: " + testFolder);
+ }
+
+ @Test
+ public void testDeleteFolder() throws Exception {
+ // using String message body for single parameter "folderId"
+ requestBody("direct://DELETEFOLDER", testFolder.getID());
+
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ Iterable<BoxItem.Info> it = rootFolder.search("^" + CAMEL_TEST_FOLDER + "$");
+ int searchResults = sizeOfIterable(it);
+ boolean exists = searchResults > 0 ? true : false;
+ assertEquals("deleteFolder exists", false, exists);
+ LOG.debug("deleteFolder: exists? " + exists);
+ }
+
+ @Test
+ public void testCopyFolder() throws Exception {
+ com.box.sdk.BoxFolder result = null;
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is String
+ headers.put("CamelBox2.destinationFolderId", CAMEL_TEST_DESTINATION_FOLDER_ID);
+ // parameter type is String
+ headers.put("CamelBox2.newName", CAMEL_TEST_COPY_FOLDER);
+ result = requestBodyAndHeaders("direct://COPYFOLDER", null, headers);
+ assertNotNull("copyFolder result", result);
+ assertEquals("copyFolder folder name", CAMEL_TEST_COPY_FOLDER, result.getInfo().getName());
+ LOG.debug("copyFolder: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ result.delete(true);
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testCreateSharedLink() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is com.box.sdk.BoxSharedLink.Access
+ headers.put("CamelBox2.access", BoxSharedLink.Access.COLLABORATORS);
+ // parameter type is java.util.Date
+ headers.put("CamelBox2.unshareDate", null);
+ // parameter type is com.box.sdk.BoxSharedLink.Permissions
+ headers.put("CamelBox2.permissions", new BoxSharedLink.Permissions());
+
+ final com.box.sdk.BoxSharedLink result = requestBodyAndHeaders("direct://CREATEFOLDERSHAREDLINK", null,
+ headers);
+
+ assertNotNull("createFolderSharedLink result", result);
+ LOG.debug("createFolderSharedLink: " + result);
+ }
+
+ @Test
+ public void testGetFolder() throws Exception {
+ // using String[] message body for single parameter "path"
+ final com.box.sdk.BoxFolder result = requestBody("direct://GETFOLDER", new String[] {CAMEL_TEST_FOLDER});
+
+ assertNotNull("getFolder result", result);
+ assertEquals("getFolder folder id", testFolder.getID(), result.getID());
+ LOG.debug("getFolder: " + result);
+ }
+
+ @Test
+ public void testGetFolderInfo() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is String[]
+ headers.put("CamelBox2.fields", new String[] {"name"});
+
+ final com.box.sdk.BoxFolder.Info result = requestBodyAndHeaders("direct://GETFOLDERINFO", null, headers);
+
+ assertNotNull("getFolderInfo result", result);
+ assertNotNull("getFolderInfo result.getName()", result.getName());
+ assertEquals("getFolderInfo info name", CAMEL_TEST_FOLDER, result.getName());
+ LOG.debug("getFolderInfo: " + result);
+ }
+
+ @Test
+ public void testGetFolderItems() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", CAMEL_TEST_ROOT_FOLDER_ID);
+ // parameter type is Long
+ headers.put("CamelBox2.offset", null);
+ // parameter type is Long
+ headers.put("CamelBox2.limit", null);
+ // parameter type is String[]
+ headers.put("CamelBox2.fields", null);
+
+ @SuppressWarnings("rawtypes")
+ final java.util.Collection result = requestBodyAndHeaders("direct://GETFOLDERITEMS", null, headers);
+
+ assertNotNull("getFolderItems result", result);
+ LOG.debug("getFolderItems: " + result);
+ }
+
+ @Test
+ public void testGetRootFolder() throws Exception {
+ final com.box.sdk.BoxFolder result = requestBody("direct://GETROOTFOLDER", null);
+
+ assertNotNull("getRootFolder result", result);
+ LOG.debug("getRootFolder: " + result);
+ }
+
+ @Test
+ public void testMoveFolder() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is String
+ headers.put("CamelBox2.destinationFolderId", CAMEL_TEST_DESTINATION_FOLDER_ID);
+ // parameter type is String
+ headers.put("CamelBox2.newName", CAMEL_TEST_MOVE_FOLDER);
+
+ final com.box.sdk.BoxFolder result = requestBodyAndHeaders("direct://MOVEFOLDER", null, headers);
+
+ assertNotNull("moveFolder result", result);
+ assertEquals("moveFolder folder name", CAMEL_TEST_MOVE_FOLDER, result.getInfo().getName());
+ LOG.debug("moveFolder: " + result);
+ }
+
+ @Test
+ public void testRenameFolder() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is String
+ headers.put("CamelBox2.newFolderName", CAMEL_TEST_RENAME_FOLDER);
+
+ final com.box.sdk.BoxFolder result = requestBodyAndHeaders("direct://RENAMEFOLDER", null, headers);
+
+ assertNotNull("renameFolder result", result);
+ assertEquals("moveFolder folder name", CAMEL_TEST_RENAME_FOLDER, result.getInfo().getName());
+ LOG.debug("renameFolder: " + result);
+ }
+
+ @Test
+ public void testUpdateInfo() throws Exception {
+ final BoxFolder.Info testFolderInfo = testFolder.getInfo();
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", testFolder.getID());
+ // parameter type is com.box.sdk.BoxFolder.Info
+ testFolderInfo.setDescription(CAMEL_TEST_FOLDER_DESCRIPTION);
+ headers.put("CamelBox2.info", testFolderInfo);
+
+ final com.box.sdk.BoxFolder result = requestBodyAndHeaders("direct://UPDATEFOLDERINFO", null, headers);
+
+ assertNotNull("updateInfo result", result);
+ assertEquals("update folder info description", CAMEL_TEST_FOLDER_DESCRIPTION,
+ result.getInfo().getDescription());
+ LOG.debug("updateInfo: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for copyFolder
+ from("direct://COPYFOLDER").to("box2://" + PATH_PREFIX + "/copyFolder");
+
+ // test route for createFolder
+ from("direct://CREATEFOLDER").to("box2://" + PATH_PREFIX + "/createFolder");
+
+ // test route for createFolderSharedLink
+ from("direct://CREATEFOLDERSHAREDLINK").to("box2://" + PATH_PREFIX + "/createFolderSharedLink");
+
+ // test route for deleteFolder
+ from("direct://DELETEFOLDER").to("box2://" + PATH_PREFIX + "/deleteFolder?inBody=folderId");
+
+ // test route for getFolder
+ from("direct://GETFOLDER").to("box2://" + PATH_PREFIX + "/getFolder?inBody=path");
+
+ // test route for getFolderInfo
+ from("direct://GETFOLDERINFO").to("box2://" + PATH_PREFIX + "/getFolderInfo");
+
+ // test route for getFolderItems
+ from("direct://GETFOLDERITEMS").to("box2://" + PATH_PREFIX + "/getFolderItems");
+
+ // test route for getRootFolder
+ from("direct://GETROOTFOLDER").to("box2://" + PATH_PREFIX + "/getRootFolder");
+
+ // test route for moveFolder
+ from("direct://MOVEFOLDER").to("box2://" + PATH_PREFIX + "/moveFolder");
+
+ // test route for renameFolder
+ from("direct://RENAMEFOLDER").to("box2://" + PATH_PREFIX + "/renameFolder");
+
+ // test route for updateFolderInfo
+ from("direct://UPDATEFOLDERINFO").to("box2://" + PATH_PREFIX + "/updateFolderInfo");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestFolder();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestFolder();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/copyFolder");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestFolder() {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ testFolder = rootFolder.createFolder(CAMEL_TEST_FOLDER).getResource();
+ }
+
+ private void deleteTestFolder() {
+ if (testFolder != null) {
+ try {
+ testFolder.delete(true);
+ } catch (Throwable t) {
+ }
+ testFolder = null;
+ }
+ }
+
+ private int sizeOfIterable(Iterable<?> it) {
+ if (it instanceof Collection) {
+ return ((Collection<?>) it).size();
+ } else {
+ int i = 0;
+ for (@SuppressWarnings("unused")
+ Object obj : it) {
+ i++;
+ }
+ return i;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2GroupsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2GroupsManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2GroupsManagerIntegrationTest.java
new file mode 100644
index 0000000..6d987ee
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2GroupsManagerIntegrationTest.java
@@ -0,0 +1,268 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxGroup;
+import com.box.sdk.BoxGroupMembership;
+import com.box.sdk.BoxUser;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2GroupsManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2GroupsManager}
+ * APIs.
+ */
+public class Box2GroupsManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2GroupsManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2GroupsManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_GROUP_NAME = "CamelTestGroup";
+ private static final String CAMEL_TEST_CREATE_GROUP_NAME = "CamelTestCreateGroup";
+
+ private BoxGroup testGroup;
+ private BoxUser testUser;
+
+ @Test
+ public void testAddGroupMembership() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.groupId", testGroup.getID());
+ // parameter type is String
+ headers.put("CamelBox2.userId", testUser.getID());
+ // parameter type is com.box.sdk.BoxGroupMembership.Role
+ headers.put("CamelBox2.role", null);
+
+ final com.box.sdk.BoxGroupMembership result = requestBodyAndHeaders("direct://ADDGROUPMEMBERSHIP", null,
+ headers);
+
+ assertNotNull("addGroupMembership result", result);
+ LOG.debug("addGroupMembership: " + result);
+ }
+
+ @Test
+ public void testCreateGroup() throws Exception {
+ com.box.sdk.BoxGroup result = null;
+
+ try {
+ // using String message body for single parameter "name"
+ result = requestBody("direct://CREATEGROUP", CAMEL_TEST_CREATE_GROUP_NAME);
+ assertNotNull("createGroup result", result);
+ assertEquals(CAMEL_TEST_CREATE_GROUP_NAME, result.getInfo().getName());
+ LOG.debug("createGroup: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ result.delete();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testDeleteGroup() throws Exception {
+ // using String message body for single parameter "groupId"
+ requestBody("direct://DELETEGROUP", testGroup.getID());
+
+ testGroup = null;
+
+ Iterable<BoxGroup.Info> it = BoxGroup.getAllGroups(getConnection());
+ int searchResults = sizeOfIterable(it);
+ boolean exists = searchResults > 0 ? true : false;
+ assertEquals("deleteGroup exists", false, exists);
+ LOG.debug("deleteGroup: exists? " + exists);
+ }
+
+ @Test
+ public void testDeleteGroupMembership() throws Exception {
+ BoxGroupMembership.Info info = testGroup.addMembership(testUser, BoxGroupMembership.Role.MEMBER);
+
+ // using String message body for single parameter "groupMembershipId"
+ requestBody("direct://DELETEGROUPMEMBERSHIP", info.getID());
+
+ Collection<BoxGroupMembership.Info> memberships = testGroup.getMemberships();
+ assertNotNull("deleteGroupMemberships memberships", memberships);
+ assertEquals("deleteGroupMemberships memberships exists", 0, memberships.size());
+ }
+
+ @Test
+ public void testGetAllGroups() throws Exception {
+ @SuppressWarnings("rawtypes")
+ final java.util.Collection result = requestBody("direct://GETALLGROUPS", null);
+
+ assertNotNull("getAllGroups result", result);
+ LOG.debug("getAllGroups: " + result);
+ }
+
+ @Test
+ public void testGetGroupInfo() throws Exception {
+ // using String message body for single parameter "groupId"
+ final com.box.sdk.BoxGroup.Info result = requestBody("direct://GETGROUPINFO", testGroup.getID());
+
+ assertNotNull("getGroupInfo result", result);
+ LOG.debug("getGroupInfo: " + result);
+ }
+
+ @Test
+ public void testGetGroupMembershipInfo() throws Exception {
+ BoxGroupMembership.Info info = testGroup.addMembership(testUser, BoxGroupMembership.Role.MEMBER);
+
+ // using String message body for single parameter "groupMemebershipId"
+ final com.box.sdk.BoxGroupMembership.Info result = requestBody("direct://GETGROUPMEMBERSHIPINFO", info.getID());
+
+ assertNotNull("getGroupMembershipInfo result", result);
+ LOG.debug("getGroupMembershipInfo: " + result);
+ }
+
+ @Test
+ public void testGetGroupMemberships() throws Exception {
+ // using String message body for single parameter "groupId"
+ @SuppressWarnings("rawtypes")
+ final java.util.Collection result = requestBody("direct://GETGROUPMEMBERSHIPS", testGroup.getID());
+
+ assertNotNull("getGroupMemberships result", result);
+ LOG.debug("getGroupMemberships: " + result);
+ }
+
+ @Test
+ public void testUpdateGroupMembershipInfo() throws Exception {
+ BoxGroupMembership.Info info = testGroup.addMembership(testUser, BoxGroupMembership.Role.MEMBER);
+ info.setRole(BoxGroupMembership.Role.ADMIN);
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.groupMemebershipId", info.getID());
+ // parameter type is com.box.sdk.BoxGroupMembership.Info
+ headers.put("CamelBox2.info", info);
+
+ final com.box.sdk.BoxGroupMembership result = requestBodyAndHeaders("direct://UPDATEGROUPMEMBERSHIPINFO", null,
+ headers);
+
+ assertNotNull("updateGroupMembershipInfo result", result);
+ LOG.debug("updateGroupMembershipInfo: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for addGroupMembership
+ from("direct://ADDGROUPMEMBERSHIP").to("box2://" + PATH_PREFIX + "/addGroupMembership");
+
+ // test route for createGroup
+ from("direct://CREATEGROUP").to("box2://" + PATH_PREFIX + "/createGroup?inBody=name");
+
+ // test route for deleteGroup
+ from("direct://DELETEGROUP").to("box2://" + PATH_PREFIX + "/deleteGroup?inBody=groupId");
+
+ // test route for deleteGroupMembership
+ from("direct://DELETEGROUPMEMBERSHIP")
+ .to("box2://" + PATH_PREFIX + "/deleteGroupMembership?inBody=groupMembershipId");
+
+ // test route for getAllGroups
+ from("direct://GETALLGROUPS").to("box2://" + PATH_PREFIX + "/getAllGroups");
+
+ // test route for getGroupInfo
+ from("direct://GETGROUPINFO").to("box2://" + PATH_PREFIX + "/getGroupInfo?inBody=groupId");
+
+ // test route for getGroupMembershipInfo
+ from("direct://GETGROUPMEMBERSHIPINFO")
+ .to("box2://" + PATH_PREFIX + "/getGroupMembershipInfo?inBody=groupMemebershipId");
+
+ // test route for getGroupMemberships
+ from("direct://GETGROUPMEMBERSHIPS")
+ .to("box2://" + PATH_PREFIX + "/getGroupMemberships?inBody=groupId");
+
+ // test route for updateGroupMembershipInfo
+ from("direct://UPDATEGROUPMEMBERSHIPINFO").to("box2://" + PATH_PREFIX + "/updateGroupMembershipInfo");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestGroup();
+ createTestUser();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestGroup();
+ deleteTestUser();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/addGroupMembership");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestGroup() {
+ testGroup = BoxGroup.createGroup(getConnection(), CAMEL_TEST_GROUP_NAME).getResource();
+ }
+
+ private void deleteTestGroup() {
+ if (testGroup != null) {
+ try {
+ testGroup.delete();
+ } catch (Throwable t) {
+ }
+ testGroup = null;
+ }
+ }
+
+ private void createTestUser() {
+ testUser = getCurrentUser();
+ }
+
+ private void deleteTestUser() {
+ if (testUser != null) {
+ testUser = null;
+ }
+ }
+
+ private BoxUser getCurrentUser() {
+ return BoxUser.getCurrentUser(getConnection());
+ }
+
+ private int sizeOfIterable(Iterable<?> it) {
+ if (it instanceof Collection) {
+ return ((Collection<?>) it).size();
+ } else {
+ int i = 0;
+ for (@SuppressWarnings("unused")
+ Object obj : it) {
+ i++;
+ }
+ return i;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2SearchManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2SearchManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2SearchManagerIntegrationTest.java
new file mode 100644
index 0000000..66be97d
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2SearchManagerIntegrationTest.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2SearchManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2SearchManager}
+ * APIs.
+ */
+public class Box2SearchManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2SearchManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2SearchManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_FILE = "/CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_NAME = "CamelTestFile.txt";
+
+ private BoxFile testFile;
+
+ @Test
+ public void testSearchFolder() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.folderId", "0");
+ // parameter type is String
+ headers.put("CamelBox2.query", CAMEL_TEST_FILE_NAME);
+
+ @SuppressWarnings("rawtypes")
+ final java.util.Collection result = requestBodyAndHeaders("direct://SEARCHFOLDER", null, headers);
+
+ assertNotNull("searchFolder result", result);
+ assertEquals("searchFolder file found", 1, result.size());
+ LOG.debug("searchFolder: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for searchFolder
+ from("direct://SEARCHFOLDER").to("box2://" + PATH_PREFIX + "/searchFolder");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestFile();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestFile();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/searchFolder");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestFile() throws FileNotFoundException {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
+ testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
+ }
+
+ private void deleteTestFile() {
+ try {
+ testFile.delete();
+ } catch (Throwable t) {
+ }
+ testFile = null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2TasksManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2TasksManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2TasksManagerIntegrationTest.java
new file mode 100644
index 0000000..b0aacfe
--- /dev/null
+++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2TasksManagerIntegrationTest.java
@@ -0,0 +1,284 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.box2;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+import com.box.sdk.BoxTask;
+import com.box.sdk.BoxTask.Action;
+import com.box.sdk.BoxTaskAssignment;
+import com.box.sdk.BoxUser;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box2.internal.Box2ApiCollection;
+import org.apache.camel.component.box2.internal.Box2TasksManagerApiMethod;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for {@link org.apache.camel.component.box2.api.Box2TasksManager}
+ * APIs.
+ */
+public class Box2TasksManagerIntegrationTest extends AbstractBox2TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Box2TasksManagerIntegrationTest.class);
+ private static final String PATH_PREFIX = Box2ApiCollection.getCollection()
+ .getApiName(Box2TasksManagerApiMethod.class).getName();
+ private static final String CAMEL_TEST_FILE = "/CamelTestFile.txt";
+ private static final String CAMEL_TEST_FILE_NAME = "CamelTestFile.txt";
+ private static final String CAMEL_TEST_MESSAGE = "Camel Test Message";
+ private static final long TEN_MINUTES_IN_MILLIS = 600000;
+
+ private BoxFile testFile;
+ private BoxTask testTask;
+
+ @Test
+ public void testAddAssignmentToTask() throws Exception {
+ com.box.sdk.BoxTask result = null;
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.taskId", testTask.getID());
+ // parameter type is com.box.sdk.BoxUser
+ headers.put("CamelBox2.assignTo", getCurrentUser());
+
+ result = requestBodyAndHeaders("direct://ADDASSIGNMENTTOTASK", null, headers);
+
+ assertNotNull("addAssignmentToTask result", result);
+ LOG.debug("addAssignmentToTask: " + result);
+ }
+
+ @Test
+ public void testAddFileTask() throws Exception {
+ com.box.sdk.BoxTask result = null;
+
+ try {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.fileId", testFile.getID());
+ // parameter type is com.box.sdk.BoxTask.Action
+ headers.put("CamelBox2.action", BoxTask.Action.REVIEW);
+ // parameter type is java.util.Date
+ Date now = new Date();
+ Date dueAt = new Date(now.getTime() + TEN_MINUTES_IN_MILLIS);
+ headers.put("CamelBox2.dueAt", dueAt);
+ // parameter type is String
+ headers.put("CamelBox2.message", CAMEL_TEST_MESSAGE);
+
+ result = requestBodyAndHeaders("direct://ADDFILETASK", null, headers);
+
+ assertNotNull("addFileTask result", result);
+ LOG.debug("addFileTask: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ result.delete();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testDeleteTask() throws Exception {
+ // using String message body for single parameter "taskId"
+ requestBody("direct://DELETETASK", testTask.getID());
+
+ List<BoxTask.Info> tasks = testFile.getTasks();
+ boolean exists = tasks.size() != 0;
+ assertEquals("deleteTask task still exists.", false, exists);
+ }
+
+ @Ignore // Receiving "not found" exception from Box API
+ @Test
+ public void testDeleteTaskAssignment() throws Exception {
+ BoxTaskAssignment.Info info = testTask.addAssignment(getCurrentUser());
+
+ // using String message body for single parameter "taskAssignmentId"
+ requestBody("direct://DELETETASKASSIGNMENT", info.getID());
+
+ List<BoxTaskAssignment.Info> assignments = testTask.getAssignments();
+ boolean exists = assignments.size() != 0;
+ assertEquals("deleteTaskAssignment assignment still exists.", false, exists);
+ }
+
+ @Test
+ public void testGetFileTasks() throws Exception {
+ // using String message body for single parameter "fileId"
+ @SuppressWarnings("rawtypes")
+ final java.util.List result = requestBody("direct://GETFILETASKS", testFile.getID());
+
+ assertNotNull("getFileTasks result", result);
+ LOG.debug("getFileTasks: " + result);
+ }
+
+ @Ignore
+ @Test
+ public void testGetTaskAssignmentInfo() throws Exception {
+ BoxTaskAssignment.Info info = testTask.addAssignment(getCurrentUser());
+ com.box.sdk.BoxTaskAssignment.Info result = null;
+
+ try {
+ // using String message body for single parameter "taskAssignmentId"
+ result = requestBody("direct://GETTASKASSIGNMENTINFO", info.getID());
+
+ assertNotNull("getTaskAssignmentInfo result", result);
+ LOG.debug("getTaskAssignmentInfo: " + result);
+ } finally {
+ if (result != null) {
+ try {
+ ((BoxTaskAssignment) result.getResource()).delete();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testGetTaskAssignments() throws Exception {
+ // using String message body for single parameter "taskId"
+ @SuppressWarnings("rawtypes")
+ final java.util.List result = requestBody("direct://GETTASKASSIGNMENTS", testTask.getID());
+
+ assertNotNull("getTaskAssignments result", result);
+ LOG.debug("getTaskAssignments: " + result);
+ }
+
+ @Test
+ public void testGetTaskInfo() throws Exception {
+ // using String message body for single parameter "taskId"
+ final com.box.sdk.BoxTask.Info result = requestBody("direct://GETTASKINFO", testTask.getID());
+
+ assertNotNull("getTaskInfo result", result);
+ LOG.debug("getTaskInfo: " + result);
+ }
+
+ @Ignore // No way to change BoxTask.Info parameters
+ @Test
+ public void testUpdateTaskInfo() throws Exception {
+ BoxTask.Info info = testTask.getInfo();
+
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelBox2.taskId", testTask.getID());
+ // parameter type is com.box.sdk.BoxTask.Info
+ headers.put("CamelBox2.info", info);
+
+ final com.box.sdk.BoxTask result = requestBodyAndHeaders("direct://UPDATETASKINFO", null, headers);
+
+ assertNotNull("updateTaskInfo result", result);
+ LOG.debug("updateTaskInfo: " + result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // test route for addAssignmentToTask
+ from("direct://ADDASSIGNMENTTOTASK").to("box2://" + PATH_PREFIX + "/addAssignmentToTask");
+
+ // test route for addFileTask
+ from("direct://ADDFILETASK").to("box2://" + PATH_PREFIX + "/addFileTask");
+
+ // test route for deleteTask
+ from("direct://DELETETASK").to("box2://" + PATH_PREFIX + "/deleteTask?inBody=taskId");
+
+ // test route for deleteTaskAssignment
+ from("direct://DELETETASKASSIGNMENT")
+ .to("box2://" + PATH_PREFIX + "/deleteTaskAssignment?inBody=taskAssignmentId");
+
+ // test route for getFileTasks
+ from("direct://GETFILETASKS").to("box2://" + PATH_PREFIX + "/getFileTasks?inBody=fileId");
+
+ // test route for getTaskAssignmentInfo
+ from("direct://GETTASKASSIGNMENTINFO")
+ .to("box2://" + PATH_PREFIX + "/getTaskAssignmentInfo?inBody=taskAssignmentId");
+
+ // test route for getTaskAssignments
+ from("direct://GETTASKASSIGNMENTS").to("box2://" + PATH_PREFIX + "/getTaskAssignments?inBody=taskId");
+
+ // test route for getTaskInfo
+ from("direct://GETTASKINFO").to("box2://" + PATH_PREFIX + "/getTaskInfo?inBody=taskId");
+
+ // test route for updateTaskInfo
+ from("direct://UPDATETASKINFO").to("box2://" + PATH_PREFIX + "/updateTaskInfo");
+
+ }
+ };
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ createTestFile();
+ createTestTask();
+ }
+
+ @After
+ public void teardownTest() {
+ deleteTestTask();
+ deleteTestFile();
+ }
+
+ public BoxAPIConnection getConnection() {
+ Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + PATH_PREFIX + "/addAssignmentToTask");
+ return endpoint.getBoxConnection();
+ }
+
+ private void createTestTask() {
+ Date now = new Date();
+ Date dueAt = new Date(now.getTime() + TEN_MINUTES_IN_MILLIS);
+ testTask = (BoxTask) testFile.addTask(Action.REVIEW, CAMEL_TEST_MESSAGE, dueAt).getResource();
+ }
+
+ private void deleteTestTask() {
+ try {
+ testTask.delete();
+ } catch (Throwable t) {
+ }
+ testTask = null;
+ }
+
+ private void createTestFile() throws FileNotFoundException {
+ BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
+ InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
+ testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
+ }
+
+ private void deleteTestFile() {
+ try {
+ testFile.delete();
+ } catch (Throwable t) {
+ }
+ testFile = null;
+ }
+
+ private BoxUser getCurrentUser() {
+ return BoxUser.getCurrentUser(getConnection());
+ }
+}