This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new ef2efe47710b CAMEL-27189: camel-google-storage - type converter from
String to StorageClass (#30435)
ef2efe47710b is described below
commit ef2efe47710b14d2533e707100abd642a8161539
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 18:55:07 2026 +0100
CAMEL-27189: camel-google-storage - type converter from String to
StorageClass (#30435)
StorageClass is not a Java enum but a StringEnumValue, and there was no type
converter for it, so the storageClass option could not be set from an
endpoint URI or a property. Add a converter that uses
StorageClass.valueOfStrict (an unknown name fails), and list the known
storage classes as enums of the option.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/catalog/components/google-storage.json | 4 +-
.../storage/GoogleCloudStorageConverterLoader.java | 60 ++++++++++++++++
.../component/google/storage/google-storage.json | 4 +-
.../services/org/apache/camel/TypeConverterLoader | 2 +
.../storage/GoogleCloudStorageConfiguration.java | 1 +
.../storage/GoogleCloudStorageConverter.java | 41 +++++++++++
.../unit/GoogleCloudStorageClassConverterTest.java | 80 ++++++++++++++++++++++
7 files changed, 188 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/google-storage.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/google-storage.json
index 0b3b659e1641..d8f7d50226a6 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/google-storage.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/google-storage.json
@@ -28,7 +28,7 @@
"configuration": { "index": 1, "kind": "property", "displayName":
"Configuration", "group": "common", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"deprecated": false, "autowired": false, "secret": false, "description": "The
component configuration" },
"objectName": { "index": 2, "kind": "property", "displayName": "Object
Name", "group": "common", "label": "common", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Object name inside
the bucket" },
"serviceAccountKey": { "index": 3, "kind": "property", "displayName":
"Service Account Key", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Service account key
that can be used as credentials for the Storage clie [...]
- "storageClass": { "index": 4, "kind": "property", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.StorageClass", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "STANDARD",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage class
to use when cr [...]
+ "storageClass": { "index": 4, "kind": "property", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"enum", "javaType": "com.google.cloud.storage.StorageClass", "enum": [
"STANDARD", "NEARLINE", "COLDLINE", "ARCHIVE", "REGIONAL", "MULTI_REGIONAL",
"DURABLE_REDUCED_AVAILABILITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "STANDARD", "configurationClass":
"org.apache.camel.component.google.storage.GoogleCl [...]
"storageClient": { "index": 5, "kind": "property", "displayName": "Storage
Client", "group": "common", "label": "", "required": false, "type": "object",
"javaType": "com.google.cloud.storage.Storage", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The storage client" },
"storageLocation": { "index": 6, "kind": "property", "displayName":
"Storage Location", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "US-EAST1",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage
location to use when creating the n [...]
"bridgeErrorHandler": { "index": 7, "kind": "property", "displayName":
"Bridge Error Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Allows for bridging the consumer to the Camel routing Error Handler, which
mean any exceptions (if possible) occurred while the Camel consumer is trying
to pickup incoming messages, or the like [...]
@@ -89,7 +89,7 @@
"autoCreateBucket": { "index": 1, "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.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "Setting the autocreation
of the bucket bucketName." },
"objectName": { "index": 2, "kind": "parameter", "displayName": "Object
Name", "group": "common", "label": "common", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Object name inside
the bucket" },
"serviceAccountKey": { "index": 3, "kind": "parameter", "displayName":
"Service Account Key", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Service account key
that can be used as credentials for the Storage cli [...]
- "storageClass": { "index": 4, "kind": "parameter", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.StorageClass", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "STANDARD",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage class
to use when c [...]
+ "storageClass": { "index": 4, "kind": "parameter", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"enum", "javaType": "com.google.cloud.storage.StorageClass", "enum": [
"STANDARD", "NEARLINE", "COLDLINE", "ARCHIVE", "REGIONAL", "MULTI_REGIONAL",
"DURABLE_REDUCED_AVAILABILITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "STANDARD", "configurationClass":
"org.apache.camel.component.google.storage.GoogleC [...]
"storageClient": { "index": 5, "kind": "parameter", "displayName":
"Storage Client", "group": "common", "label": "", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.Storage", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The storage client" },
"storageLocation": { "index": 6, "kind": "parameter", "displayName":
"Storage Location", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "US-EAST1",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage
location to use when creating the [...]
"deleteAfterRead": { "index": 7, "kind": "parameter", "displayName":
"Delete After Read", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true,
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "Delete objects from the
bucket after they have been retrieved [...]
diff --git
a/components/camel-google/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverterLoader.java
b/components/camel-google/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverterLoader.java
new file mode 100644
index 000000000000..07ea38545f2a
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/generated/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverterLoader.java
@@ -0,0 +1,60 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.google.storage;
+
+import javax.annotation.processing.Generated;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.DeferredContextBinding;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.TypeConverterLoaderGeneratorMojo")
+@SuppressWarnings("unchecked")
+@DeferredContextBinding
+public final class GoogleCloudStorageConverterLoader implements
TypeConverterLoader, CamelContextAware {
+
+ private CamelContext camelContext;
+
+ public GoogleCloudStorageConverterLoader() {
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void load(TypeConverterRegistry registry) throws
TypeConverterLoaderException {
+ registerConverters(registry);
+ }
+
+ private void registerConverters(TypeConverterRegistry registry) {
+ addTypeConverter(registry,
com.google.cloud.storage.StorageClass.class, java.lang.String.class, false,
+ (type, exchange, value) -> {
+ Object answer =
org.apache.camel.component.google.storage.GoogleCloudStorageConverter.toStorageClass((java.lang.String)
value);
+ if (false && answer == null) {
+ answer = Void.class;
+ }
+ return answer;
+ });
+ }
+
+ private static void addTypeConverter(TypeConverterRegistry registry,
Class<?> toType, Class<?> fromType, boolean allowNull,
SimpleTypeConverter.ConversionMethod method) {
+ registry.addTypeConverter(toType, fromType, new
SimpleTypeConverter(allowNull, method));
+ }
+}
diff --git
a/components/camel-google/camel-google-storage/src/generated/resources/META-INF/org/apache/camel/component/google/storage/google-storage.json
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/org/apache/camel/component/google/storage/google-storage.json
index 0b3b659e1641..d8f7d50226a6 100644
---
a/components/camel-google/camel-google-storage/src/generated/resources/META-INF/org/apache/camel/component/google/storage/google-storage.json
+++
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/org/apache/camel/component/google/storage/google-storage.json
@@ -28,7 +28,7 @@
"configuration": { "index": 1, "kind": "property", "displayName":
"Configuration", "group": "common", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"deprecated": false, "autowired": false, "secret": false, "description": "The
component configuration" },
"objectName": { "index": 2, "kind": "property", "displayName": "Object
Name", "group": "common", "label": "common", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Object name inside
the bucket" },
"serviceAccountKey": { "index": 3, "kind": "property", "displayName":
"Service Account Key", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Service account key
that can be used as credentials for the Storage clie [...]
- "storageClass": { "index": 4, "kind": "property", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.StorageClass", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "STANDARD",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage class
to use when cr [...]
+ "storageClass": { "index": 4, "kind": "property", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"enum", "javaType": "com.google.cloud.storage.StorageClass", "enum": [
"STANDARD", "NEARLINE", "COLDLINE", "ARCHIVE", "REGIONAL", "MULTI_REGIONAL",
"DURABLE_REDUCED_AVAILABILITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "STANDARD", "configurationClass":
"org.apache.camel.component.google.storage.GoogleCl [...]
"storageClient": { "index": 5, "kind": "property", "displayName": "Storage
Client", "group": "common", "label": "", "required": false, "type": "object",
"javaType": "com.google.cloud.storage.Storage", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The storage client" },
"storageLocation": { "index": 6, "kind": "property", "displayName":
"Storage Location", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "US-EAST1",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage
location to use when creating the n [...]
"bridgeErrorHandler": { "index": 7, "kind": "property", "displayName":
"Bridge Error Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Allows for bridging the consumer to the Camel routing Error Handler, which
mean any exceptions (if possible) occurred while the Camel consumer is trying
to pickup incoming messages, or the like [...]
@@ -89,7 +89,7 @@
"autoCreateBucket": { "index": 1, "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.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "Setting the autocreation
of the bucket bucketName." },
"objectName": { "index": 2, "kind": "parameter", "displayName": "Object
Name", "group": "common", "label": "common", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Object name inside
the bucket" },
"serviceAccountKey": { "index": 3, "kind": "parameter", "displayName":
"Service Account Key", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Service account key
that can be used as credentials for the Storage cli [...]
- "storageClass": { "index": 4, "kind": "parameter", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.StorageClass", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "STANDARD",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage class
to use when c [...]
+ "storageClass": { "index": 4, "kind": "parameter", "displayName": "Storage
Class", "group": "common", "label": "common", "required": false, "type":
"enum", "javaType": "com.google.cloud.storage.StorageClass", "enum": [
"STANDARD", "NEARLINE", "COLDLINE", "ARCHIVE", "REGIONAL", "MULTI_REGIONAL",
"DURABLE_REDUCED_AVAILABILITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "STANDARD", "configurationClass":
"org.apache.camel.component.google.storage.GoogleC [...]
"storageClient": { "index": 5, "kind": "parameter", "displayName":
"Storage Client", "group": "common", "label": "", "required": false, "type":
"object", "javaType": "com.google.cloud.storage.Storage", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The storage client" },
"storageLocation": { "index": 6, "kind": "parameter", "displayName":
"Storage Location", "group": "common", "label": "common", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "US-EAST1",
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "The Cloud Storage
location to use when creating the [...]
"deleteAfterRead": { "index": 7, "kind": "parameter", "displayName":
"Delete After Read", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true,
"configurationClass":
"org.apache.camel.component.google.storage.GoogleCloudStorageConfiguration",
"configurationField": "configuration", "description": "Delete objects from the
bucket after they have been retrieved [...]
diff --git
a/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 000000000000..d9bf32a99dfc
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.google.storage.GoogleCloudStorageConverterLoader
diff --git
a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConfiguration.java
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConfiguration.java
index 7bbcdf46eca8..0d811b3a05e6 100644
---
a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConfiguration.java
+++
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConfiguration.java
@@ -58,6 +58,7 @@ public class GoogleCloudStorageConfiguration implements
Cloneable, GoogleCommonC
private String storageLocation = "US-EAST1";
@UriParam(label = "common", defaultValue = "STANDARD",
+ enums =
"STANDARD,NEARLINE,COLDLINE,ARCHIVE,REGIONAL,MULTI_REGIONAL,DURABLE_REDUCED_AVAILABILITY",
description = "The Cloud Storage class to use when creating the
new buckets")
private StorageClass storageClass = StorageClass.STANDARD;
diff --git
a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverter.java
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverter.java
new file mode 100644
index 000000000000..5544bb088852
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConverter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.google.storage;
+
+import java.util.Locale;
+
+import com.google.cloud.storage.StorageClass;
+import org.apache.camel.Converter;
+
+/**
+ * Type converters for the Google Cloud Storage types that are not Java enums.
+ */
+@Converter(generateLoader = true)
+public final class GoogleCloudStorageConverter {
+
+ private GoogleCloudStorageConverter() {
+ }
+
+ /**
+ * Converts the name of a storage class, such as STANDARD or NEARLINE (any
case), to the {@link StorageClass} of
+ * that name. An unknown name fails, instead of creating a storage class
that Cloud Storage would reject.
+ */
+ @Converter
+ public static StorageClass toStorageClass(String value) {
+ return
StorageClass.valueOfStrict(value.trim().toUpperCase(Locale.ROOT));
+ }
+}
diff --git
a/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageClassConverterTest.java
b/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageClassConverterTest.java
new file mode 100644
index 000000000000..5673644bb2fc
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageClassConverterTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.google.storage.unit;
+
+import com.google.cloud.storage.Bucket;
+import com.google.cloud.storage.Storage;
+import com.google.cloud.storage.StorageClass;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.component.google.storage.GoogleCloudStorageComponent;
+import org.apache.camel.component.google.storage.GoogleCloudStorageEndpoint;
+import org.apache.camel.support.PropertyBindingSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * The storageClass option is set from the name of a storage class, in an
endpoint URI or as a property.
+ */
+public class GoogleCloudStorageClassConverterTest extends
GoogleCloudStorageBaseTest {
+
+ @Test
+ public void testStorageClassFromTheUri() {
+ GoogleCloudStorageEndpoint endpoint = context.getEndpoint(
+
"google-storage://coldbucket?autoCreateBucket=false&storageClass=NEARLINE",
GoogleCloudStorageEndpoint.class);
+
+
assertThat(endpoint.getConfiguration().getStorageClass()).isSameAs(StorageClass.NEARLINE);
+ }
+
+ @Test
+ public void testStorageClassNameIsNotCaseSensitive() {
+ GoogleCloudStorageEndpoint endpoint = context.getEndpoint(
+
"google-storage://coldbucket?autoCreateBucket=false&storageClass=coldline",
GoogleCloudStorageEndpoint.class);
+
+
assertThat(endpoint.getConfiguration().getStorageClass()).isSameAs(StorageClass.COLDLINE);
+ }
+
+ @Test
+ public void testStorageClassOnTheComponent() {
+ GoogleCloudStorageComponent component =
context.getComponent("google-storage", GoogleCloudStorageComponent.class);
+ // as camel.component.google-storage.storageClass=ARCHIVE binds it
+
PropertyBindingSupport.build().withConfigurer(component.getComponentPropertyConfigurer())
+ .bind(context, component, "storageClass", "ARCHIVE");
+
+
assertThat(component.getConfiguration().getStorageClass()).isSameAs(StorageClass.ARCHIVE);
+ }
+
+ @Test
+ public void testUnknownStorageClassFails() {
+ assertThatThrownBy(() ->
context.getEndpoint("google-storage://coldbucket?autoCreateBucket=false&storageClass=FROZEN"))
+ .isInstanceOf(ResolveEndpointFailedException.class)
+ .hasRootCauseInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void testAutoCreatedBucketGetsTheStorageClass() {
+ // the endpoint creates the bucket when it starts
+
context.getEndpoint("google-storage://nearlinebucket?autoCreateBucket=true&storageClass=NEARLINE&storageLocation=EU");
+
+ Storage storage = context.getComponent("google-storage",
GoogleCloudStorageComponent.class).getConfiguration()
+ .getStorageClient();
+ Bucket bucket = storage.get("nearlinebucket");
+ assertThat(bucket).isNotNull();
+ assertThat(bucket.getStorageClass()).isSameAs(StorageClass.NEARLINE);
+ }
+}