http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventLogsManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventLogsManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventLogsManagerIntegrationTest.java new file mode 100644 index 0000000..8200b8c --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventLogsManagerIntegrationTest.java @@ -0,0 +1,77 @@ +/** + * 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.box; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.box.api.BoxEventLogsManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxEventLogsManagerApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for + * {@link BoxEventLogsManager} APIs. + */ +public class BoxEventLogsManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxEventLogsManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxEventLogsManagerApiMethod.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("CamelBox.position", null); + // parameter type is java.util.Date + headers.put("CamelBox.after", after); + // parameter type is java.util.Date + headers.put("CamelBox.before", before); + // parameter type is com.box.sdk.BoxEvent.Type[] + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/getEnterpriseEvents"); + + } + }; + } +}
http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsManagerIntegrationTest.java new file mode 100644 index 0000000..fb18624 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsManagerIntegrationTest.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.box; + +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.box.api.BoxEventsManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxEventsManagerApiMethod; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link BoxEventsManager} + * 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 BoxEventsManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxEventsManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxEventsManagerApiMethod.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:boxEvents"); + 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("box://" + PATH_PREFIX + "/listen?startingPosition=0").to("mock:boxEvents"); + + } + }; + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context() + .getEndpoint("box://" + 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/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFilesManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFilesManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFilesManagerIntegrationTest.java new file mode 100644 index 0000000..349e8b1 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFilesManagerIntegrationTest.java @@ -0,0 +1,576 @@ +/** + * 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.box; + +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.box.api.BoxFilesManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxFilesManagerApiMethod; +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 BoxFilesManager} + * APIs. + */ +public class BoxFilesManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxFilesManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxFilesManagerApiMethod.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("CamelBox.fileId", testFile.getID()); + // parameter type is String + headers.put("CamelBox.destinationFolderId", "0"); + // parameter type is String + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.Metadata + headers.put("CamelBox.metadata", metadata); + // parameter type is String + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.BoxSharedLink.Access + headers.put("CamelBox.access", BoxSharedLink.Access.DEFAULT); + // parameter type is java.util.Date + headers.put("CamelBox.unshareDate", null); + // parameter type is com.box.sdk.BoxSharedLink.Permissions + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is Integer + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is java.io.OutputStream + ByteArrayOutputStream output = new ByteArrayOutputStream(); + headers.put("CamelBox.output", output); + // parameter type is Long + headers.put("CamelBox.rangeStart", null); + // parameter type is Long + headers.put("CamelBox.rangeEnd", null); + // parameter type is com.box.sdk.ProgressListener + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is Integer + headers.put("CamelBox.version", 0); + // parameter type is java.io.OutputStream + ByteArrayOutputStream output = new ByteArrayOutputStream(); + headers.put("CamelBox.output", output); + // parameter type is com.box.sdk.ProgressListener + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is String[] + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is String + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.BoxFile.ThumbnailFileType + headers.put("CamelBox.fileType", ThumbnailFileType.JPG); + // parameter type is Integer + headers.put("CamelBox.minWidth", 32); + // parameter type is Integer + headers.put("CamelBox.minHeight", 32); + // parameter type is Integer + headers.put("CamelBox.maxWidth", 32); + // parameter type is Integer + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is String + headers.put("CamelBox.destinationFolderId", "0"); + // parameter type is String + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is Integer + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is String + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.BoxFile.Info + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.Metadata + headers.put("CamelBox.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("CamelBox.parentFolderId", "0"); + headers.put("CamelBox.content", getClass().getResourceAsStream(CAMEL_TEST_FILE)); + headers.put("CamelBox.fileName", CAMEL_TEST_UPLOAD_FILE_NAME); + headers.put("CamelBox.created", null); + headers.put("CamelBox.modified", null); + headers.put("CamelBox.size", null); + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is java.io.InputStream + headers.put("CamelBox.fileContent", getClass().getResourceAsStream(CAMEL_TEST_FILE)); + // parameter type is java.util.Date + headers.put("CamelBox.modified", null); + // parameter type is Long + headers.put("CamelBox.fileSize", null); + // parameter type is com.box.sdk.ProgressListener + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/copyFile"); + + // test route for createFileMetadata + from("direct://CREATEFILEMETADATA").to("box://" + PATH_PREFIX + "/createFileMetadata"); + + // test route for createFileSharedLink + from("direct://CREATEFILESHAREDLINK").to("box://" + PATH_PREFIX + "/createFileSharedLink"); + + // test route for deleteFile + from("direct://DELETEFILE").to("box://" + PATH_PREFIX + "/deleteFile?inBody=fileId"); + + // test route for deleteFileMetadata + from("direct://DELETEFILEMETADATA").to("box://" + PATH_PREFIX + "/deleteFileMetadata?inBody=fileId"); + + // test route for deleteFileVersion + from("direct://DELETEFILEVERSION").to("box://" + PATH_PREFIX + "/deleteFileVersion"); + + // test route for downloadFile + from("direct://DOWNLOADFILE").to("box://" + PATH_PREFIX + "/downloadFile"); + + // test route for downloadPreviousFileVersion + from("direct://DOWNLOADPREVIOUSFILEVERSION") + .to("box://" + PATH_PREFIX + "/downloadPreviousFileVersion"); + + // test route for getDownloadURL + from("direct://GETDOWNLOADURL").to("box://" + PATH_PREFIX + "/getDownloadURL?inBody=fileId"); + + // test route for getFileInfo + from("direct://GETFILEINFO").to("box://" + PATH_PREFIX + "/getFileInfo"); + + // test route for getFileMetadata + from("direct://GETFILEMETADATA").to("box://" + PATH_PREFIX + "/getFileMetadata"); + + // test route for getFilePreviewLink + from("direct://GETFILEPREVIEWLINK").to("box://" + PATH_PREFIX + "/getFilePreviewLink?inBody=fileId"); + + // test route for getFileThumbnail + from("direct://GETFILETHUMBNAIL").to("box://" + PATH_PREFIX + "/getFileThumbnail"); + + // test route for getFileVersions + from("direct://GETFILEVERSIONS").to("box://" + PATH_PREFIX + "/getFileVersions?inBody=fileId"); + + // test route for moveFile + from("direct://MOVEFILE").to("box://" + PATH_PREFIX + "/moveFile"); + + // test route for promoteFileVersion + from("direct://PROMOTEFILEVERSION").to("box://" + PATH_PREFIX + "/promoteFileVersion"); + + // test route for renameFile + from("direct://RENAMEFILE").to("box://" + PATH_PREFIX + "/renameFile"); + + // test route for updateFileInfo + from("direct://UPDATEFILEINFO").to("box://" + PATH_PREFIX + "/updateFileInfo"); + + // test route for updateFileMetadata + from("direct://UPDATEFILEMETADATA").to("box://" + PATH_PREFIX + "/updateFileMetadata"); + + // test route for uploadFile + from("direct://UPLOADFILE").to("box://" + PATH_PREFIX + "/uploadFile"); + + // test route for uploadNewFileVersion + from("direct://UPLOADNEWFILEVERSION").to("box://" + PATH_PREFIX + "/uploadNewFileVersion"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestFile(); + } + + @After + public void teardownTest() { + deleteTestFile(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + 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/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java new file mode 100644 index 0000000..7dcea18 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java @@ -0,0 +1,323 @@ +/** + * 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.box; + +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.box.api.BoxFoldersManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxFoldersManagerApiMethod; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link BoxFoldersManager} + * APIs. + */ +public class BoxFoldersManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxFoldersManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxFoldersManagerApiMethod.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 = BoxFoldersManagerIntegrationTest.CAMEL_TEST_FOLDER + "_Copy"; + private static final String CAMEL_TEST_MOVE_FOLDER = BoxFoldersManagerIntegrationTest.CAMEL_TEST_FOLDER + "_Move"; + private static final String CAMEL_TEST_RENAME_FOLDER = BoxFoldersManagerIntegrationTest.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("CamelBox.parentFolderId", "0"); + // parameter type is String + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is String + headers.put("CamelBox.destinationFolderId", CAMEL_TEST_DESTINATION_FOLDER_ID); + // parameter type is String + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is com.box.sdk.BoxSharedLink.Access + headers.put("CamelBox.access", BoxSharedLink.Access.COLLABORATORS); + // parameter type is java.util.Date + headers.put("CamelBox.unshareDate", null); + // parameter type is com.box.sdk.BoxSharedLink.Permissions + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is String[] + headers.put("CamelBox.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("CamelBox.folderId", CAMEL_TEST_ROOT_FOLDER_ID); + // parameter type is Long + headers.put("CamelBox.offset", null); + // parameter type is Long + headers.put("CamelBox.limit", null); + // parameter type is String[] + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is String + headers.put("CamelBox.destinationFolderId", CAMEL_TEST_DESTINATION_FOLDER_ID); + // parameter type is String + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is String + headers.put("CamelBox.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("CamelBox.folderId", testFolder.getID()); + // parameter type is com.box.sdk.BoxFolder.Info + testFolderInfo.setDescription(CAMEL_TEST_FOLDER_DESCRIPTION); + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/copyFolder"); + + // test route for createFolder + from("direct://CREATEFOLDER").to("box://" + PATH_PREFIX + "/createFolder"); + + // test route for createFolderSharedLink + from("direct://CREATEFOLDERSHAREDLINK").to("box://" + PATH_PREFIX + "/createFolderSharedLink"); + + // test route for deleteFolder + from("direct://DELETEFOLDER").to("box://" + PATH_PREFIX + "/deleteFolder?inBody=folderId"); + + // test route for getFolder + from("direct://GETFOLDER").to("box://" + PATH_PREFIX + "/getFolder?inBody=path"); + + // test route for getFolderInfo + from("direct://GETFOLDERINFO").to("box://" + PATH_PREFIX + "/getFolderInfo"); + + // test route for getFolderItems + from("direct://GETFOLDERITEMS").to("box://" + PATH_PREFIX + "/getFolderItems"); + + // test route for getRootFolder + from("direct://GETROOTFOLDER").to("box://" + PATH_PREFIX + "/getRootFolder"); + + // test route for moveFolder + from("direct://MOVEFOLDER").to("box://" + PATH_PREFIX + "/moveFolder"); + + // test route for renameFolder + from("direct://RENAMEFOLDER").to("box://" + PATH_PREFIX + "/renameFolder"); + + // test route for updateFolderInfo + from("direct://UPDATEFOLDERINFO").to("box://" + PATH_PREFIX + "/updateFolderInfo"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestFolder(); + } + + @After + public void teardownTest() { + deleteTestFolder(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + 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/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxGroupsManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxGroupsManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxGroupsManagerIntegrationTest.java new file mode 100644 index 0000000..41a4e2c --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxGroupsManagerIntegrationTest.java @@ -0,0 +1,269 @@ +/** + * 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.box; + +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.box.api.BoxGroupsManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxGroupsManagerApiMethod; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link BoxGroupsManager} + * APIs. + */ +public class BoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxGroupsManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxGroupsManagerApiMethod.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("CamelBox.groupId", testGroup.getID()); + // parameter type is String + headers.put("CamelBox.userId", testUser.getID()); + // parameter type is com.box.sdk.BoxGroupMembership.Role + headers.put("CamelBox.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("CamelBox.groupMemebershipId", info.getID()); + // parameter type is com.box.sdk.BoxGroupMembership.Info + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/addGroupMembership"); + + // test route for createGroup + from("direct://CREATEGROUP").to("box://" + PATH_PREFIX + "/createGroup?inBody=name"); + + // test route for deleteGroup + from("direct://DELETEGROUP").to("box://" + PATH_PREFIX + "/deleteGroup?inBody=groupId"); + + // test route for deleteGroupMembership + from("direct://DELETEGROUPMEMBERSHIP") + .to("box://" + PATH_PREFIX + "/deleteGroupMembership?inBody=groupMembershipId"); + + // test route for getAllGroups + from("direct://GETALLGROUPS").to("box://" + PATH_PREFIX + "/getAllGroups"); + + // test route for getGroupInfo + from("direct://GETGROUPINFO").to("box://" + PATH_PREFIX + "/getGroupInfo?inBody=groupId"); + + // test route for getGroupMembershipInfo + from("direct://GETGROUPMEMBERSHIPINFO") + .to("box://" + PATH_PREFIX + "/getGroupMembershipInfo?inBody=groupMemebershipId"); + + // test route for getGroupMemberships + from("direct://GETGROUPMEMBERSHIPS") + .to("box://" + PATH_PREFIX + "/getGroupMemberships?inBody=groupId"); + + // test route for updateGroupMembershipInfo + from("direct://UPDATEGROUPMEMBERSHIPINFO").to("box://" + PATH_PREFIX + "/updateGroupMembershipInfo"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestGroup(); + createTestUser(); + } + + @After + public void teardownTest() { + deleteTestGroup(); + deleteTestUser(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + 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/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSearchManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSearchManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSearchManagerIntegrationTest.java new file mode 100644 index 0000000..16d5aed --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSearchManagerIntegrationTest.java @@ -0,0 +1,107 @@ +/** + * 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.box; + +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.box.api.BoxSearchManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxSearchManagerApiMethod; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link BoxSearchManager} + * APIs. + */ +public class BoxSearchManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxSearchManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxSearchManagerApiMethod.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("CamelBox.folderId", "0"); + // parameter type is String + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/searchFolder"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestFile(); + } + + @After + public void teardownTest() { + deleteTestFile(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + 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/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxTasksManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxTasksManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxTasksManagerIntegrationTest.java new file mode 100644 index 0000000..0f6a10b --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxTasksManagerIntegrationTest.java @@ -0,0 +1,285 @@ +/** + * 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.box; + +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.box.api.BoxTasksManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxTasksManagerApiMethod; +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 BoxTasksManager} + * APIs. + */ +public class BoxTasksManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxTasksManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxTasksManagerApiMethod.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("CamelBox.taskId", testTask.getID()); + // parameter type is com.box.sdk.BoxUser + headers.put("CamelBox.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("CamelBox.fileId", testFile.getID()); + // parameter type is com.box.sdk.BoxTask.Action + headers.put("CamelBox.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("CamelBox.dueAt", dueAt); + // parameter type is String + headers.put("CamelBox.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("CamelBox.taskId", testTask.getID()); + // parameter type is com.box.sdk.BoxTask.Info + headers.put("CamelBox.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("box://" + PATH_PREFIX + "/addAssignmentToTask"); + + // test route for addFileTask + from("direct://ADDFILETASK").to("box://" + PATH_PREFIX + "/addFileTask"); + + // test route for deleteTask + from("direct://DELETETASK").to("box://" + PATH_PREFIX + "/deleteTask?inBody=taskId"); + + // test route for deleteTaskAssignment + from("direct://DELETETASKASSIGNMENT") + .to("box://" + PATH_PREFIX + "/deleteTaskAssignment?inBody=taskAssignmentId"); + + // test route for getFileTasks + from("direct://GETFILETASKS").to("box://" + PATH_PREFIX + "/getFileTasks?inBody=fileId"); + + // test route for getTaskAssignmentInfo + from("direct://GETTASKASSIGNMENTINFO") + .to("box://" + PATH_PREFIX + "/getTaskAssignmentInfo?inBody=taskAssignmentId"); + + // test route for getTaskAssignments + from("direct://GETTASKASSIGNMENTS").to("box://" + PATH_PREFIX + "/getTaskAssignments?inBody=taskId"); + + // test route for getTaskInfo + from("direct://GETTASKINFO").to("box://" + PATH_PREFIX + "/getTaskInfo?inBody=taskId"); + + // test route for updateTaskInfo + from("direct://UPDATETASKINFO").to("box://" + PATH_PREFIX + "/updateTaskInfo"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestFile(); + createTestTask(); + } + + @After + public void teardownTest() { + deleteTestTask(); + deleteTestFile(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + 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()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxUsersManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxUsersManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxUsersManagerIntegrationTest.java new file mode 100644 index 0000000..ad59b21 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxUsersManagerIntegrationTest.java @@ -0,0 +1,324 @@ +/** + * 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.box; + +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.BoxUser; +import com.box.sdk.CreateUserParams; +import com.box.sdk.EmailAlias; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.box.api.BoxUsersManager; +import org.apache.camel.component.box.internal.BoxApiCollection; +import org.apache.camel.component.box.internal.BoxUsersManagerApiMethod; +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 BoxUsersManager} + * APIs. + */ +public class BoxUsersManagerIntegrationTest extends AbstractBoxTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BoxUsersManagerIntegrationTest.class); + private static final String PATH_PREFIX = BoxApiCollection.getCollection() + .getApiName(BoxUsersManagerApiMethod.class).getName(); + private static final String CAMEL_TEST_USER_EMAIL_ALIAS = "ca...@example.com"; + private static final String CAMEL_TEST_USER_JOB_TITLE = "Camel Tester"; + private static final String CAMEL_TEST_CREATE_APP_USER_NAME = "Wilma"; + private static final String CAMEL_TEST_CREATE_ENTERPRISE_USER_NAME = "fred"; + private static final String CAMEL_TEST_CREATE_ENTERPRISE_USER_LOGIN = "f...@example.com"; + + private BoxUser testUser; + + @Ignore + @Test + public void testAddUserEmailAlias() throws Exception { + com.box.sdk.EmailAlias result = null; + try { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.userId", testUser.getID()); + // parameter type is String + headers.put("CamelBox.email", CAMEL_TEST_USER_EMAIL_ALIAS); + result = requestBodyAndHeaders("direct://ADDUSEREMAILALIAS", null, headers); + assertNotNull("addUserEmailAlias result", result); + LOG.debug("addUserEmailAlias: " + result); + } finally { + if (result != null) { + try { + testUser.deleteEmailAlias(result.getID()); + } catch (Throwable t) { + } + } + } + } + + @Test + public void testCreateAppUser() throws Exception { + com.box.sdk.BoxUser result = null; + + try { + CreateUserParams params = new CreateUserParams(); + params.setSpaceAmount(1073741824); // 1 GB + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.name", CAMEL_TEST_CREATE_APP_USER_NAME); + // parameter type is com.box.sdk.CreateUserParams + headers.put("CamelBox.params", params); + + result = requestBodyAndHeaders("direct://CREATEAPPUSER", null, headers); + + assertNotNull("createAppUser result", result); + LOG.debug("createAppUser: " + result); + } finally { + if (result != null) { + try { + result.delete(false, true); + } catch (Throwable t) { + } + } + } + } + + @Test + public void testCreateEnterpriseUser() throws Exception { + com.box.sdk.BoxUser result = null; + + try { + CreateUserParams params = new CreateUserParams(); + params.setSpaceAmount(1073741824); // 1 GB + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.login", CAMEL_TEST_CREATE_ENTERPRISE_USER_LOGIN); + // parameter type is String + headers.put("CamelBox.name", CAMEL_TEST_CREATE_ENTERPRISE_USER_NAME); + // parameter type is com.box.sdk.CreateUserParams + headers.put("CamelBox.params", params); + + result = requestBodyAndHeaders("direct://CREATEENTERPRISEUSER", null, headers); + + assertNotNull("createEnterpriseUser result", result); + LOG.debug("createEnterpriseUser: " + result); + } finally { + if (result != null) { + try { + result.delete(false, true); + } catch (Throwable t) { + } + } + } + } + + @Test + public void testDeleteUser() throws Exception { + BoxUser.Info info = BoxUser.createAppUser(getConnection(), CAMEL_TEST_CREATE_APP_USER_NAME); + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.userId", info.getID()); + headers.put("CamelBox.notifyUser", Boolean.FALSE); + headers.put("CamelBox.force", Boolean.FALSE); + + requestBodyAndHeaders("direct://DELETEUSER", null, headers); + + Iterable<BoxUser.Info> it = BoxUser.getAllEnterpriseUsers(getConnection(), CAMEL_TEST_CREATE_APP_USER_NAME); + int searchResults = sizeOfIterable(it); + boolean exists = searchResults > 0 ? true : false; + assertEquals("deleteUser exists", false, exists); + LOG.debug("deleteUser: exists? " + exists); + } + + @Ignore + @Test + public void testDeleteUserEmailAlias() throws Exception { + EmailAlias emailAlias = null; + try { + emailAlias = testUser.addEmailAlias(CAMEL_TEST_USER_EMAIL_ALIAS); + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.userId", testUser.getID()); + // parameter type is String + headers.put("CamelBox.emailAliasId", emailAlias.getID()); + + requestBodyAndHeaders("direct://DELETEUSEREMAILALIAS", null, headers); + + assertNotNull("deleteUserEmailAlias email aliases", testUser.getEmailAliases()); + assertEquals("deleteUserEmailAlias email aliases", 0, testUser.getEmailAliases().size()); + } + + @Test + public void testGetAllEnterpriseOrExternalUsers() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.filterTerm", null); + // parameter type is String[] + headers.put("CamelBox.fields", null); + + @SuppressWarnings("rawtypes") + final java.util.List result = requestBodyAndHeaders("direct://GETALLENTERPRISEOREXTERNALUSERS", null, headers); + + assertNotNull("getAllEnterpriseOrExternalUsers result", result); + LOG.debug("getAllEnterpriseOrExternalUsers: " + result); + } + + @Test + public void testGetCurrentUser() throws Exception { + final com.box.sdk.BoxUser result = requestBody("direct://GETCURRENTUSER", testUser.getID()); + + assertNotNull("getCurrentUser result", result); + LOG.debug("getCurrentUser: " + result); + } + + @Test + public void testGetUserEmailAlias() throws Exception { + // using String message body for single parameter "userId" + @SuppressWarnings("rawtypes") + final java.util.Collection result = requestBody("direct://GETUSEREMAILALIAS", testUser.getID()); + + assertNotNull("getUserEmailAlias result", result); + LOG.debug("getUserEmailAlias: " + result); + } + + @Test + public void testGetUserInfo() throws Exception { + // using String message body for single parameter "userId" + final com.box.sdk.BoxUser.Info result = requestBody("direct://GETUSERINFO", testUser.getID()); + + assertNotNull("getUserInfo result", result); + LOG.debug("getUserInfo: " + result); + } + + @Test + public void testUpdateUserInfo() throws Exception { + BoxUser.Info info = testUser.getInfo(); + info.setJobTitle(CAMEL_TEST_USER_JOB_TITLE); + + try { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.userId", testUser.getID()); + // parameter type is com.box.sdk.BoxUser.Info + headers.put("CamelBox.info", info); + final com.box.sdk.BoxUser result = requestBodyAndHeaders("direct://UPDATEUSERINFO", null, headers); + assertNotNull("updateUserInfo result", result); + LOG.debug("updateUserInfo: " + result); + } finally { + info = testUser.getInfo(); + info.setJobTitle(""); + testUser.updateInfo(info); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for addUserEmailAlias + from("direct://ADDUSEREMAILALIAS").to("box://" + PATH_PREFIX + "/addUserEmailAlias"); + + // test route for createAppUser + from("direct://CREATEAPPUSER").to("box://" + PATH_PREFIX + "/createAppUser"); + + // test route for createEnterpriseUser + from("direct://CREATEENTERPRISEUSER").to("box://" + PATH_PREFIX + "/createEnterpriseUser"); + + // test route for deleteUser + from("direct://DELETEUSER").to("box://" + PATH_PREFIX + "/deleteUser"); + + // test route for deleteUserEmailAlias + from("direct://DELETEUSEREMAILALIAS").to("box://" + PATH_PREFIX + "/deleteUserEmailAlias"); + + // test route for getAllEnterpriseOrExternalUsers + from("direct://GETALLENTERPRISEOREXTERNALUSERS") + .to("box://" + PATH_PREFIX + "/getAllEnterpriseOrExternalUsers"); + + // test route for getCurrentUser + from("direct://GETCURRENTUSER").to("box://" + PATH_PREFIX + "/getCurrentUser"); + + // test route for getUserEmailAlias + from("direct://GETUSEREMAILALIAS").to("box://" + PATH_PREFIX + "/getUserEmailAlias?inBody=userId"); + + // test route for getUserInfo + from("direct://GETUSERINFO").to("box://" + PATH_PREFIX + "/getUserInfo?inBody=userId"); + + // test route for updateUserInfo + from("direct://UPDATEUSERINFO").to("box://" + PATH_PREFIX + "/updateUserInfo"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestUser(); + } + + @After + public void teardownTest() { + deleteTestUser(); + } + + public BoxAPIConnection getConnection() { + BoxEndpoint endpoint = (BoxEndpoint) context().getEndpoint("box://" + PATH_PREFIX + "/addUserEmailAlias"); + return endpoint.getBoxConnection(); + } + + 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/db0ca734/components/camel-box/camel-box-component/src/test/resources/CamelTestFile.txt ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/resources/CamelTestFile.txt b/components/camel-box/camel-box-component/src/test/resources/CamelTestFile.txt new file mode 100644 index 0000000..e420c95 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/resources/CamelTestFile.txt @@ -0,0 +1 @@ +This is the CamelTestFile. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/resources/log4j.properties b/components/camel-box/camel-box-component/src/test/resources/log4j.properties new file mode 100644 index 0000000..3b1bd38 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/resources/log4j.properties @@ -0,0 +1,14 @@ +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +