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/Box2UsersManagerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2UsersManagerIntegrationTest.java b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2UsersManagerIntegrationTest.java new file mode 100644 index 0000000..6b4b952 --- /dev/null +++ b/components/camel-box2/camel-box2-component/src/test/java/org/apache/camel/component/box2/Box2UsersManagerIntegrationTest.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.box2; + +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.box2.internal.Box2ApiCollection; +import org.apache.camel.component.box2.internal.Box2UsersManagerApiMethod; +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.Box2UsersManager} + * APIs. + */ +public class Box2UsersManagerIntegrationTest extends AbstractBox2TestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(Box2UsersManagerIntegrationTest.class); + private static final String PATH_PREFIX = Box2ApiCollection.getCollection() + .getApiName(Box2UsersManagerApiMethod.class).getName(); + private static final String CAMEL_TEST_USER_EMAIL_ALIAS = "[email protected]"; + 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 = "[email protected]"; + + 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("CamelBox2.userId", testUser.getID()); + // parameter type is String + headers.put("CamelBox2.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("CamelBox2.name", CAMEL_TEST_CREATE_APP_USER_NAME); + // parameter type is com.box.sdk.CreateUserParams + headers.put("CamelBox2.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("CamelBox2.login", CAMEL_TEST_CREATE_ENTERPRISE_USER_LOGIN); + // parameter type is String + headers.put("CamelBox2.name", CAMEL_TEST_CREATE_ENTERPRISE_USER_NAME); + // parameter type is com.box.sdk.CreateUserParams + headers.put("CamelBox2.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("CamelBox2.userId", info.getID()); + headers.put("CamelBox2.notifyUser", Boolean.FALSE); + headers.put("CamelBox2.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("CamelBox2.userId", testUser.getID()); + // parameter type is String + headers.put("CamelBox2.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("CamelBox2.filterTerm", null); + // parameter type is String[] + headers.put("CamelBox2.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("CamelBox2.userId", testUser.getID()); + // parameter type is com.box.sdk.BoxUser.Info + headers.put("CamelBox2.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("box2://" + PATH_PREFIX + "/addUserEmailAlias"); + + // test route for createAppUser + from("direct://CREATEAPPUSER").to("box2://" + PATH_PREFIX + "/createAppUser"); + + // test route for createEnterpriseUser + from("direct://CREATEENTERPRISEUSER").to("box2://" + PATH_PREFIX + "/createEnterpriseUser"); + + // test route for deleteUser + from("direct://DELETEUSER").to("box2://" + PATH_PREFIX + "/deleteUser"); + + // test route for deleteUserEmailAlias + from("direct://DELETEUSEREMAILALIAS").to("box2://" + PATH_PREFIX + "/deleteUserEmailAlias"); + + // test route for getAllEnterpriseOrExternalUsers + from("direct://GETALLENTERPRISEOREXTERNALUSERS") + .to("box2://" + PATH_PREFIX + "/getAllEnterpriseOrExternalUsers"); + + // test route for getCurrentUser + from("direct://GETCURRENTUSER").to("box2://" + PATH_PREFIX + "/getCurrentUser"); + + // test route for getUserEmailAlias + from("direct://GETUSEREMAILALIAS").to("box2://" + PATH_PREFIX + "/getUserEmailAlias?inBody=userId"); + + // test route for getUserInfo + from("direct://GETUSERINFO").to("box2://" + PATH_PREFIX + "/getUserInfo?inBody=userId"); + + // test route for updateUserInfo + from("direct://UPDATEUSERINFO").to("box2://" + PATH_PREFIX + "/updateUserInfo"); + + } + }; + } + + @Before + public void setupTest() throws Exception { + createTestUser(); + } + + @After + public void teardownTest() { + deleteTestUser(); + } + + public BoxAPIConnection getConnection() { + Box2Endpoint endpoint = (Box2Endpoint) context().getEndpoint("box2://" + 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/45335d1e/components/camel-box2/camel-box2-component/src/test/resources/CamelTestFile.txt ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-component/src/test/resources/CamelTestFile.txt b/components/camel-box2/camel-box2-component/src/test/resources/CamelTestFile.txt new file mode 100644 index 0000000..e420c95 --- /dev/null +++ b/components/camel-box2/camel-box2-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/45335d1e/components/camel-box2/camel-box2-component/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-component/src/test/resources/log4j.properties b/components/camel-box2/camel-box2-component/src/test/resources/log4j.properties new file mode 100644 index 0000000..3b1bd38 --- /dev/null +++ b/components/camel-box2/camel-box2-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 + http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-component/src/test/resources/test-options.properties b/components/camel-box2/camel-box2-component/src/test/resources/test-options.properties new file mode 100644 index 0000000..c5a5481 --- /dev/null +++ b/components/camel-box2/camel-box2-component/src/test/resources/test-options.properties @@ -0,0 +1,33 @@ +# +# 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. +# + +############################################### +## Authentication properties for Box2 Component +############################################### + +############################################################################# +## Authentication properties for Box2 Component using STANDARD_AUTHENTICATION +############################################################################# +authenticationType=STANDARD_AUTHENTICATION +## User name and password +## Create a free developer account on http://developers.box.com/ and provide user name password +userName= +userPassword= +## Application client id and secret +## Create a test Box.com application and provide its clientId and clientSecret +clientId= +clientSecret= http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/camel-box2-component/tmp/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-component/tmp/test-options.properties b/components/camel-box2/camel-box2-component/tmp/test-options.properties new file mode 100644 index 0000000..30a032c --- /dev/null +++ b/components/camel-box2/camel-box2-component/tmp/test-options.properties @@ -0,0 +1,67 @@ +# +# 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. +# + +############################################### +## Authentication properties for Box2 Component +############################################### + +############################################################################# +## Authentication properties for Box2 Component using STANDARD_AUTHENTICATION +############################################################################# +authenticationType=STANDARD_AUTHENTICATION +## User name and password +## Create a free developer account on http://developers.box.com/ and provide user name password [email protected] +userPassword=RedHat12!@ +## Application client id and secret +## Create a test Box.com application and provide its clientId and clientSecret +clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr + +################################################################################### +## Authentication properties for Box2 Component using APP_ENTERPRISE_AUTHENTICATION +################################################################################### +#authenticationType=APP_ENTERPRISE_AUTHENTICATION +#enterpriseId=8962085 +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr +#publicKeyId=b22nf9qt +#privateKeyFile=/Volumes/Development/Dev/box-java-sdk/private_key.pem +#privateKeyPassword=RedHat12!@ +#encryptionAlgorithm=RSA_SHA_256 +#maxCacheEntries=100 +### Application client id and secret +### Create a test Box.com application and provide its clientId and clientSecret +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr + +################################################################################### +## Authentication properties for Box2 Component using APP_USER_AUTHENTICATION +################################################################################### +#authenticationType=APP_USER_AUTHENTICATION +#[email protected] +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr +#publicKeyId=b22nf9qt +#privateKeyFile=/Volumes/Development/Dev/box-java-sdk/private_key.pem +#privateKeyPassword=RedHat12!@ +#encryptionAlgorithm=RSA_SHA_256 +#maxCacheEntries=100 +### Application client id and secret +### Create a test Box.com application and provide its clientId and clientSecret +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/camel-box2/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-box2/pom.xml b/components/camel-box2/pom.xml new file mode 100644 index 0000000..b25a287 --- /dev/null +++ b/components/camel-box2/pom.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>components</artifactId> + <groupId>org.apache.camel</groupId> + <version>2.19.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-box2-parent</artifactId> + <packaging>pom</packaging> + + <name>Camel Box2 Component Parent</name> + <description>Parent project for Camel {Box2} Component</description> + + <modules> + <module>camel-box2-component</module> + <module>camel-box2-api</module> + </modules> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/components/readme.adoc ---------------------------------------------------------------------- diff --git a/components/readme.adoc b/components/readme.adoc index 0904eab..fde808d 100644 --- a/components/readme.adoc +++ b/components/readme.adoc @@ -98,6 +98,9 @@ Number of Components: 220 in 175 JAR artifacts | link:camel-box/src/main/docs/box-component.adoc[Box] (camel-box) + `box:apiName/methodName` | 2.14 | For uploading downloading and managing files folders groups collaborations etc on box DOT com. +| link:camel-box2/src/main/docs/box2-component.adoc[Box] (camel-box2) + +`box2:apiName/methodName` | 2.19 | For uploading downloading and managing files folders groups collaborations etc on box DOT com. + | link:camel-braintree/src/main/docs/braintree-component.adoc[Braintree] (camel-braintree) + `braintree:apiName/methodName` | 2.17 | The braintree component is used for integrating with the Braintree Payment System. http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/docs/user-manual/en/SUMMARY.md ---------------------------------------------------------------------- diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md index d9212a8..57a4822 100644 --- a/docs/user-manual/en/SUMMARY.md +++ b/docs/user-manual/en/SUMMARY.md @@ -152,6 +152,7 @@ * [Beanstalk](beanstalk-component.adoc) * [Bonita](bonita-component.adoc) * [Box](box-component.adoc) + * [Box2](box2-component.adoc) * [Braintree](braintree-component.adoc) * [Camel Context](context-component.adoc) * [Cassandra CQL](cql-component.adoc) http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 3001de0..0874266 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -85,6 +85,7 @@ <boon-version>0.34</boon-version> <bouncycastle-version>1.55</bouncycastle-version> <boxjavalibv2.version>3.2.1</boxjavalibv2.version> + <box-java-sdk-version>2.1.1</box-java-sdk-version> <braintree-gateway-version>2.63.0</braintree-gateway-version> <brave-zipkin-version>4.0.6</brave-zipkin-version> <build-helper-maven-plugin-version>1.10</build-helper-maven-plugin-version> http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/platforms/spring-boot/components-starter/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml index e0e5fca..b198c69 100644 --- a/platforms/spring-boot/components-starter/pom.xml +++ b/platforms/spring-boot/components-starter/pom.xml @@ -94,6 +94,7 @@ <module>camel-bonita-starter</module> <module>camel-boon-starter</module> <module>camel-box-starter</module> + <module>camel-box2-starter</module> <module>camel-braintree-starter</module> <module>camel-cache-starter</module> <module>camel-cassandraql-starter</module> http://git-wip-us.apache.org/repos/asf/camel/blob/45335d1e/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml index 42ac198..75cd5de 100644 --- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml +++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml @@ -1009,6 +1009,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-groovy-dsl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-groovy-starter</artifactId> <version>${project.version}</version> </dependency>
