This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 88aef1f991 Adapt Dropbox tests to new authentication mechanism
88aef1f991 is described below

commit 88aef1f9911d327d56d47bfd8a3d9107700a7e9a
Author: James Netherton <[email protected]>
AuthorDate: Thu Aug 25 09:15:27 2022 +0100

    Adapt Dropbox tests to new authentication mechanism
    
    Fixes #4021
---
 integration-tests/dropbox/README.adoc              |  9 ++++++
 .../component/dropbox/it/DropboxResource.java      | 35 ++++++++++------------
 .../quarkus/component/dropbox/it/DropboxTest.java  |  4 +++
 3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/integration-tests/dropbox/README.adoc 
b/integration-tests/dropbox/README.adoc
index 25cfaca01d..5feca47141 100644
--- a/integration-tests/dropbox/README.adoc
+++ b/integration-tests/dropbox/README.adoc
@@ -3,10 +3,19 @@
 To run the Dropbox integration tests, you need a valid Dropbox 
https://www.dropbox.com/developers[developer account]. Then from
 the developer console, create a new app and make a note of the access token.
 
+You will also require a refresh token for authentication. If you're planning 
on repeatedly performing tests, then it's a good idea to
+generate a long-lived token. Some instructions for how to do that are here:
+
+https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens#implement-refresh-tokens
+
 Then set the following environment variables. Note that 
`DROPBOX_CLIENT_IDENTIFIER` should be set to the name of your Dropbox app:
 
 [source,shell]
 ----
 export DROPBOX_ACCESS_TOKEN=your-access-token
+export DROPBOX_ACCESS_TOKEN_EXPIRES_IN=your-access-token-expiry
+export DROPBOX_API_KEY=your-app-api-key
+export DROPBOX_API_SECRET=your-app-api-secret
 export DROPBOX_CLIENT_IDENTIFIER=your-client-identifier
+export DROPBOX_REFRESH_TOKEN=your-refresh-token
 ----
diff --git 
a/integration-tests/dropbox/src/main/java/org/apache/camel/quarkus/component/dropbox/it/DropboxResource.java
 
b/integration-tests/dropbox/src/main/java/org/apache/camel/quarkus/component/dropbox/it/DropboxResource.java
index c2d504dd53..8a7c80944a 100644
--- 
a/integration-tests/dropbox/src/main/java/org/apache/camel/quarkus/component/dropbox/it/DropboxResource.java
+++ 
b/integration-tests/dropbox/src/main/java/org/apache/camel/quarkus/component/dropbox/it/DropboxResource.java
@@ -53,16 +53,10 @@ public class DropboxResource {
     @Produces(MediaType.TEXT_PLAIN)
     public Response createFile() throws Exception {
         java.nio.file.Path path = Files.write(Paths.get("target", FILE_NAME), 
FILE_CONTENT.getBytes(StandardCharsets.UTF_8));
-        String result = producerTemplate.requestBodyAndHeader(
-                
"dropbox://put?uploadMode=add&accessToken={{DROPBOX_ACCESS_TOKEN}}&clientIdentifier={{DROPBOX_CLIENT_IDENTIFIER}}&localPath="
-                        + path.toString()
-                        + "&remotePath=" + REMOTE_PATH,
-                null,
-                HEADER_PUT_FILE_NAME, FILE_NAME, String.class);
-        return Response
-                .created(new URI("https://camel.apache.org/";))
-                .entity(result)
-                .build();
+        String result = producerTemplate.requestBodyAndHeader("dropbox://put?" 
+ getCredentialsUriOptions()
+                + "&uploadMode=add&localPath=" + path + "&remotePath=" + 
REMOTE_PATH, null, HEADER_PUT_FILE_NAME, FILE_NAME,
+                String.class);
+        return Response.created(new 
URI("https://camel.apache.org/";)).entity(result).build();
     }
 
     @Path("/read")
@@ -71,10 +65,7 @@ public class DropboxResource {
     public Response readFile() {
         try {
             String content = producerTemplate.requestBody(
-                    
"dropbox://get?accessToken={{DROPBOX_ACCESS_TOKEN}}&clientIdentifier={{DROPBOX_CLIENT_IDENTIFIER}}&remotePath="
-                            + REMOTE_PATH
-                            + FILE_NAME,
-                    null,
+                    "dropbox://get?" + getCredentialsUriOptions() + 
"&remotePath=" + REMOTE_PATH + FILE_NAME, null,
                     String.class);
             if (content != null) {
                 return Response.ok(content).build();
@@ -93,11 +84,17 @@ public class DropboxResource {
     @Path("/delete")
     @DELETE
     public Response deleteFile() {
-        producerTemplate
-                .requestBody(
-                        
"dropbox://del?accessToken={{DROPBOX_ACCESS_TOKEN}}&clientIdentifier={{DROPBOX_CLIENT_IDENTIFIER}}&remotePath="
-                                + REMOTE_PATH + FILE_NAME,
-                        (Object) null);
+        producerTemplate.requestBody("dropbox://del?" + 
getCredentialsUriOptions() + "&remotePath=" + REMOTE_PATH + FILE_NAME,
+                (Object) null);
         return Response.status(Response.Status.NO_CONTENT).build();
     }
+
+    private String getCredentialsUriOptions() {
+        return "accessToken={{DROPBOX_ACCESS_TOKEN}}" +
+                "&clientIdentifier={{DROPBOX_CLIENT_IDENTIFIER}}" +
+                "&refreshToken={{DROPBOX_REFRESH_TOKEN}}" +
+                "&apiKey={{DROPBOX_API_KEY}}" +
+                "&apiSecret={{DROPBOX_API_SECRET}}" +
+                "&expireIn={{DROPBOX_ACCESS_TOKEN_EXPIRES_IN}}";
+    }
 }
diff --git 
a/integration-tests/dropbox/src/test/java/org/apache/camel/quarkus/component/dropbox/it/DropboxTest.java
 
b/integration-tests/dropbox/src/test/java/org/apache/camel/quarkus/component/dropbox/it/DropboxTest.java
index b9e4f5a414..628bfa258b 100644
--- 
a/integration-tests/dropbox/src/test/java/org/apache/camel/quarkus/component/dropbox/it/DropboxTest.java
+++ 
b/integration-tests/dropbox/src/test/java/org/apache/camel/quarkus/component/dropbox/it/DropboxTest.java
@@ -25,7 +25,11 @@ import 
org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
 import static org.hamcrest.Matchers.is;
 
 @EnabledIfEnvironmentVariable(named = "DROPBOX_ACCESS_TOKEN", matches = ".+")
+@EnabledIfEnvironmentVariable(named = "DROPBOX_ACCESS_TOKEN_EXPIRES_IN", 
matches = ".+")
+@EnabledIfEnvironmentVariable(named = "DROPBOX_API_KEY", matches = ".+")
+@EnabledIfEnvironmentVariable(named = "DROPBOX_API_SECRET", matches = ".+")
 @EnabledIfEnvironmentVariable(named = "DROPBOX_CLIENT_IDENTIFIER", matches = 
".+")
+@EnabledIfEnvironmentVariable(named = "DROPBOX_REFRESH_TOKEN", matches = ".+")
 @QuarkusTest
 class DropboxTest {
 

Reply via email to