diff --git a/docs/modules/plugins/pages/plugin-azure-event-grid.adoc b/docs/modules/plugins/pages/plugin-azure-event-grid.adoc index 3c98f2ffdf..0a36c9aefa 100644 --- a/docs/modules/plugins/pages/plugin-azure-event-grid.adoc +++ b/docs/modules/plugins/pages/plugin-azure-event-grid.adoc @@ -74,6 +74,17 @@ include::partial$azure-profile-and-subscription.adoc[leveloffset=+1] ==== Collect system topics info +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.EventGrid/systemTopics` using API version `2021-12-01` and save it to variable `` +---- +==== + Collects system topics info in the specified resource group and saves it as JSON to a variable. For more information, see the https://docs.microsoft.com/en-us/rest/api/eventgrid/controlplane-version2021-12-01/system-topics/get[Azure Docs]. diff --git a/docs/modules/plugins/pages/plugin-azure-key-vault.adoc b/docs/modules/plugins/pages/plugin-azure-key-vault.adoc index c26cad2112..1f5b58fb61 100644 --- a/docs/modules/plugins/pages/plugin-azure-key-vault.adoc +++ b/docs/modules/plugins/pages/plugin-azure-key-vault.adoc @@ -24,6 +24,17 @@ include::partial$azure-profile-and-subscription.adoc[leveloffset=+1] ==== Retrieve the Key Vault properties +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.KeyVault/vaults/` using API version `2021-10-01` and save it to variable `` +---- +==== + Retrieves the properties of the specified Azure key vault and saves them as JSON to a variable. For more information, see the https://docs.microsoft.com/en-us/rest/api/keyvault/keyvault/vaults/get[Azure Docs]. diff --git a/docs/modules/plugins/pages/plugin-azure-sql-db.adoc b/docs/modules/plugins/pages/plugin-azure-sql-db.adoc index 53d418e648..8246536885 100644 --- a/docs/modules/plugins/pages/plugin-azure-sql-db.adoc +++ b/docs/modules/plugins/pages/plugin-azure-sql-db.adoc @@ -24,6 +24,17 @@ include::partial$azure-profile-and-subscription.adoc[leveloffset=+1] ==== Collect SQL Servers info +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers` using API version `2021-08-01-preview` and save it to variable `` +---- +==== + Collects the info about all the SQL Servers under the specified resource group and saves it as JSON to a variable. For more information, see the https://docs.microsoft.com/en-us/rest/api/sql/2021-08-01-preview/servers/list-by-resource-group[Azure Docs]. @@ -45,6 +56,17 @@ When I collect SQL Servers from resource group `TEST-SQL` and save them as JSON ==== Collect SQL Databases info +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers//databases` using API version `2021-08-01-preview` and save it to variable `` +---- +==== + Collects the info about all the databases belonging to the identified SQL Server under the specified resource group and saves it as JSON to a variable. For more information, see the @@ -68,6 +90,17 @@ When I collect databases from SQL Server `geography-server` from resource group ==== Retrieve the SQL Database properties +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers//databases/` using API version `2021-08-01-preview` and save it to variable `` +---- +==== + Retrieves the properties of the specified SQL Database belonging to the identified SQL Server and saves them as JSON to a variable. For more information, see the diff --git a/docs/modules/plugins/pages/plugin-azure-storage-account.adoc b/docs/modules/plugins/pages/plugin-azure-storage-account.adoc index 3f2804f930..6519fcb001 100644 --- a/docs/modules/plugins/pages/plugin-azure-storage-account.adoc +++ b/docs/modules/plugins/pages/plugin-azure-storage-account.adoc @@ -386,6 +386,17 @@ include::partial$azure-profile-and-subscription.adoc[leveloffset=+1] ==== Collect storage accounts info +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Storage/storageAccounts` using API version `2021-08-01` and save it to variable `` +---- +==== + Collects storage accounts info in the specified resource group and saves it as JSON to a variable. For more information, see the https://docs.microsoft.com/en-us/rest/api/storagerp/storage-accounts/list[Azure Docs]. @@ -413,6 +424,17 @@ When I collect storage accounts in resource group `TEST-SA` and save them as JSO ==== Retrieve the blob service properties +[WARNING] +==== +The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is +xref:plugins:plugin-azure-resource-manager.adoc#_get_information_about_azure_resource[the generic step retrieving information about Azure resources]. +The replacement pattern is: +[source,gherkin] +---- +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Storage/storageAccounts//blobServices/default` using API version `2021-08-01` and save it to variable `` +---- +==== + Retrieves the properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules, and saves them as JSON to a variable. For more information, see the diff --git a/vividus-extension-azure/build.gradle b/vividus-extension-azure/build.gradle index f2088f1243..1b3a79d733 100644 --- a/vividus-extension-azure/build.gradle +++ b/vividus-extension-azure/build.gradle @@ -3,8 +3,6 @@ project.description = 'Vividus extension for Azure Cloud' dependencies { api platform(group: 'com.azure', name: 'azure-sdk-bom', version: '1.2.5') api(group: 'com.azure', name: 'azure-identity') - implementation project(':vividus-engine') - implementation project(':vividus-soft-assert') testImplementation platform(group: 'org.junit', name: 'junit-bom', version: '5.9.0') testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter') diff --git a/vividus-extension-azure/src/main/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementSteps.java b/vividus-extension-azure/src/main/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementSteps.java deleted file mode 100644 index 5f6461ff81..0000000000 --- a/vividus-extension-azure/src/main/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementSteps.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.resourcemanager; - -import java.util.Set; -import java.util.function.Consumer; - -import com.azure.core.http.ContentType; -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; - -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import io.netty.handler.codec.http.HttpResponseStatus; - -public abstract class AbstractAzureResourceManagementSteps -{ - private final HttpPipeline httpPipeline; - private final String resourceManagerEndpoint; - private final ISoftAssert softAssert; - private final VariableContext variableContext; - - protected AbstractAzureResourceManagementSteps(HttpPipeline httpPipeline, String resourceManagerEndpoint, - ISoftAssert softAssert, VariableContext variableContext) - { - this.httpPipeline = httpPipeline; - this.resourceManagerEndpoint = resourceManagerEndpoint; - this.softAssert = softAssert; - this.variableContext = variableContext; - } - - protected void saveHttpGetResponseAsVariable(String urlPath, String apiVersion, Set scopes, - String variableName) - { - String url = buildUrl(urlPath, apiVersion); - HttpRequest httpRequest = new HttpRequest(HttpMethod.GET, url); - executeHttpRequest(httpRequest, - responseBody -> variableContext.putVariable(scopes, variableName, responseBody)); - } - - protected void saveHttpPostResponseAsVariable(String urlPath, String apiVersion, String requestBody, - Set scopes, String variableName) - { - HttpRequest httpRequest = createRequest(HttpMethod.POST, urlPath, apiVersion, requestBody); - executeHttpRequest(httpRequest, - responseBody -> variableContext.putVariable(scopes, variableName, responseBody)); - } - - protected void executeHttpPut(String urlPath, String apiVersion, String requestBody) - { - HttpRequest httpRequest = createRequest(HttpMethod.PUT, urlPath, apiVersion, requestBody); - executeHttpRequest(httpRequest, responseBody -> { }); - } - - protected void executeHttpDelete(String urlPath, String apiVersion) - { - String url = buildUrl(urlPath, apiVersion); - HttpRequest httpRequest = new HttpRequest(HttpMethod.DELETE, url); - executeHttpRequest(httpRequest, responseBody -> { }); - } - - private HttpRequest createRequest(HttpMethod method, String urlPath, String apiVersion, String azureResourceBody) - { - String url = buildUrl(urlPath, apiVersion); - HttpRequest httpRequest = new HttpRequest(method, url); - httpRequest.setBody(azureResourceBody); - httpRequest.setHeader("Content-Type", ContentType.APPLICATION_JSON); - return httpRequest; - } - - private void executeHttpRequest(HttpRequest httpRequest, Consumer responseBodyConsumer) - { - try (HttpResponse httpResponse = httpPipeline.send(httpRequest).block()) - { - String responseBody = httpResponse.getBodyAsString().block(); - if (httpResponse.getStatusCode() == HttpResponseStatus.OK.code()) - { - responseBodyConsumer.accept(responseBody); - } - else - { - softAssert.recordFailedAssertion("Azure REST API HTTP request execution is failed: " + responseBody); - } - } - } - - private String buildUrl(String urlPath, String apiVersion) - { - // Workaround for https://github.com/Azure/azure-sdk-for-java/issues/27268 - return resourceManagerEndpoint + urlPath + "?api-version=" + apiVersion; - } -} diff --git a/vividus-extension-azure/src/test/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementStepsTests.java b/vividus-extension-azure/src/test/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementStepsTests.java deleted file mode 100644 index 1d8e46295b..0000000000 --- a/vividus-extension-azure/src/test/java/org/vividus/azure/resourcemanager/AbstractAzureResourceManagementStepsTests.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.resourcemanager; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.nio.charset.StandardCharsets; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class AbstractAzureResourceManagementStepsTests -{ - private static final String URL_PATH = "subscriptions/sub-id/resourceGroups/rgname/providers/Microsoft" - + ".KeyVault/vaults/sample-vault"; - private static final String API_VERSION = "2021-10-01"; - private static final Set SCOPES = Set.of(VariableScope.STORY); - private static final String VAR_NAME = "varName"; - private static final String REQUEST_BODY = "{\"azure-resource\":\"body\"}"; - - @Mock private HttpPipeline httpPipeline; - @Mock private ISoftAssert softAssert; - @Mock private VariableContext variableContext; - - @Test - void shouldSaveHttpGetResponseInCaseOfSuccess() - { - var response = testHttpRequestExecution(200, - steps -> steps.saveHttpGetResponseAsVariable(URL_PATH, API_VERSION, SCOPES, VAR_NAME), - httpRequest -> assertEquals(HttpMethod.GET, httpRequest.getHttpMethod())); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - } - - @Test - void shouldSaveHttpPostResponseInCaseOfSuccess() - { - var response = testHttpRequestExecution(200, - steps -> steps.saveHttpPostResponseAsVariable(URL_PATH, API_VERSION, REQUEST_BODY, SCOPES, VAR_NAME), - httpRequest -> assertHttpRequestWithBody(HttpMethod.POST, httpRequest)); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - } - - @Test - void shouldRecordFailedAssertionInCaseOfFailure() - { - var response = testHttpRequestExecution(404, - steps -> steps.saveHttpGetResponseAsVariable(URL_PATH, API_VERSION, SCOPES, VAR_NAME), - httpRequest -> assertEquals(HttpMethod.GET, httpRequest.getHttpMethod())); - verify(softAssert).recordFailedAssertion("Azure REST API HTTP request execution is failed: " + response); - } - - @Test - void shouldExecuteHttpPutRequest() - { - testHttpRequestExecution(200, steps -> steps.executeHttpPut(URL_PATH, API_VERSION, REQUEST_BODY), - httpRequest -> assertHttpRequestWithBody(HttpMethod.PUT, httpRequest)); - } - - @Test - void shouldExecuteHttpDeleteRequest() - { - testHttpRequestExecution(200, steps -> steps.executeHttpDelete(URL_PATH, API_VERSION), - httpRequest -> assertEquals(HttpMethod.DELETE, httpRequest.getHttpMethod())); - } - - private String testHttpRequestExecution(int statusCode, Consumer test, - Consumer httpRequestValidator) - { - var responseAsString = "{\"key\":\"value\"}"; - var httpResponse = mock(HttpResponse.class); - when(httpResponse.getStatusCode()).thenReturn(statusCode); - when(httpResponse.getBodyAsString()).thenReturn(Mono.just(responseAsString)); - var httpRequestCaptor = ArgumentCaptor.forClass(HttpRequest.class); - when(httpPipeline.send(httpRequestCaptor.capture())).thenReturn(Mono.just(httpResponse)); - - var resourceManagerEndpoint = "https://management.azure.com/"; - var steps = new TestSteps(httpPipeline, resourceManagerEndpoint, softAssert, variableContext); - test.accept(steps); - var httpRequest = httpRequestCaptor.getValue(); - assertEquals(resourceManagerEndpoint + URL_PATH + "?api-version=" + API_VERSION, - httpRequest.getUrl().toString()); - httpRequestValidator.accept(httpRequest); - return responseAsString; - } - - private void assertHttpRequestWithBody(HttpMethod httpMethod, HttpRequest httpRequest) - { - assertEquals(httpMethod, httpRequest.getHttpMethod()); - assertEquals(REQUEST_BODY, new String(httpRequest.getBody().blockFirst().array(), StandardCharsets.UTF_8)); - var expectedHeaders = Map.of( - "Content-Type", "application/json", - "Content-Length", Integer.toString(REQUEST_BODY.length()) - ); - assertEquals(expectedHeaders, httpRequest.getHeaders().toMap()); - } - - private static class TestSteps extends AbstractAzureResourceManagementSteps - { - protected TestSteps(HttpPipeline httpPipeline, String resourceManagerEndpoint, ISoftAssert softAssert, - VariableContext variableContext) - { - super(httpPipeline, resourceManagerEndpoint, softAssert, variableContext); - } - } -} diff --git a/vividus-plugin-azure-event-grid/build.gradle b/vividus-plugin-azure-event-grid/build.gradle index 1b86e8f756..71c582abe7 100644 --- a/vividus-plugin-azure-event-grid/build.gradle +++ b/vividus-plugin-azure-event-grid/build.gradle @@ -5,14 +5,13 @@ dependencies { implementation project(':vividus-util') implementation project(':vividus-extension-azure') implementation project(':vividus-soft-assert') + implementation project(':vividus-plugin-azure-resource-manager') implementation platform(group: 'com.azure', name: 'azure-sdk-bom', version: '1.2.5') implementation(group: 'com.azure', name: 'azure-messaging-eventgrid') - implementation(group: 'com.azure.resourcemanager', name: 'azure-resourcemanager-resources', version: '2.18.0') testImplementation platform(group: 'org.junit', name: 'junit-bom', version: '5.9.0') testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter') testImplementation platform(group: 'org.mockito', name: 'mockito-bom', version: '4.8.0') testImplementation(group: 'org.mockito', name: 'mockito-junit-jupiter') testImplementation(group: 'org.mockito', name: 'mockito-inline') - testImplementation(group: 'org.junit-pioneer', name: 'junit-pioneer', version: '1.7.1') } diff --git a/vividus-plugin-azure-event-grid/src/main/java/org/vividus/azure/eventgrid/EventGridManagementSteps.java b/vividus-plugin-azure-event-grid/src/main/java/org/vividus/azure/eventgrid/EventGridManagementSteps.java deleted file mode 100644 index a45f29fcb3..0000000000 --- a/vividus-plugin-azure-event-grid/src/main/java/org/vividus/azure/eventgrid/EventGridManagementSteps.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.eventgrid; - -import java.util.Set; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.jbehave.core.annotations.When; -import org.vividus.azure.resourcemanager.AbstractAzureResourceManagementSteps; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -public class EventGridManagementSteps extends AbstractAzureResourceManagementSteps -{ - private static final String API_VERSION = "2021-12-01"; - - private final AzureProfile azureProfile; - - public EventGridManagementSteps(AzureProfile azureProfile, TokenCredential tokenCredential, ISoftAssert softAssert, - VariableContext variableContext) - { - super(HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile), - azureProfile.getEnvironment().getResourceManagerEndpoint(), softAssert, variableContext); - this.azureProfile = azureProfile; - } - - /** - * Collects the info about all the system topics info under the specified resource group and saves it as JSON to a - * variable. For more information, see the Azure - * Docs. - * @param resourceGroupName The name of the resource group within the user's subscription to list the system - * topics from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the blob properties. - */ - @When("I collect system topics in resource group `$resourceGroupName` and save them as JSON to $scopes variable " - + "`$variableName`") - public void listSystemTopics(String resourceGroupName, Set scopes, String variableName) - { - String urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/systemTopics", - azureProfile.getSubscriptionId(), resourceGroupName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } -} diff --git a/vividus-plugin-azure-event-grid/src/main/resources/steps/defaults/composite.steps b/vividus-plugin-azure-event-grid/src/main/resources/steps/defaults/composite.steps new file mode 100644 index 0000000000..a0f400ccf0 --- /dev/null +++ b/vividus-plugin-azure-event-grid/src/main/resources/steps/defaults/composite.steps @@ -0,0 +1,3 @@ +Composite: When I collect system topics in resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I collect system topics in resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.EventGrid/systemTopics` using API version `2021-12-01` and save it to variable `` diff --git a/vividus-plugin-azure-event-grid/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-azure-event-grid/src/main/resources/vividus-plugin/spring.xml index daaa726cb4..1e6bb32171 100644 --- a/vividus-plugin-azure-event-grid/src/main/resources/vividus-plugin/spring.xml +++ b/vividus-plugin-azure-event-grid/src/main/resources/vividus-plugin/spring.xml @@ -18,16 +18,7 @@ - - - - - - - - - diff --git a/vividus-plugin-azure-event-grid/src/test/java/org/vividus/azure/eventgrid/EventGridManagementStepsTests.java b/vividus-plugin-azure-event-grid/src/test/java/org/vividus/azure/eventgrid/EventGridManagementStepsTests.java deleted file mode 100644 index 1ee5666a11..0000000000 --- a/vividus-plugin-azure-event-grid/src/test/java/org/vividus/azure/eventgrid/EventGridManagementStepsTests.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.eventgrid; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Named.named; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Stream; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; -import com.azure.core.management.AzureEnvironment; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.Named; -import org.junit.jupiter.api.TestFactory; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.SetSystemProperty; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class EventGridManagementStepsTests -{ - private static final String SUBSCRIPTION_ID_PROPERTY_NAME = "AZURE_SUBSCRIPTION_ID"; - private static final String SUBSCRIPTION_ID_PROPERTY_VALUE = "subscription-id"; - - private static final String RESOURCE_GROUP_NAME = "resourceGroupName"; - private static final Set SCOPES = Set.of(VariableScope.STORY); - private static final String VAR_NAME = "varName"; - - @Mock private TokenCredential tokenCredential; - @Mock private ISoftAssert softAssert; - @Mock private VariableContext variableContext; - - private Stream, String>>> createStreamOfTests() - { - return Stream.of( - named("success", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 200, expectedUrlPath); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - }), - named("failure", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 404, expectedUrlPath); - verify(softAssert).recordFailedAssertion( - "Azure REST API HTTP request execution is failed: " + response); - }) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldRetrieveKeyVaultProperties() - { - var urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/systemTopics", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME); - return DynamicTest.stream(createStreamOfTests(), - test -> test.accept(steps -> steps.listSystemTopics(RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), - urlPath) - ); - } - - @SuppressWarnings("PMD.CloseResource") - private String testHttpRequestExecution(Consumer test, int statusCode, - String expectedUrlPath) - { - var azureProfile = new AzureProfile(AzureEnvironment.AZURE); - try (MockedStatic httpPipelineProviderMock = mockStatic(HttpPipelineProvider.class)) - { - var httpPipeline = mock(HttpPipeline.class); - httpPipelineProviderMock.when(() -> HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile)) - .thenReturn(httpPipeline); - var responseAsString = "{\"key\":\"value\"}"; - var httpResponse = mock(HttpResponse.class); - when(httpResponse.getStatusCode()).thenReturn(statusCode); - when(httpResponse.getBodyAsString()).thenReturn(Mono.just(responseAsString)); - var httpRequestCaptor = ArgumentCaptor.forClass(HttpRequest.class); - when(httpPipeline.send(httpRequestCaptor.capture())).thenReturn(Mono.just(httpResponse)); - - var steps = new EventGridManagementSteps(azureProfile, tokenCredential, softAssert, variableContext); - test.accept(steps); - var httpRequest = httpRequestCaptor.getValue(); - assertEquals(HttpMethod.GET, httpRequest.getHttpMethod()); - assertEquals("https://management.azure.com/" + expectedUrlPath + "?api-version=2021-12-01", - httpRequest.getUrl().toString()); - return responseAsString; - } - } -} diff --git a/vividus-plugin-azure-key-vault/build.gradle b/vividus-plugin-azure-key-vault/build.gradle index ce1f7bd1bd..5806adb909 100644 --- a/vividus-plugin-azure-key-vault/build.gradle +++ b/vividus-plugin-azure-key-vault/build.gradle @@ -1,15 +1,5 @@ project.description = 'Vividus plugin for Azure Key Vault' dependencies { - api project(':vividus-engine') - implementation project(':vividus-extension-azure') - implementation project(':vividus-soft-assert') - implementation(group: 'com.azure.resourcemanager', name: 'azure-resourcemanager-resources', version: '2.18.0') - - testImplementation platform(group: 'org.junit', name: 'junit-bom', version: '5.9.0') - testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter') - testImplementation platform(group: 'org.mockito', name: 'mockito-bom', version: '4.8.0') - testImplementation(group: 'org.mockito', name: 'mockito-junit-jupiter') - testImplementation(group: 'org.mockito', name: 'mockito-inline') - testImplementation(group: 'org.junit-pioneer', name: 'junit-pioneer', version: '1.7.1') + implementation project(':vividus-plugin-azure-resource-manager') } diff --git a/vividus-plugin-azure-key-vault/src/main/java/org/vividus/azure/keyvault/KeyVaultManagementSteps.java b/vividus-plugin-azure-key-vault/src/main/java/org/vividus/azure/keyvault/KeyVaultManagementSteps.java deleted file mode 100644 index c6a8867122..0000000000 --- a/vividus-plugin-azure-key-vault/src/main/java/org/vividus/azure/keyvault/KeyVaultManagementSteps.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.keyvault; - -import java.util.Set; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.jbehave.core.annotations.When; -import org.vividus.azure.resourcemanager.AbstractAzureResourceManagementSteps; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -public class KeyVaultManagementSteps extends AbstractAzureResourceManagementSteps -{ - private static final String API_VERSION = "2021-10-01"; - - private final AzureProfile azureProfile; - - public KeyVaultManagementSteps(AzureProfile azureProfile, TokenCredential tokenCredential, ISoftAssert softAssert, - VariableContext variableContext) - { - super(HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile), - azureProfile.getEnvironment().getResourceManagerEndpoint(), softAssert, variableContext); - this.azureProfile = azureProfile; - } - - /** - * Retrieves the properties of the specified Azure key vault and saves them as JSON to a variable. For more - * information, see the - * Azure Docs. - * - * @param keyVaultName The name of the key vault within the specified resource group. - * @param resourceGroupName The name of the resource group within the user's subscription to retrieve the key - * vault from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the key vault properties as JSON. - */ - @When("I retrieve properties of key vault with name `$keyVaultName` from resource group `$resourceGroupName` and " - + "save them as JSON to $scopes variable `$variableName`") - public void retrieveKeyVaultProperties(String keyVaultName, String resourceGroupName, Set scopes, - String variableName) - { - String urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/vaults/%s", - azureProfile.getSubscriptionId(), resourceGroupName, keyVaultName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } -} diff --git a/vividus-plugin-azure-key-vault/src/main/resources/steps/defaults/composite.steps b/vividus-plugin-azure-key-vault/src/main/resources/steps/defaults/composite.steps new file mode 100644 index 0000000000..007a9c21bc --- /dev/null +++ b/vividus-plugin-azure-key-vault/src/main/resources/steps/defaults/composite.steps @@ -0,0 +1,3 @@ +Composite: When I retrieve properties of key vault with name `$keyVaultName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I retrieve properties of key vault with name `$keyVaultName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.KeyVault/vaults/` using API version `2021-10-01` and save it to variable `` diff --git a/vividus-plugin-azure-key-vault/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-azure-key-vault/src/main/resources/vividus-plugin/spring.xml deleted file mode 100644 index e1a126f9b9..0000000000 --- a/vividus-plugin-azure-key-vault/src/main/resources/vividus-plugin/spring.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/vividus-plugin-azure-key-vault/src/test/java/org/vividus/azure/keyvault/KeyVaultManagementStepsTests.java b/vividus-plugin-azure-key-vault/src/test/java/org/vividus/azure/keyvault/KeyVaultManagementStepsTests.java deleted file mode 100644 index eed6e51ee9..0000000000 --- a/vividus-plugin-azure-key-vault/src/test/java/org/vividus/azure/keyvault/KeyVaultManagementStepsTests.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.keyvault; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Named.named; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Stream; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; -import com.azure.core.management.AzureEnvironment; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.Named; -import org.junit.jupiter.api.TestFactory; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.SetSystemProperty; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class KeyVaultManagementStepsTests -{ - private static final String SUBSCRIPTION_ID_PROPERTY_NAME = "AZURE_SUBSCRIPTION_ID"; - private static final String SUBSCRIPTION_ID_PROPERTY_VALUE = "subscription-id"; - - private static final String RESOURCE_GROUP_NAME = "resourceGroupName"; - private static final String KEY_VAULT_NAME = "keyVaultName"; - private static final Set SCOPES = Set.of(VariableScope.STORY); - private static final String VAR_NAME = "varName"; - - @Mock private TokenCredential tokenCredential; - @Mock private ISoftAssert softAssert; - @Mock private VariableContext variableContext; - - private Stream, String>>> createStreamOfTests() - { - return Stream.of( - named("success", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 200, expectedUrlPath); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - }), - named("failure", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 404, expectedUrlPath); - verify(softAssert).recordFailedAssertion( - "Azure REST API HTTP request execution is failed: " + response); - }) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldRetrieveKeyVaultProperties() - { - var urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/vaults/%s", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME, KEY_VAULT_NAME); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.retrieveKeyVaultProperties(KEY_VAULT_NAME, RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), - urlPath) - ); - } - - @SuppressWarnings("PMD.CloseResource") - private String testHttpRequestExecution(Consumer test, int statusCode, - String expectedUrlPath) - { - var azureProfile = new AzureProfile(AzureEnvironment.AZURE); - try (MockedStatic httpPipelineProviderMock = mockStatic(HttpPipelineProvider.class)) - { - var httpPipeline = mock(HttpPipeline.class); - httpPipelineProviderMock.when(() -> HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile)) - .thenReturn(httpPipeline); - var responseAsString = "{\"key\":\"value\"}"; - var httpResponse = mock(HttpResponse.class); - when(httpResponse.getStatusCode()).thenReturn(statusCode); - when(httpResponse.getBodyAsString()).thenReturn(Mono.just(responseAsString)); - var httpRequestCaptor = ArgumentCaptor.forClass(HttpRequest.class); - when(httpPipeline.send(httpRequestCaptor.capture())).thenReturn(Mono.just(httpResponse)); - - var steps = new KeyVaultManagementSteps(azureProfile, tokenCredential, softAssert, variableContext); - test.accept(steps); - var httpRequest = httpRequestCaptor.getValue(); - assertEquals(HttpMethod.GET, httpRequest.getHttpMethod()); - assertEquals("https://management.azure.com/" + expectedUrlPath + "?api-version=2021-10-01", - httpRequest.getUrl().toString()); - return responseAsString; - } - } -} diff --git a/vividus-plugin-azure-resource-manager/src/main/java/org/vividus/azure/resourcemanager/ResourceManagementSteps.java b/vividus-plugin-azure-resource-manager/src/main/java/org/vividus/azure/resourcemanager/ResourceManagementSteps.java index 05b12f11bb..2227b8276c 100644 --- a/vividus-plugin-azure-resource-manager/src/main/java/org/vividus/azure/resourcemanager/ResourceManagementSteps.java +++ b/vividus-plugin-azure-resource-manager/src/main/java/org/vividus/azure/resourcemanager/ResourceManagementSteps.java @@ -16,9 +16,16 @@ package org.vividus.azure.resourcemanager; +import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; import com.azure.core.credential.TokenCredential; +import com.azure.core.http.ContentType; +import com.azure.core.http.HttpMethod; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; import com.azure.core.management.profile.AzureProfile; import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; @@ -28,15 +35,21 @@ import org.vividus.softassert.ISoftAssert; import org.vividus.variable.VariableScope; -public class ResourceManagementSteps extends AbstractAzureResourceManagementSteps +import io.netty.handler.codec.http.HttpResponseStatus; + +public class ResourceManagementSteps { + private final HttpPipeline httpPipeline; + private final ISoftAssert softAssert; + private final VariableContext variableContext; private final AzureProfile azureProfile; public ResourceManagementSteps(AzureProfile azureProfile, TokenCredential tokenCredential, ISoftAssert softAssert, VariableContext variableContext) { - super(HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile), - azureProfile.getEnvironment().getResourceManagerEndpoint(), softAssert, variableContext); + this.httpPipeline = HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile); + this.softAssert = softAssert; + this.variableContext = variableContext; this.azureProfile = azureProfile; } @@ -75,8 +88,8 @@ public ResourceManagementSteps(AzureProfile azureProfile, TokenCredential tokenC public void saveAzureResourceAsVariable(String azureResourceIdentifier, String apiVersion, Set scopes, String variableName) { - String urlPath = buildUrlPath(azureResourceIdentifier); - saveHttpGetResponseAsVariable(urlPath, apiVersion, scopes, variableName); + executeHttpRequest(HttpMethod.GET, azureResourceIdentifier, apiVersion, Optional.empty(), + responseBody -> variableContext.putVariable(scopes, variableName, responseBody)); } /** @@ -110,13 +123,14 @@ public void saveAzureResourceAsVariable(String azureResourceIdentifier, String a * * @param variableName The variable name to store the result of Azure operation execution. */ + @SuppressWarnings("PMD.UseObjectForClearerAPI") @When("I execute Azure operation with identifier `$azureOperationIdentifier` using API version `$apiVersion` and " + "body `$azureOperationBody` and save result to $scopes variable `$variableName`") public void executeOperationAtAzureResource(String azureOperationIdentifier, String apiVersion, String azureOperationBody, Set scopes, String variableName) { - String urlPath = buildUrlPath(azureOperationIdentifier); - saveHttpPostResponseAsVariable(urlPath, apiVersion, azureOperationBody, scopes, variableName); + executeHttpRequest(HttpMethod.POST, azureOperationIdentifier, apiVersion, Optional.of(azureOperationBody), + responseBody -> variableContext.putVariable(scopes, variableName, responseBody)); } /** @@ -144,8 +158,8 @@ public void executeOperationAtAzureResource(String azureOperationIdentifier, Str + "API version `$apiVersion`") public void configureAzureResource(String azureResourceIdentifier, String azureResourceBody, String apiVersion) { - String urlPath = buildUrlPath(azureResourceIdentifier); - executeHttpPut(urlPath, apiVersion, azureResourceBody); + executeHttpRequest(HttpMethod.PUT, azureResourceIdentifier, apiVersion, Optional.of(azureResourceBody), + responseBody -> { }); } /** @@ -170,13 +184,34 @@ public void configureAzureResource(String azureResourceIdentifier, String azureR @When("I delete Azure resource with identifier `$azureResourceIdentifier` using API version `$apiVersion`") public void deleteAzureResource(String azureResourceIdentifier, String apiVersion) { - String urlPath = buildUrlPath(azureResourceIdentifier); - executeHttpDelete(urlPath, apiVersion); + executeHttpRequest(HttpMethod.DELETE, azureResourceIdentifier, apiVersion, Optional.empty(), + responseBody -> { }); } - private String buildUrlPath(String azureResourceIdentifier) + private void executeHttpRequest(HttpMethod method, String azureResourceIdentifier, String apiVersion, + Optional azureResourceBody, Consumer responseBodyConsumer) { - return "subscriptions/" + azureProfile.getSubscriptionId() + StringUtils.prependIfMissing( - azureResourceIdentifier, "/"); + String url = String.format("%ssubscriptions/%s%s?api-version=%s", + azureProfile.getEnvironment().getResourceManagerEndpoint(), azureProfile.getSubscriptionId(), + StringUtils.prependIfMissing(azureResourceIdentifier, "/"), apiVersion); + + HttpRequest httpRequest = new HttpRequest(method, url); + azureResourceBody.ifPresent(requestBody -> { + httpRequest.setBody(requestBody); + httpRequest.setHeader("Content-Type", ContentType.APPLICATION_JSON); + }); + + try (HttpResponse httpResponse = httpPipeline.send(httpRequest).block()) + { + String responseBody = httpResponse.getBodyAsString().block(); + if (httpResponse.getStatusCode() == HttpResponseStatus.OK.code()) + { + responseBodyConsumer.accept(responseBody); + } + else + { + softAssert.recordFailedAssertion("Azure REST API HTTP request execution is failed: " + responseBody); + } + } } } diff --git a/vividus-plugin-azure-resource-manager/src/test/java/org/vividus/azure/resourcemanager/ResourceManagementStepsTests.java b/vividus-plugin-azure-resource-manager/src/test/java/org/vividus/azure/resourcemanager/ResourceManagementStepsTests.java index 8dc54b13fa..27e3fd899c 100644 --- a/vividus-plugin-azure-resource-manager/src/test/java/org/vividus/azure/resourcemanager/ResourceManagementStepsTests.java +++ b/vividus-plugin-azure-resource-manager/src/test/java/org/vividus/azure/resourcemanager/ResourceManagementStepsTests.java @@ -92,7 +92,7 @@ private Stream, String>>> cre @TestFactory @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldSaveAzureResourceAsVariable() + Stream testSavingOfAzureResourceAsVariable() { return DynamicTest.stream(createTestsCreatingResources(), test -> test.accept( steps -> steps.saveAzureResourceAsVariable(AZURE_RESOURCE_IDENTIFIER, API_VERSION, SCOPES, VAR_NAME), @@ -120,7 +120,7 @@ private Stream, String>>> cre @TestFactory @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldExecuteOperationAtAzureResource() + Stream testExecutionOfOperationAtAzureResource() { return DynamicTest.stream(createTestsExecutionOperations(), test -> test.accept( steps -> steps.executeOperationAtAzureResource(AZURE_RESOURCE_IDENTIFIER, API_VERSION, REQUEST_BODY, diff --git a/vividus-plugin-azure-sql-db/build.gradle b/vividus-plugin-azure-sql-db/build.gradle index 7de341a3fb..fc68b65c75 100644 --- a/vividus-plugin-azure-sql-db/build.gradle +++ b/vividus-plugin-azure-sql-db/build.gradle @@ -1,15 +1,5 @@ project.description = 'Vividus plugin for Azure SQL Databse' dependencies { - api project(':vividus-engine') - implementation project(':vividus-extension-azure') - implementation project(':vividus-soft-assert') - implementation(group: 'com.azure.resourcemanager', name: 'azure-resourcemanager-resources', version: '2.18.0') - - testImplementation platform(group: 'org.junit', name: 'junit-bom', version: '5.9.0') - testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter') - testImplementation platform(group: 'org.mockito', name: 'mockito-bom', version: '4.8.0') - testImplementation(group: 'org.mockito', name: 'mockito-junit-jupiter') - testImplementation(group: 'org.mockito', name: 'mockito-inline') - testImplementation(group: 'org.junit-pioneer', name: 'junit-pioneer', version: '1.7.1') + implementation project(':vividus-plugin-azure-resource-manager') } diff --git a/vividus-plugin-azure-sql-db/src/main/java/org/vividus/azure/sql/SqlDatabaseManagementSteps.java b/vividus-plugin-azure-sql-db/src/main/java/org/vividus/azure/sql/SqlDatabaseManagementSteps.java deleted file mode 100644 index 76d2bdb66e..0000000000 --- a/vividus-plugin-azure-sql-db/src/main/java/org/vividus/azure/sql/SqlDatabaseManagementSteps.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.sql; - -import java.util.Set; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.jbehave.core.annotations.When; -import org.vividus.azure.resourcemanager.AbstractAzureResourceManagementSteps; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -public class SqlDatabaseManagementSteps extends AbstractAzureResourceManagementSteps -{ - private static final String API_VERSION = "2021-08-01-preview"; - - private final AzureProfile azureProfile; - - public SqlDatabaseManagementSteps(AzureProfile azureProfile, TokenCredential tokenCredential, - ISoftAssert softAssert, VariableContext variableContext) - { - super(HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile), - azureProfile.getEnvironment().getResourceManagerEndpoint(), softAssert, variableContext); - this.azureProfile = azureProfile; - } - - /** - * Collects the info about all the SQL Servers under the specified resource group and saves it as JSON to a - * variable. For more information, see the Azure Docs. - * - * @param resourceGroupName The name of the resource group within the user's subscription to retrieve SQL Servers - * from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the info about SQL Servers as JSON. - */ - @When("I collect SQL Servers from resource group `$resourceGroupName` and save them as JSON to $scopes variable " - + "`$variableName`") - public void listSqlServers(String resourceGroupName, Set scopes, String variableName) - { - String urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers", - azureProfile.getSubscriptionId(), resourceGroupName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } - - /** - * Collects the info about all the databases belonging to the identified SQL Server under the specified resource - * group and saves it as JSON to a variable. For more information, see the Azure Docs. - * - * @param sqlServerName The name of the SQL Server to list databases from. - * @param resourceGroupName The name of the resource group within the user's subscription to retrieve the SQL - * Server from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the info about databases as JSON. - */ - @When("I collect databases from SQL Server `$sqlServerName` from resource group `$resourceGroupName` and save " - + "them as JSON to $scopes variable `$variableName`") - public void listSqlDatabases(String sqlServerName, String resourceGroupName, Set scopes, - String variableName) - { - String urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases", - azureProfile.getSubscriptionId(), resourceGroupName, sqlServerName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } - - /** - * Retrieves the properties of the specified SQL Database belonging to the identified SQL Server and saves them as - * JSON to a variable. For more information, see the - * Azure Docs. - * - * @param databaseName The name of the SQL Database. - * @param sqlServerName The name of the SQL Server. - * @param resourceGroupName The name of the resource group within the user's subscription to retrieve the SQL - * Server from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the SQL Database properties as JSON. - */ - @SuppressWarnings("PMD.UseObjectForClearerAPI") - @When("I retrieve properties of database with name `$databaseName` from SQL Server `$sqlServerName` from resource" - + " group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`") - public void retrieveSqlServerDatabaseProperties(String databaseName, String sqlServerName, String resourceGroupName, - Set scopes, String variableName) - { - String urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s", - azureProfile.getSubscriptionId(), resourceGroupName, sqlServerName, databaseName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } -} diff --git a/vividus-plugin-azure-sql-db/src/main/resources/steps/defaults/composite.steps b/vividus-plugin-azure-sql-db/src/main/resources/steps/defaults/composite.steps new file mode 100644 index 0000000000..1f3ed95fcb --- /dev/null +++ b/vividus-plugin-azure-sql-db/src/main/resources/steps/defaults/composite.steps @@ -0,0 +1,11 @@ +Composite: When I collect SQL Servers from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I collect SQL Servers from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers` using API version `2021-08-01-preview` and save it to variable `` + +Composite: When I collect databases from SQL Server `$sqlServerName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I collect databases from SQL Server `$sqlServerName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers//databases` using API version `2021-08-01-preview` and save it to variable `` + +Composite: When I retrieve properties of database with name `$databaseName` from SQL Server `$sqlServerName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I retrieve properties of database with name `$databaseName` from SQL Server `$sqlServerName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Sql/servers//databases/` using API version `2021-08-01-preview` and save it to variable `` diff --git a/vividus-plugin-azure-sql-db/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-azure-sql-db/src/main/resources/vividus-plugin/spring.xml deleted file mode 100644 index 5365769fb5..0000000000 --- a/vividus-plugin-azure-sql-db/src/main/resources/vividus-plugin/spring.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/vividus-plugin-azure-sql-db/src/test/java/org/vividus/azure/sql/SqlDatabaseManagementStepsTests.java b/vividus-plugin-azure-sql-db/src/test/java/org/vividus/azure/sql/SqlDatabaseManagementStepsTests.java deleted file mode 100644 index 6b67282528..0000000000 --- a/vividus-plugin-azure-sql-db/src/test/java/org/vividus/azure/sql/SqlDatabaseManagementStepsTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.sql; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Named.named; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Stream; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; -import com.azure.core.management.AzureEnvironment; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.Named; -import org.junit.jupiter.api.TestFactory; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.SetSystemProperty; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class SqlDatabaseManagementStepsTests -{ - private static final String SUBSCRIPTION_ID_PROPERTY_NAME = "AZURE_SUBSCRIPTION_ID"; - private static final String SUBSCRIPTION_ID_PROPERTY_VALUE = "subscription-id"; - - private static final String RESOURCE_GROUP_NAME = "resourceGroupName"; - private static final String SQL_SERVER_NAME = "sqlServerName"; - private static final Set SCOPES = Set.of(VariableScope.STORY); - private static final String VAR_NAME = "varName"; - - @Mock private TokenCredential tokenCredential; - @Mock private ISoftAssert softAssert; - @Mock private VariableContext variableContext; - - private Stream, String>>> createStreamOfTests() - { - return Stream.of( - named("success", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 200, expectedUrlPath); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - }), - named("failure", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 404, expectedUrlPath); - verify(softAssert).recordFailedAssertion( - "Azure REST API HTTP request execution is failed: " + response); - }) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldListSqlServers() - { - var urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.listSqlServers(RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), urlPath) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldListSqlDatabases() - { - var urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME, SQL_SERVER_NAME); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.listSqlDatabases(SQL_SERVER_NAME, RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), urlPath) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldRetrieveSqlServerDatabaseProperties() - { - String databaseName = "dbname"; - var urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME, SQL_SERVER_NAME, databaseName); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.retrieveSqlServerDatabaseProperties(databaseName, SQL_SERVER_NAME, RESOURCE_GROUP_NAME, - SCOPES, VAR_NAME), urlPath) - ); - } - - @SuppressWarnings("PMD.CloseResource") - private String testHttpRequestExecution(Consumer test, int statusCode, - String expectedUrlPath) - { - var azureProfile = new AzureProfile(AzureEnvironment.AZURE); - try (MockedStatic httpPipelineProviderMock = mockStatic(HttpPipelineProvider.class)) - { - var httpPipeline = mock(HttpPipeline.class); - httpPipelineProviderMock.when(() -> HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile)) - .thenReturn(httpPipeline); - var responseAsString = "{\"key\":\"value\"}"; - var httpResponse = mock(HttpResponse.class); - when(httpResponse.getStatusCode()).thenReturn(statusCode); - when(httpResponse.getBodyAsString()).thenReturn(Mono.just(responseAsString)); - var httpRequestCaptor = ArgumentCaptor.forClass(HttpRequest.class); - when(httpPipeline.send(httpRequestCaptor.capture())).thenReturn(Mono.just(httpResponse)); - - var steps = new SqlDatabaseManagementSteps(azureProfile, tokenCredential, softAssert, variableContext); - test.accept(steps); - var httpRequest = httpRequestCaptor.getValue(); - assertEquals(HttpMethod.GET, httpRequest.getHttpMethod()); - assertEquals("https://management.azure.com/" + expectedUrlPath + "?api-version=2021-08-01-preview", - httpRequest.getUrl().toString()); - return responseAsString; - } - } -} diff --git a/vividus-plugin-azure-storage-account/build.gradle b/vividus-plugin-azure-storage-account/build.gradle index 0c0a0c2fd6..7b10afb75e 100644 --- a/vividus-plugin-azure-storage-account/build.gradle +++ b/vividus-plugin-azure-storage-account/build.gradle @@ -5,10 +5,10 @@ dependencies { implementation project(':vividus-util') implementation project(':vividus-extension-azure') implementation project(':vividus-soft-assert') + implementation project(':vividus-plugin-azure-resource-manager') implementation platform(group: 'com.azure', name: 'azure-sdk-bom', version: '1.2.5') implementation(group: 'com.azure', name: 'azure-storage-blob') implementation(group: 'com.azure', name: 'azure-storage-file-share') - implementation(group: 'com.azure.resourcemanager', name: 'azure-resourcemanager-resources', version: '2.18.0') implementation(group: 'com.google.guava', name: 'guava', version: '31.1-jre') implementation(group: 'org.slf4j', name: 'slf4j-api', version: versions.slf4j) @@ -18,5 +18,4 @@ dependencies { testImplementation(group: 'org.mockito', name: 'mockito-junit-jupiter') testImplementation(group: 'org.mockito', name: 'mockito-inline') testImplementation(group: 'com.github.valfirst', name: 'slf4j-test', version: '2.6.1') - testImplementation(group: 'org.junit-pioneer', name: 'junit-pioneer', version: '1.7.1') } diff --git a/vividus-plugin-azure-storage-account/src/main/java/org/vividus/azure/storage/StorageAccountManagementSteps.java b/vividus-plugin-azure-storage-account/src/main/java/org/vividus/azure/storage/StorageAccountManagementSteps.java deleted file mode 100644 index db48deaca2..0000000000 --- a/vividus-plugin-azure-storage-account/src/main/java/org/vividus/azure/storage/StorageAccountManagementSteps.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.storage; - -import java.util.Set; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.jbehave.core.annotations.When; -import org.vividus.azure.resourcemanager.AbstractAzureResourceManagementSteps; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -public class StorageAccountManagementSteps extends AbstractAzureResourceManagementSteps -{ - private static final String API_VERSION = "2021-08-01"; - - private final AzureProfile azureProfile; - - public StorageAccountManagementSteps(AzureProfile azureProfile, TokenCredential tokenCredential, - ISoftAssert softAssert, VariableContext variableContext) - { - super(HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile), - azureProfile.getEnvironment().getResourceManagerEndpoint(), softAssert, variableContext); - this.azureProfile = azureProfile; - } - - /** - * Collects the info about all the storage accounts under the specified resource group and saves it as JSON to a - * variable. Note that storage keys are not returned. For more information, see the - * Azure Docs. - * - * @param resourceGroupName The name of the resource group within the user's subscription to list the storage - * accounts from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the info about storage accounts as JSON. - */ - @When("I collect storage accounts in resource group `$resourceGroupName` and save them as JSON to $scopes variable " - + "`$variableName`") - public void listStorageAccounts(String resourceGroupName, Set scopes, String variableName) - { - String urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts", - azureProfile.getSubscriptionId(), resourceGroupName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } - - /** - * Retrieves the properties of a storage account’s Blob service, including properties for Storage Analytics and CORS - * (Cross-Origin Resource Sharing) rules, and saves them as JSON to a variable. For more information, see the - * Azure - * Docs. - * - * @param storageAccountName The name of the storage account within the specified resource group. - * @param resourceGroupName The name of the resource group within the user's subscription to retrieve the storage - * account from. The name is case-insensitive. - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - *
    - *
  • STEP - the variable will be available only within the step, - *
  • SCENARIO - the variable will be available only within the scenario, - *
  • STORY - the variable will be available within the whole story, - *
  • NEXT_BATCHES - the variable will be available starting from next batch - *
- * @param variableName The variable name to store the blob service properties as JSON. - */ - @When("I retrieve blob service properties of storage account with name `$storageAccountName` from resource group " - + "`$resourceGroupName` and save them as JSON to $scopes variable `$variableName`") - public void retrieveBlobServiceProperties(String storageAccountName, String resourceGroupName, - Set scopes, String variableName) - { - String urlPath = String.format( - "subscriptions/%s/resourceGroups/%s/providers/Microsoft" - + ".Storage/storageAccounts/%s/blobServices/default", - azureProfile.getSubscriptionId(), resourceGroupName, storageAccountName); - saveHttpGetResponseAsVariable(urlPath, API_VERSION, scopes, variableName); - } -} diff --git a/vividus-plugin-azure-storage-account/src/main/resources/steps/defaults/composite.steps b/vividus-plugin-azure-storage-account/src/main/resources/steps/defaults/composite.steps new file mode 100644 index 0000000000..e7409ef26d --- /dev/null +++ b/vividus-plugin-azure-storage-account/src/main/resources/steps/defaults/composite.steps @@ -0,0 +1,7 @@ +Composite: When I collect storage accounts in resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I collect storage accounts in resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Storage/storageAccounts` using API version `2021-08-01` and save it to variable `` + +Composite: When I retrieve blob service properties of storage account with name `$storageAccountName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName` +!-- WARNING: The step "When I retrieve blob service properties of storage account with name `$storageAccountName` from resource group `$resourceGroupName` and save them as JSON to $scopes variable `$variableName`" is deprecated and will be removed in VIVIDUS 0.6.0 +When I get Azure resource with identifier `resourceGroups//providers/Microsoft.Storage/storageAccounts//blobServices/default` using API version `2021-08-01` and save it to variable `` diff --git a/vividus-plugin-azure-storage-account/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-azure-storage-account/src/main/resources/vividus-plugin/spring.xml index 04d113e2cf..ea9517010b 100644 --- a/vividus-plugin-azure-storage-account/src/main/resources/vividus-plugin/spring.xml +++ b/vividus-plugin-azure-storage-account/src/main/resources/vividus-plugin/spring.xml @@ -21,19 +21,10 @@ - - - - - - - - - diff --git a/vividus-plugin-azure-storage-account/src/test/java/org/vividus/azure/storage/StorageAccountManagementStepsTests.java b/vividus-plugin-azure-storage-account/src/test/java/org/vividus/azure/storage/StorageAccountManagementStepsTests.java deleted file mode 100644 index 71ba188f94..0000000000 --- a/vividus-plugin-azure-storage-account/src/test/java/org/vividus/azure/storage/StorageAccountManagementStepsTests.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2019-2022 the original author or authors. - * - * Licensed 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 - * - * https://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.vividus.azure.storage; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Named.named; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Stream; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpMethod; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; -import com.azure.core.management.AzureEnvironment; -import com.azure.core.management.profile.AzureProfile; -import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; - -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.Named; -import org.junit.jupiter.api.TestFactory; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.SetSystemProperty; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.vividus.context.VariableContext; -import org.vividus.softassert.ISoftAssert; -import org.vividus.variable.VariableScope; - -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class StorageAccountManagementStepsTests -{ - private static final String SUBSCRIPTION_ID_PROPERTY_NAME = "AZURE_SUBSCRIPTION_ID"; - private static final String SUBSCRIPTION_ID_PROPERTY_VALUE = "subscription-id"; - - private static final String RESOURCE_GROUP_NAME = "resourceGroupName"; - private static final Set SCOPES = Set.of(VariableScope.STORY); - private static final String VAR_NAME = "varName"; - - @Mock private TokenCredential tokenCredential; - @Mock private ISoftAssert softAssert; - @Mock private VariableContext variableContext; - - private Stream, String>>> createStreamOfTests() - { - return Stream.of( - named("success", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 200, expectedUrlPath); - verify(variableContext).putVariable(SCOPES, VAR_NAME, response); - }), - named("failure", (test, expectedUrlPath) -> { - var response = testHttpRequestExecution(test, 404, expectedUrlPath); - verify(softAssert).recordFailedAssertion( - "Azure REST API HTTP request execution is failed: " + response); - }) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldListStorageAccounts() - { - var urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts", - SUBSCRIPTION_ID_PROPERTY_VALUE, RESOURCE_GROUP_NAME); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.listStorageAccounts(RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), urlPath) - ); - } - - @TestFactory - @SetSystemProperty(key = SUBSCRIPTION_ID_PROPERTY_NAME, value = SUBSCRIPTION_ID_PROPERTY_VALUE) - Stream shouldRetrieveBlobServiceProperties() - { - String storageAccountName = "storageaccountname"; - var urlPath = String.format("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage" - + "/storageAccounts/%s/blobServices/default", SUBSCRIPTION_ID_PROPERTY_VALUE, - RESOURCE_GROUP_NAME, storageAccountName); - return DynamicTest.stream(createStreamOfTests(), test -> test.accept( - steps -> steps.retrieveBlobServiceProperties(storageAccountName, RESOURCE_GROUP_NAME, SCOPES, VAR_NAME), - urlPath) - ); - } - - @SuppressWarnings("PMD.CloseResource") - private String testHttpRequestExecution(Consumer test, int statusCode, - String expectedUrlPath) - { - var azureProfile = new AzureProfile(AzureEnvironment.AZURE); - try (MockedStatic httpPipelineProviderMock = mockStatic(HttpPipelineProvider.class)) - { - var httpPipeline = mock(HttpPipeline.class); - httpPipelineProviderMock.when(() -> HttpPipelineProvider.buildHttpPipeline(tokenCredential, azureProfile)) - .thenReturn(httpPipeline); - var responseAsString = "{\"key\":\"value\"}"; - var httpResponse = mock(HttpResponse.class); - when(httpResponse.getStatusCode()).thenReturn(statusCode); - when(httpResponse.getBodyAsString()).thenReturn(Mono.just(responseAsString)); - var httpRequestCaptor = ArgumentCaptor.forClass(HttpRequest.class); - when(httpPipeline.send(httpRequestCaptor.capture())).thenReturn(Mono.just(httpResponse)); - - var steps = new StorageAccountManagementSteps(azureProfile, tokenCredential, softAssert, variableContext); - test.accept(steps); - var httpRequest = httpRequestCaptor.getValue(); - assertEquals(HttpMethod.GET, httpRequest.getHttpMethod()); - assertEquals("https://management.azure.com/" + expectedUrlPath + "?api-version=2021-08-01", - httpRequest.getUrl().toString()); - return responseAsString; - } - } -}