You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2020/11/23 13:24:46 UTC
[camel] branch master updated: Migrates the
camel-azure-storage-blob tests to the shared test infra (#4660)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 70b88e1 Migrates the camel-azure-storage-blob tests to the shared test infra (#4660)
70b88e1 is described below
commit 70b88e124563e0264bf0f6cadb561749dce9383b
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Nov 23 14:24:26 2020 +0100
Migrates the camel-azure-storage-blob tests to the shared test infra (#4660)
---
components/camel-azure-storage-blob/pom.xml | 27 ++++++--
.../azure/storage/blob/integration/BaseIT.java | 81 +++++++++-------------
.../azure/common/services/AzureStorageService.java | 6 +-
.../camel-test-infra-azure-storage-blob/pom.xml | 7 ++
.../blob/clients/AzureStorageBlobClientUtils.java | 61 ++++++++++++++++
5 files changed, 126 insertions(+), 56 deletions(-)
diff --git a/components/camel-azure-storage-blob/pom.xml b/components/camel-azure-storage-blob/pom.xml
index 7332b98..79c7172 100644
--- a/components/camel-azure-storage-blob/pom.xml
+++ b/components/camel-azure-storage-blob/pom.xml
@@ -83,14 +83,33 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>testcontainers</artifactId>
+ <artifactId>junit-jupiter</artifactId>
<version>${testcontainers-version}</version>
<scope>test</scope>
</dependency>
+
+ <!-- test infra -->
<dependency>
- <groupId>org.testcontainers</groupId>
- <artifactId>junit-jupiter</artifactId>
- <version>${testcontainers-version}</version>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-azure-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-azure-storage-blob</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BaseIT.java b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BaseIT.java
index cc14584..90591d0 100644
--- a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BaseIT.java
+++ b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BaseIT.java
@@ -16,85 +16,70 @@
*/
package org.apache.camel.component.azure.storage.blob.integration;
-import java.util.Properties;
-
import com.azure.storage.blob.BlobServiceClient;
-import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.common.StorageSharedKeyCredential;
import org.apache.camel.CamelContext;
import org.apache.camel.component.azure.storage.blob.BlobConfiguration;
-import org.apache.camel.component.azure.storage.blob.BlobTestUtils;
+import org.apache.camel.test.infra.azure.common.AzureConfigs;
+import org.apache.camel.test.infra.azure.common.services.AzureService;
+import org.apache.camel.test.infra.azure.storage.blob.clients.AzureStorageBlobClientUtils;
+import org.apache.camel.test.infra.azure.storage.blob.services.AzureStorageBlobServiceFactory;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
-import org.testcontainers.containers.GenericContainer;
+import org.junit.jupiter.api.extension.RegisterExtension;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BaseIT extends CamelTestSupport {
- private static final String ACCESS_KEY = "accessKey";
- private static final String ACCOUNT_NAME = "accountName";
- private static final String AZURITE_IMAGE_NAME = "mcr.microsoft.com/azure-storage/azurite:3.9.0";
- private static final int AZURITE_EXPOSED_PORT = 10000;
- private static String accountName;
- private static String accessKey;
- private static String endpoint;
+ @RegisterExtension
+ public static AzureService service;
protected BlobServiceClient serviceClient;
- protected BlobConfiguration configuration;
protected String containerName;
+ protected BlobConfiguration configuration;
static {
- // Start testcontainers as a singleton if needed
- initEndpoint();
- }
+ initCredentials();
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
- context.getRegistry().bind("serviceClient", serviceClient);
- return context;
+ service = AzureStorageBlobServiceFactory.createAzureService();
}
- static void initEndpoint() {
- accountName = System.getProperty(ACCOUNT_NAME);
- accessKey = System.getProperty(ACCESS_KEY);
- endpoint = String.format("https://%s.blob.core.windows.net", accountName);
+ /*
+ * The previous behavior of the test code was such that if accessKey or accountName properties were
+ * set, the code would not start the azurite container and would execute against a remote environment.
+ * To avoid breaking tests for environments relying on this behavior, copy the old properties into the
+ * new and set the test as remote.
+ */
+ private static void initCredentials() {
+ String accountName = System.getProperty("accountName");
+ String accessKey = System.getProperty("accessKey");
- // If everything is set, do not start Azurite
if (StringUtils.isNotEmpty(accountName) && StringUtils.isNotEmpty(accessKey)) {
- return;
- }
-
- if ((StringUtils.isEmpty(accountName) && StringUtils.isNotEmpty(accessKey)) ||
- (StringUtils.isNotEmpty(accountName) && StringUtils.isEmpty(accessKey))) {
- throw new IllegalArgumentException(
- "Make sure to supply both azure accessKey and accountName," +
- " e.g: mvn verify -DaccountName=myacc -DaccessKey=mykey");
+ System.setProperty(AzureConfigs.ACCOUNT_NAME, accountName);
+ System.setProperty(AzureConfigs.ACCOUNT_KEY, accessKey);
+ System.setProperty("azure.instance.type", "remote");
}
+ }
- final GenericContainer<?> azurite = new GenericContainer<>(AZURITE_IMAGE_NAME)
- .withExposedPorts(AZURITE_EXPOSED_PORT);
- azurite.start();
- Properties azuriteProperties = BlobTestUtils.getAzuriteProperties();
- accountName = azuriteProperties.getProperty(ACCOUNT_NAME);
- accessKey = azuriteProperties.getProperty(ACCESS_KEY);
- endpoint = String.format("http://%s:%d/%s", azurite.getContainerIpAddress(),
- azurite.getMappedPort(AZURITE_EXPOSED_PORT), accountName);
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.getRegistry().bind("serviceClient", serviceClient);
+ return context;
}
@BeforeAll
- void initProperties() {
+ public void initProperties() {
containerName = RandomStringUtils.randomAlphabetic(5).toLowerCase();
configuration = new BlobConfiguration();
- configuration.setCredentials(new StorageSharedKeyCredential(accountName, accessKey));
+ configuration.setCredentials(new StorageSharedKeyCredential(
+ service.azureCredentials().accountName(), service.azureCredentials().accountKey()));
configuration.setContainerName(containerName);
- serviceClient = new BlobServiceClientBuilder()
- .credential(configuration.getCredentials())
- .endpoint(endpoint)
- .buildClient();
+ serviceClient = AzureStorageBlobClientUtils.getClient();
}
+
}
diff --git a/test-infra/camel-test-infra-azure-common/src/test/java/org/apache/camel/test/infra/azure/common/services/AzureStorageService.java b/test-infra/camel-test-infra-azure-common/src/test/java/org/apache/camel/test/infra/azure/common/services/AzureStorageService.java
index b23e5d6..0cb1d55 100644
--- a/test-infra/camel-test-infra-azure-common/src/test/java/org/apache/camel/test/infra/azure/common/services/AzureStorageService.java
+++ b/test-infra/camel-test-infra-azure-common/src/test/java/org/apache/camel/test/infra/azure/common/services/AzureStorageService.java
@@ -26,10 +26,6 @@ public abstract class AzureStorageService implements AzureService, ContainerServ
private static final Logger LOG = LoggerFactory.getLogger(AzureStorageService.class);
private final AzuriteContainer container = new AzuriteContainer();
- public AzureStorageService() {
- container.start();
- }
-
public AzuriteContainer getContainer() {
return container;
}
@@ -42,6 +38,8 @@ public abstract class AzureStorageService implements AzureService, ContainerServ
@Override
public void initialize() {
+ container.start();
+
LOG.info("Azurite local blob service running at address {}:{}", container.getHost(),
container.getMappedPort(AzureServices.BLOB_SERVICE));
LOG.info("Azurite local queue service running at address {}:{}", container.getHost(),
diff --git a/test-infra/camel-test-infra-azure-storage-blob/pom.xml b/test-infra/camel-test-infra-azure-storage-blob/pom.xml
index f0b61aa..e5191b1 100644
--- a/test-infra/camel-test-infra-azure-storage-blob/pom.xml
+++ b/test-infra/camel-test-infra-azure-storage-blob/pom.xml
@@ -52,6 +52,13 @@
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
+
+ <!-- azure sdk -->
+ <dependency>
+ <groupId>com.azure</groupId>
+ <artifactId>azure-storage-blob</artifactId>
+ <version>${azure-storage-blob-java-sdk12-version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/test-infra/camel-test-infra-azure-storage-blob/src/test/java/org/apache/camel/test/infra/azure/storage/blob/clients/AzureStorageBlobClientUtils.java b/test-infra/camel-test-infra-azure-storage-blob/src/test/java/org/apache/camel/test/infra/azure/storage/blob/clients/AzureStorageBlobClientUtils.java
new file mode 100644
index 0000000..089214e
--- /dev/null
+++ b/test-infra/camel-test-infra-azure-storage-blob/src/test/java/org/apache/camel/test/infra/azure/storage/blob/clients/AzureStorageBlobClientUtils.java
@@ -0,0 +1,61 @@
+/*
+ * 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.test.infra.azure.storage.blob.clients;
+
+import com.azure.core.http.policy.HttpLogDetailLevel;
+import com.azure.core.http.policy.HttpLogOptions;
+import com.azure.storage.blob.BlobServiceClient;
+import com.azure.storage.blob.BlobServiceClientBuilder;
+import com.azure.storage.common.StorageSharedKeyCredential;
+import org.apache.camel.test.infra.azure.common.AzureConfigs;
+
+public final class AzureStorageBlobClientUtils {
+
+ private AzureStorageBlobClientUtils() {
+
+ }
+
+ public static BlobServiceClient getClient() {
+ String instanceType = System.getProperty("azure.instance.type");
+
+ String accountName = System.getProperty(AzureConfigs.ACCOUNT_NAME);
+ String accountKey = System.getProperty(AzureConfigs.ACCOUNT_KEY);
+ StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
+
+ String host = System.getProperty(AzureConfigs.HOST);
+ String port = System.getProperty(AzureConfigs.PORT);
+
+ String endpoint;
+
+ if (instanceType == null || instanceType.equals("local-azure-container")) {
+ endpoint = String.format("http://%s:%s/%s", host, port, accountName);
+ } else {
+ if (host == null || host.isEmpty()) {
+ endpoint = String.format("https://%s.blob.core.windows.net/%s", accountName, accountKey);
+ } else {
+ endpoint = String.format("http://%s:%s/%s", host, port, accountName);
+ }
+ }
+
+ return new BlobServiceClientBuilder()
+ .endpoint(endpoint)
+ .credential(credential)
+ .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).setPrettyPrintBody(true))
+ .buildClient();
+ }
+}