forked from Azure-Samples/quarkus-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure-Samples#4 from majguo/azure-storage-blob
Quarkus Azure storage blob extension - Dev Services and native executable
- Loading branch information
Showing
18 changed files
with
718 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
# quarkus-azure-services | ||
# Quarkiverse - Quarkus Azure Services | ||
|
||
This repository hosts Quarkus extensions for different Azure Services. | ||
|
||
The following services are implemented: | ||
|
||
- [StorageBlob](storage-blob): Support Dev Services. | ||
|
||
## Example applications | ||
|
||
Example applications can be found inside the integration-tests folder: | ||
|
||
- [integration-tests](integration-tests): RESTEasy endpoints using all the Azure Services extensions, to be deployed as | ||
a standalone JAR and a native executable. | ||
|
||
## Contributing | ||
|
||
Contributions are always welcome, but better create an issue to discuss them prior to any contributions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Quarkus Azure Services - Integration Tests | ||
|
||
This is the integration test for testing all Quarkus Azure services extensions from REST endpoints. | ||
|
||
## Running the test with Dev services | ||
|
||
Some Quarkus Azure services extensions support Dev Services, it allows to test easily. | ||
Launch these tests with: | ||
|
||
``` | ||
mvn test | ||
``` | ||
|
||
## Running the test with Azure services | ||
|
||
If you want to run all the test with real Azure services in the native mode, you need to create the dependent services | ||
on Azure after logging into Azure. | ||
|
||
### Logging into Azure | ||
|
||
Log into Azure and create a resource group for hosting different Azure services to be created. | ||
|
||
``` | ||
az login | ||
RESOURCE_GROUP_NAME=<resource-group-name> | ||
az group create \ | ||
--name ${RESOURCE_GROUP_NAME} \ | ||
--location eastus | ||
``` | ||
|
||
### Creating Azure Storage Account | ||
|
||
Run the following commands to create an Azure Storage Account and retrieve its connection string: | ||
|
||
``` | ||
STORAGE_ACCOUNT_NAME=<unique-storage-account-name> | ||
az storage account create \ | ||
--name ${STORAGE_ACCOUNT_NAME} \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--location eastus \ | ||
--sku Standard_LRS \ | ||
--kind StorageV2 | ||
STORAGE_ACCOUNT_CONNECTION_STRING=$(az storage account show-connection-string \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--name ${STORAGE_ACCOUNT_NAME} \ | ||
--query connectionString -o tsv) | ||
echo "The value of 'quarkus.azure.storage.blob.connection-string' is: ${STORAGE_ACCOUNT_CONNECTION_STRING}" | ||
``` | ||
|
||
### Running the test | ||
|
||
Copy the output of the following variables from previous steps: | ||
|
||
* **quarkus.azure.storage.blob.connection-string** | ||
|
||
Then update [application.properties](src/main/resources/application.properties) by uncommenting the relevant properties | ||
and setting copied values. | ||
|
||
Finally, build the native executable and launch the test with: | ||
|
||
``` | ||
mvn integration-test -Dnative | ||
``` | ||
|
||
### Cleaning up Azure resources | ||
|
||
Once you complete the test, run the following command to clean up the Azure resources used in the test: | ||
|
||
``` | ||
az group delete \ | ||
--name ${RESOURCE_GROUP_NAME} \ | ||
--yes --no-wait | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkiverse.azureservices</groupId> | ||
<artifactId>quarkus-azure-services-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>quarkus-azure-services-integration-tests</artifactId> | ||
<name>Quarkus Azure Services - Integration Tests</name> | ||
|
||
<properties> | ||
<skipITs>true</skipITs> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkiverse.azureservices</groupId> | ||
<artifactId>quarkus-azure-storage-blob</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<!-- See https://github.com/quarkusio/quarkus/issues/26879 | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-aot-graalvm-support</artifactId> | ||
<version>1.0.0-beta.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-aot-graalvm-support-netty</artifactId> | ||
<version>1.0.0-beta.3</version> | ||
</dependency> | ||
--> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native-image</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${native.surefire.skip}</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<skipITs>false</skipITs> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
...src/main/java/io/quarkiverse/azureservices/azure/storage/blob/it/StorageBlobResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 io.quarkiverse.azureservices.azure.storage.blob.it; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import com.azure.core.util.BinaryData; | ||
import com.azure.storage.blob.BlobClient; | ||
import com.azure.storage.blob.BlobContainerClient; | ||
import com.azure.storage.blob.BlobServiceClient; | ||
|
||
@Path("/azure-storage-blob") | ||
@ApplicationScoped | ||
public class StorageBlobResource { | ||
|
||
@Inject | ||
BlobServiceClient blobServiceClient; | ||
|
||
@GET | ||
public String hello() { | ||
BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainerIfNotExists("mycontainer"); | ||
BlobClient blobClient = blobContainerClient.getBlobClient("myblob"); | ||
blobClient.upload(BinaryData.fromString("Hello azure-storage-blob"), true); | ||
|
||
return blobClient.downloadContent().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Uncomment and set a valid connection string of an Azure Storage Account if you want to connect Azure. Otherwise, leave it to use Dev Services of Azure Storage Blob extension for development and testing purpose. | ||
#quarkus.azure.storage.blob.connection-string= |
7 changes: 7 additions & 0 deletions
7
...c/test/java/io/quarkiverse/azureservices/azure/storage/blob/it/StorageBlobResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkiverse.azureservices.azure.storage.blob.it; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class StorageBlobResourceIT extends StorageBlobResourceTest { | ||
} |
21 changes: 21 additions & 0 deletions
21
...test/java/io/quarkiverse/azureservices/azure/storage/blob/it/StorageBlobResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkiverse.azureservices.azure.storage.blob.it; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class StorageBlobResourceTest { | ||
|
||
@Test | ||
public void testHelloEndpoint() { | ||
given() | ||
.when().get("/azure-storage-blob") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello azure-storage-blob")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,3 @@ | ||
# Quarkus Azure Storage Blob | ||
|
||
[![Version](https://img.shields.io/maven-central/v/io.quarkiverse.azureservices/quarkus-azure-storage-blob?logo=apache-maven&style=flat-square)](https://search.maven.org/artifact/io.quarkiverse.azureservices/quarkus-azure-storage-blob) | ||
|
||
## Welcome to Quarkiverse! | ||
|
||
Congratulations and thank you for creating a new Quarkus extension project in Quarkiverse! | ||
|
||
Feel free to replace this content with the proper description of your new project and necessary instructions how to use and contribute to it. | ||
|
||
You can find the basic info, Quarkiverse policies and conventions in [the Quarkiverse wiki](https://github.com/quarkiverse/quarkiverse/wiki). | ||
|
||
In case you are creating a Quarkus extension project for the first time, please follow [Building My First Extension](https://quarkus.io/guides/building-my-first-extension) guide. | ||
|
||
Other useful articles related to Quarkus extension development can be found under the [Writing Extensions](https://quarkus.io/guides/#writing-extensions) guide category on the [Quarkus.io](https://quarkus.io) website. | ||
|
||
Thanks again, good luck and have fun! | ||
|
||
## Documentation | ||
|
||
The documentation for this extension should be maintained as part of this repository and it is stored in the `docs/` directory. | ||
|
||
The layout should follow the [Antora's Standard File and Directory Set](https://docs.antora.org/antora/2.3/standard-directories/). | ||
|
||
Once the docs are ready to be published, please open a PR including this repository in the [Quarkiverse Docs Antora playbook](https://github.com/quarkiverse/quarkiverse-docs/blob/main/antora-playbook.yml#L7). See an example [here](https://github.com/quarkiverse/quarkiverse-docs/pull/1). | ||
This extension allows to inject a `com.azure.storage.blob.BlobServiceClient` object inside your Quarkus application. |
Oops, something went wrong.