This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7cae141011c6524d43abd7fac174963bb2f49f17 Author: Raffaele Marcello <marcelloraffa...@gmail.com> AuthorDate: Thu Feb 11 09:37:59 2021 +0100 CAMEL-15964 create camel-google-storage component --- components/camel-google-storage/ReadMe.txt | 34 ++++++++++---- components/camel-google-storage/pom.xml | 5 +- .../GoogleCloudStorageEndpointUriFactory.java | 4 +- .../component/google/storage/google-storage.json | 1 - .../google/storage/GoogleCloudStorageEndpoint.java | 26 ++--------- ...ogleCloudStorageComponentConfigurationTest.java | 19 -------- .../storage/{ => unit}/ConsumerLocalTest.java | 3 +- .../{ => unit}/GoogleCloudStorageBaseTest.java | 3 +- ...ogleCloudStorageComponentConfigurationTest.java | 54 ++++++++++++++++++++++ .../storage/{ => unit}/ProducerLocalTest.java | 4 +- 10 files changed, 94 insertions(+), 59 deletions(-) diff --git a/components/camel-google-storage/ReadMe.txt b/components/camel-google-storage/ReadMe.txt index f327e1e..4b5dcf0 100644 --- a/components/camel-google-storage/ReadMe.txt +++ b/components/camel-google-storage/ReadMe.txt @@ -1,13 +1,31 @@ -Camel Component Project -======================= +## Camel Google Storage Component +This component is based on the https://github.com/googleapis/java-storage[google java storage library] that works as a client for the Google Cloud Storage. -This project is a template of a Camel component. -To build this project use +## Camel Google Storage Component testing - mvn install +The unit tests provided are somewhat limited. +Due to the nature of the component, it needs to be tested against a google Storage instance because although there are some emulators +they doesn't cover all the functionalities. + +The tests are organized into two packages: +* Unit : <br> + Standalone tests that can be conducted on their own +* Integration : <br> + Tests against a Google Storage instance + +For the Unit tests has been extended the emulator https://github.com/googleapis/java-storage-nio/blob/master/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java[FakeStorageRpc] +adding some functionalities (bucket creation and deletion). However there are still some unsupported operations. + + +### Execution of integration tests + +A Google Cloud account with a project... + +Running tests against Storage instance: + +``` +mvn -Pgoogle-storage-test verify +``` -For more help see the Apache Camel documentation: - http://camel.apache.org/writing-components.html - diff --git a/components/camel-google-storage/pom.xml b/components/camel-google-storage/pom.xml index 26d3519..832fa11 100644 --- a/components/camel-google-storage/pom.xml +++ b/components/camel-google-storage/pom.xml @@ -92,10 +92,9 @@ <forkCount>1</forkCount> <reuseForks>true</reuseForks> <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds> - <!--<includes> - + <includes> <include>**/unit/**/*.java</include> - </includes>--> + </includes> </configuration> </plugin> </plugins> diff --git a/components/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpointUriFactory.java b/components/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpointUriFactory.java index 35339d8..e421f25 100644 --- a/components/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpointUriFactory.java +++ b/components/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpointUriFactory.java @@ -20,9 +20,8 @@ public class GoogleCloudStorageEndpointUriFactory extends org.apache.camel.suppo private static final Set<String> PROPERTY_NAMES; private static final Set<String> SECRET_PROPERTY_NAMES; static { - Set<String> props = new HashSet<>(33); + Set<String> props = new HashSet<>(32); props.add("backoffMultiplier"); - props.add("bucketName"); props.add("destinationBucket"); props.add("initialDelay"); props.add("serviceAccountCredentials"); @@ -70,7 +69,6 @@ public class GoogleCloudStorageEndpointUriFactory extends org.apache.camel.suppo Map<String, Object> copy = new HashMap<>(properties); - uri = buildPathParameter(syntax, uri, "bucketName", null, true, copy); uri = buildQueryParameters(uri, copy, encode); return uri; } diff --git a/components/camel-google-storage/src/generated/resources/org/apache/camel/component/google/storage/google-storage.json b/components/camel-google-storage/src/generated/resources/org/apache/camel/component/google/storage/google-storage.json index e75a20d7..d06cb07 100644 --- a/components/camel-google-storage/src/generated/resources/org/apache/camel/component/google/storage/google-storage.json +++ b/components/camel-google-storage/src/generated/resources/org/apache/camel/component/google/storage/google-storage.json @@ -40,7 +40,6 @@ "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] }, "properties": { - "bucketName": { "kind": "path", "displayName": "Bucket Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Bucket name or ARN" }, "autoCreateBucket": { "kind": "parameter", "displayName": "Auto Create Bucket", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.google.storage.GoogleCloudStorageComponentConfiguration", "configurationField": "configuration", "description": "Setting the autocreation of the bucket bucketName." }, "objectName": { "kind": "parameter", "displayName": "Object Name", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.google.storage.GoogleCloudStorageComponentConfiguration", "configurationField": "configuration", "description": "objectName" }, "serviceAccountCredentials": { "kind": "parameter", "displayName": "Service Account Credentials", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.google.storage.GoogleCloudStorageComponentConfiguration", "configurationField": "configuration", "description": "Specify the service account credentials file (json)" }, diff --git a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java index a82eab2..31ed2dc 100644 --- a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java +++ b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java @@ -15,18 +15,17 @@ import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.google.storage.client.StorageInternalClientFactory; -import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriPath; import org.apache.camel.support.ScheduledPollEndpoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * GoogleCloudStorage component which does bla bla. - * - * TODO: Update one line description above what the component does. + * Google Cloud Storage is an Object Storage to store any amount of data and retrieve it as often you like. + * + * Google Storage Endpoint definition represents a bucket within the storage and contains configuration + * to customize the behavior of Consumer and Producer. */ @UriEndpoint(firstVersion = "3.7.0", scheme = "google-storage", title = "Google Storage", syntax = "google-storage:bucketName", @@ -35,10 +34,6 @@ public class GoogleCloudStorageEndpoint extends ScheduledPollEndpoint { private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudStorageEndpoint.class); - @UriPath(description = "Bucket name or ARN") - @Metadata(required = true) - private String bucketName; // to support component docs - @UriParam private GoogleCloudStorageComponentConfiguration configuration; @@ -167,17 +162,4 @@ public class GoogleCloudStorageEndpoint extends ScheduledPollEndpoint { return exchange; } - public String getBucketName() { - return bucketName; - } - - /** - * Bucket name - * - * @param bucketName - */ - public void setBucketName(String bucketName) { - this.bucketName = bucketName; - } - } diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponentConfigurationTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponentConfigurationTest.java deleted file mode 100644 index e6977a2..0000000 --- a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponentConfigurationTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apache.camel.component.google.storage; - -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class GoogleCloudStorageComponentConfigurationTest extends CamelTestSupport { - - @Test - public void createEndpointWithMinimalConfiguration() throws Exception { - GoogleCloudStorageComponent component = context.getComponent("google-storage", GoogleCloudStorageComponent.class); - GoogleCloudStorageEndpoint endpoint = (GoogleCloudStorageEndpoint) component.createEndpoint( - "google-storage://rafa_test_bucket?serviceAccountCredentials=somefile.json"); - - assertEquals(endpoint.getConfiguration().getServiceAccountCredentials(), "somefile.json"); - } - -} diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ConsumerLocalTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ConsumerLocalTest.java similarity index 96% rename from components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ConsumerLocalTest.java rename to components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ConsumerLocalTest.java index 22c3a49..b6b3c4f 100644 --- a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ConsumerLocalTest.java +++ b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ConsumerLocalTest.java @@ -1,8 +1,9 @@ -package org.apache.camel.component.google.storage; +package org.apache.camel.component.google.storage.unit; import org.apache.camel.EndpointInject; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.storage.GoogleCloudStorageConstants; import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; import org.slf4j.Logger; diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageBaseTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageBaseTest.java similarity index 87% rename from components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageBaseTest.java rename to components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageBaseTest.java index 83d01f2..0bdf863 100644 --- a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/GoogleCloudStorageBaseTest.java +++ b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageBaseTest.java @@ -1,7 +1,8 @@ -package org.apache.camel.component.google.storage; +package org.apache.camel.component.google.storage.unit; import com.google.cloud.storage.Storage; import org.apache.camel.CamelContext; +import org.apache.camel.component.google.storage.GoogleCloudStorageComponent; import org.apache.camel.component.google.storage.localstorage.LocalStorageHelper; import org.apache.camel.test.junit5.CamelTestSupport; diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java new file mode 100644 index 0000000..73e5c89 --- /dev/null +++ b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java @@ -0,0 +1,54 @@ +package org.apache.camel.component.google.storage.unit; + +import org.apache.camel.component.google.storage.GoogleCloudStorageComponent; +import org.apache.camel.component.google.storage.GoogleCloudStorageComponentConfiguration; +import org.apache.camel.component.google.storage.GoogleCloudStorageEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class GoogleCloudStorageComponentConfigurationTest extends CamelTestSupport { + + @Test + public void createEndpointWithMinimalConfiguration() throws Exception { + final String bucketName = "myCamelBucket"; + final String serviceAccountCredentialsFile = "somefile.json"; + + GoogleCloudStorageComponent component = context.getComponent("google-storage", GoogleCloudStorageComponent.class); + GoogleCloudStorageEndpoint endpoint = (GoogleCloudStorageEndpoint) component.createEndpoint( + String.format("google-storage://%s?serviceAccountCredentials=%s", bucketName, serviceAccountCredentialsFile)); + + assertEquals(endpoint.getConfiguration().getBucketName(), bucketName); + assertEquals(endpoint.getConfiguration().getServiceAccountCredentials(), serviceAccountCredentialsFile); + } + + public void createEndpointForComplexConsumer() throws Exception { + + final String bucketName = "sourceCamelBucket"; + final String serviceAccountCredentialsFile = "somefile.json"; + final boolean moveAfterRead = false; + final String destinationBucket = "destinationCamelBucket"; + final boolean autoCreateBucket = true; + final boolean deleteAfterRead = false; + final boolean includeBody = true; + + GoogleCloudStorageComponent component = context.getComponent("google-storage", GoogleCloudStorageComponent.class); + GoogleCloudStorageEndpoint endpoint = (GoogleCloudStorageEndpoint) component.createEndpoint( + String.format( + "google-storage://%s?serviceAccountCredentials=%s&moveAfterRead=%s&destinationBucket=%s&autoCreateBucket=%s&deleteAfterRead=%s&includeBody=%s", + bucketName, serviceAccountCredentialsFile, moveAfterRead, destinationBucket, autoCreateBucket, + deleteAfterRead, includeBody)); + + GoogleCloudStorageComponentConfiguration configuration = endpoint.getConfiguration(); + assertEquals(configuration.getBucketName(), bucketName); + assertEquals(configuration.getServiceAccountCredentials(), serviceAccountCredentialsFile); + assertEquals(configuration.isMoveAfterRead(), moveAfterRead); + assertEquals(configuration.getDestinationBucket(), destinationBucket); + assertEquals(configuration.isAutoCreateBucket(), autoCreateBucket); + assertEquals(configuration.isDeleteAfterRead(), deleteAfterRead); + assertEquals(configuration.isIncludeBody(), includeBody); + + } + +} diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ProducerLocalTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ProducerLocalTest.java similarity index 96% rename from components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ProducerLocalTest.java rename to components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ProducerLocalTest.java index 71b2419..591c633 100644 --- a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/ProducerLocalTest.java +++ b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/ProducerLocalTest.java @@ -1,4 +1,4 @@ -package org.apache.camel.component.google.storage; +package org.apache.camel.component.google.storage.unit; import java.io.ByteArrayInputStream; import java.util.List; @@ -9,6 +9,8 @@ import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.storage.GoogleCloudStorageComponentOperations; +import org.apache.camel.component.google.storage.GoogleCloudStorageConstants; import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; import org.slf4j.Logger;