Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Annotation to Parameterize Tests with more Complex Scenarios #20484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c9569a3
Initial design for supporting tests parameterized by ServiceVersion
alzimmermsft Apr 9, 2021
e541ed9
Merge branch 'master' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Apr 9, 2021
b8617f8
Fix linting and added some testing
alzimmermsft Apr 9, 2021
570d689
Merge branch 'master' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Apr 16, 2021
8e84319
Tighten requirements on what is allowed for the source supplier method
alzimmermsft Apr 16, 2021
66bb035
Merge branch 'master' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Apr 16, 2021
6dc6355
Add the ability to use all service versions with a flag
alzimmermsft Apr 16, 2021
b887f6e
Merge branch 'master' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Apr 22, 2021
f343ac5
Fix failing tests
alzimmermsft Apr 22, 2021
18d6969
Merge in upstream and fix conflicts
alzimmermsft Apr 27, 2021
1e0e436
Merge branch 'master' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft May 11, 2021
29382f2
Add class level annotation for service version testing, simplify test…
alzimmermsft Jun 18, 2021
d9e800a
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jun 18, 2021
98cf6d6
Update dependency version
alzimmermsft Jun 18, 2021
1619253
Remove references to azure-core-test implementation
alzimmermsft Jun 18, 2021
d0a9fbc
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jun 18, 2021
8218424
Restructuring and added new extension to prevent execution from faili…
alzimmermsft Jun 19, 2021
3c7b353
Fixed test pointing to wrong method
alzimmermsft Jun 21, 2021
2124e91
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jun 22, 2021
1c76f9c
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jun 22, 2021
5de7e74
Support maximumServiceVersions and add PlaybackOnly annotation
alzimmermsft Jun 22, 2021
544444f
Changed class annotation to support inheritence and use min and max f…
alzimmermsft Jun 23, 2021
12b74f6
Merge in main and fix linting issue
alzimmermsft Jul 16, 2021
d053b1e
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jul 20, 2021
74537d2
Update based on feedback
alzimmermsft Jul 20, 2021
e4bcc28
Merge branch 'main' into AzTest_SupportTestingMultipleApiVersions
alzimmermsft Jul 20, 2021
eef39fe
Revert changes made to azure-search-documents
alzimmermsft Jul 20, 2021
11121f2
Fix broken Javadocs
alzimmermsft Jul 20, 2021
557d538
Fix InvalidPathException from preventing DefaultLogger construction
alzimmermsft Jul 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2510,4 +2510,11 @@
<Method name="clone"/>
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS"/>
</Match>

<!-- If the ServiceVersion type doesn't implement Enum it would have already thrown an exception. -->
<Match>
<Class name="com.azure.core.test.implementation.AzureMethodSourceArgumentsProvider"/>
<Method name="getServiceVersions"/>
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package com.azure.containers.containerregistry;

import com.azure.containers.containerregistry.models.ArtifactManifestProperties;
import com.azure.containers.containerregistry.models.ArtifactManifestOrderBy;
import com.azure.containers.containerregistry.models.ArtifactManifestProperties;
import com.azure.containers.containerregistry.models.ContainerRepositoryProperties;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceMethod;
Expand All @@ -17,8 +17,8 @@

/**
* This class provides a helper type that contains all the operations for repositories in Azure Container Registry.
* Operations allowed by this type are listing, retrieving, deleting, setting writeable properties.
* These operations are supported on the repository and the respective tags and manifests in it.
* Operations allowed by this type are listing, retrieving, deleting, setting writeable properties. These operations are
* supported on the repository and the respective tags and manifests in it.
*
* <p><strong>Instantiating Container Repository helper type.</strong></p>
*
Expand All @@ -33,8 +33,9 @@ public final class ContainerRepository {


/**
* Creates a {@link ContainerRepositoryAsync} that sends requests to the given repository in the container registry service at {@code endpoint}.
* Each service call goes through the {@code pipeline}.
* Creates a {@link ContainerRepositoryAsync} that sends requests to the given repository in the container registry
* service at {@code endpoint}. Each service call goes through the {@code pipeline}.
*
* @param asyncClient The async client for the given repository.
*/
ContainerRepository(ContainerRepositoryAsync asyncClient) {
Expand All @@ -43,6 +44,7 @@ public final class ContainerRepository {

/**
* Gets the Azure Container Registry service endpoint for the current instance.
*
* @return The service endpoint for the current instance.
*/
public String getName() {
Expand All @@ -51,6 +53,7 @@ public String getName() {

/**
* Gets the Azure Container Registry name for the current instance.
*
* @return Return the registry name.
*/
public String getRegistryEndpoint() {
Expand All @@ -66,8 +69,8 @@ public String getRegistryEndpoint() {
*
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.deleteRepositoryWithResponse}
*
* @param context Additional context that is passed through the Http pipeline during the service call.
* artifacts that are deleted as part of the repository delete.
* @param context Additional context that is passed through the Http pipeline during the service call. artifacts
* that are deleted as part of the repository delete.
* @return A void response for completion.
* @throws ClientAuthenticationException thrown if the client does not have access to the repository.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
Expand Down Expand Up @@ -95,7 +98,8 @@ public void delete() {
}

/**
* Gets the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() repository}.
* Gets the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName()
* repository}.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -104,7 +108,8 @@ public void delete() {
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.getPropertiesWithResponse}
*
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A REST response with the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() repository}.
* @return A REST response with the {@link ContainerRepositoryProperties properties} associated with the given
* {@link #getName() repository}.
* @throws ClientAuthenticationException thrown if the client does not have access to modify the namespace.
* @throws ResourceNotFoundException thrown if the repository with the given name was not found.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
Expand All @@ -115,15 +120,17 @@ public Response<ContainerRepositoryProperties> getPropertiesWithResponse(Context
}

/**
* Gets the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() repository}.
* Gets the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName()
* repository}.
*
* <p><strong>Code Samples</strong></p>
*
* <p>Get the properties for the given repository.</p>
*
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.getProperties}
*
* @return The{@link RepositoryProperties properties} associated with the given {@link #getName() repository}.
* @return The {@link ContainerRepositoryProperties properties} associated with the given {@link #getName()
* repository}.
* @throws ClientAuthenticationException thrown if the client does not have access to modify the namespace.
* @throws ResourceNotFoundException thrown if the repository with the given name was not found.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
Expand All @@ -149,8 +156,9 @@ public RegistryArtifact getArtifact(String digest) {
* Fetches all the artifacts associated with the given {@link #getName() repository}.
*
* <p> If you would like to specify the order in which the tags are returned please
* use the overload that takes in the options parameter {@link #listManifestProperties(ArtifactManifestOrderBy, Context)} listManifestProperties}
* No assumptions on the order can be made if no options are provided to the service.
* use the overload that takes in the options parameter {@link #listManifestProperties(ArtifactManifestOrderBy,
* Context)} listManifestProperties} No assumptions on the order can be made if no options are provided to the
* service.
* </p>
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -160,7 +168,8 @@ public RegistryArtifact getArtifact(String digest) {
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.listManifestProperties}.
*
* @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the
* namespace.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
Expand All @@ -172,8 +181,8 @@ public PagedIterable<ArtifactManifestProperties> listManifestProperties() {
* Fetches all the artifacts associated with the given {@link #getName() repository }.
*
* <p> The method supports options to select the order in which the artifacts are returned by the service.
* Currently the service supports an ascending or descending order for the last updated time for the artifacts.
* No assumptions on the order can be made if no options are provided by the service.
* Currently the service supports an ascending or descending order for the last updated time for the artifacts. No
* assumptions on the order can be made if no options are provided by the service.
* </p>
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -184,7 +193,8 @@ public PagedIterable<ArtifactManifestProperties> listManifestProperties() {
*
* @param orderBy the order in which the artifacts are returned by the service.
* @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the
* namespace.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
Expand All @@ -196,8 +206,8 @@ public PagedIterable<ArtifactManifestProperties> listManifestProperties(Artifact
* Fetches all the artifacts associated with the given {@link #getName() repository }.
*
* <p> The method supports options to select the order in which the artifacts are returned by the service.
* Currently the service supports an ascending or descending order for the last updated time for the artifacts.
* No assumptions on the order can be made if no options are provided by the service.
* Currently the service supports an ascending or descending order for the last updated time for the artifacts. No
* assumptions on the order can be made if no options are provided by the service.
* </p>
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -209,7 +219,8 @@ public PagedIterable<ArtifactManifestProperties> listManifestProperties(Artifact
* @param orderBy the order in which the artifacts are returned by the service.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace.
* @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the
* namespace.
* @throws HttpResponseException thrown if any other unexpected exception is returned by the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
Expand All @@ -227,7 +238,8 @@ public PagedIterable<ArtifactManifestProperties> listManifestProperties(Artifact
*
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.updatePropertiesWithResponse}.
*
* @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated for the repository.
* @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated
* for the repository.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A REST response with the completion.
* @throws ClientAuthenticationException thrown if the client does not have access to the repository.
Expand All @@ -241,16 +253,17 @@ public Response<ContainerRepositoryProperties> updatePropertiesWithResponse(Cont
}

/**
* Update the repository properties {@link ContainerRepositoryProperties} of the given {@link #getName() repository}.
* These properties set the update, delete and retrieve options of the repository.
* Update the repository properties {@link ContainerRepositoryProperties} of the given {@link #getName()
* repository}. These properties set the update, delete and retrieve options of the repository.
*
* <p><strong>Code Samples</strong></p>
*
* <p>Update the writeable properties for the given repository.</p>
*
* {@codesnippet com.azure.containers.containerregistry.ContainerRepository.updateProperties}.
*
* @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated for the repository.
* @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated
* for the repository.
* @return The updated {@link ContainerRepositoryProperties properties }
* @throws ClientAuthenticationException thrown if the client does not have access to the repository.
* @throws ResourceNotFoundException thrown if the repository with the given name was not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.http.HttpClient;
import com.azure.core.test.TestMode;
import com.azure.core.test.implementation.ImplUtils;
import com.azure.core.util.Context;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -51,9 +50,9 @@ private ContainerRegistryClient getContainerRegistryClient(HttpClient httpClient

@BeforeEach
void beforeEach() {
TestUtils.importImage(ImplUtils.getTestMode(), HELLO_WORLD_REPOSITORY_NAME, Arrays.asList("latest", "v1", "v2", "v3", "v4"));
TestUtils.importImage(getTestMode(), HELLO_WORLD_REPOSITORY_NAME, Arrays.asList("latest", "v1", "v2", "v3", "v4"));
TestUtils.importImage(
ImplUtils.getTestMode(),
getTestMode(),
ALPINE_REPOSITORY_NAME,
Arrays.asList(
LATEST_TAG_NAME,
Expand All @@ -72,7 +71,7 @@ public void listRepositoryNames(HttpClient httpClient) {
StepVerifier.create(registryAsyncClient.listRepositoryNames())
.recordWith(ArrayList::new)
.thenConsumeWhile(x -> true)
.expectRecordedMatches(repositories -> validateRepositories(repositories))
.expectRecordedMatches(this::validateRepositories)
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
.verifyComplete();

List<String> repositories = registryClient.listRepositoryNames().stream().collect(Collectors.toList());
Expand All @@ -88,11 +87,12 @@ public void listRepositoryNamesWithPageSize(HttpClient httpClient) {
StepVerifier.create(registryAsyncClient.listRepositoryNames().byPage(PAGESIZE_1))
.recordWith(ArrayList::new)
.thenConsumeWhile(x -> true)
.expectRecordedMatches(pagedResList -> validateRepositoriesByPage(pagedResList))
.expectRecordedMatches(this::validateRepositoriesByPage)
.verifyComplete();

ArrayList<String> repositories = new ArrayList<>();
registryClient.listRepositoryNames().iterableByPage(PAGESIZE_1).forEach(res -> res.getValue().forEach(repo -> repositories.add(repo)));
registryClient.listRepositoryNames().iterableByPage(PAGESIZE_1)
.forEach(res -> repositories.addAll(res.getValue()));
validateRepositories(repositories);
}

Expand All @@ -103,7 +103,8 @@ public void listRepositoryNamesWithInvalidPageSize(HttpClient httpClient) {
registryClient = getContainerRegistryClient(httpClient);

ArrayList<String> repositories = new ArrayList<>();
assertThrows(IllegalArgumentException.class, () -> registryClient.listRepositoryNames().iterableByPage(-1).forEach(res -> res.getValue().forEach(repo -> repositories.add(repo))));
assertThrows(IllegalArgumentException.class, () -> registryClient.listRepositoryNames().iterableByPage(-1)
.forEach(res -> repositories.addAll(res.getValue())));

StepVerifier.create(registryAsyncClient.listRepositoryNames().byPage(-1))
.verifyError(IllegalArgumentException.class);
Expand Down Expand Up @@ -132,7 +133,7 @@ public void getContainerRepository(HttpClient httpClient) {
ContainerRepositoryAsync repositoryAsync = registryAsyncClient.getRepository(HELLO_WORLD_REPOSITORY_NAME);
assertNotNull(repositoryAsync);
StepVerifier.create(repositoryAsync.getProperties())
.assertNext(res -> validateProperties(res))
.assertNext(this::validateProperties)
.verifyComplete();

ContainerRepository repository = registryClient.getRepository(HELLO_WORLD_REPOSITORY_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.http.rest.Response;
import com.azure.core.test.TestMode;
import com.azure.core.test.implementation.ImplUtils;
import com.azure.core.util.Context;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
Expand All @@ -18,15 +18,14 @@
import reactor.test.StepVerifier;

import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;

import static com.azure.containers.containerregistry.TestUtils.HELLO_WORLD_REPOSITORY_NAME;
import static com.azure.containers.containerregistry.TestUtils.HELLO_WORLD_SEATTLE_REPOSITORY_NAME;
import static com.azure.containers.containerregistry.TestUtils.HTTP_STATUS_CODE_202;
import static com.azure.containers.containerregistry.TestUtils.SLEEP_TIME_IN_MILLISECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Execution(ExecutionMode.SAME_THREAD)
public class ContainerRegistryClientTest extends ContainerRegistryClientsTestBase {
Expand All @@ -47,7 +46,7 @@ private ContainerRegistryAsyncClient getContainerRegistryAsyncClient(HttpClient

@BeforeEach
void beforeEach() {
TestUtils.importImage(ImplUtils.getTestMode(), repositoryName, Arrays.asList("latest"));
TestUtils.importImage(getTestMode(), repositoryName, Collections.singletonList("latest"));
if (getTestMode() == TestMode.PLAYBACK) {
httpClient = interceptorManager.getPlaybackClient();
} else {
Expand All @@ -68,12 +67,12 @@ public void deleteRepositoryByRegistryWithResponseAsyncClient() {
.then(registryAsyncClient.getRepository(repositoryName).getProperties())
.flatMap(res -> Mono.just(false))
.onErrorResume(res -> registryAsyncClient.getRepository(repositoryName)
.delete()
.then(Mono.just(true))
.delete()
.then(Mono.just(true))
.onErrorResume(err -> Mono.just(false)));

StepVerifier.create(deleteRepositoryTest)
.assertNext(res -> assertTrue(res))
.assertNext(Assertions::assertTrue)
.verifyComplete();
}

Expand All @@ -89,7 +88,7 @@ public void deleteRepositoryByRegistryAsyncClient() {
.onErrorResume(err -> Mono.just(false)));

StepVerifier.create(deleteRepositoryTest)
.assertNext(res -> assertTrue(res))
.assertNext(Assertions::assertTrue)
.verifyComplete();
}

Expand All @@ -105,7 +104,7 @@ public void deleteRepositoryWithResponseAsyncClient() {
.onErrorResume(err -> Mono.just(false)));

StepVerifier.create(deleteRepositoryTest)
.assertNext(res -> assertTrue(res))
.assertNext(Assertions::assertTrue)
.verifyComplete();
}

Expand All @@ -121,7 +120,7 @@ public void deleteRepositoryAsyncClient() {
.onErrorResume(err -> Mono.just(false)));

StepVerifier.create(deleteRepositoryTest)
.assertNext(res -> assertTrue(res))
.assertNext(Assertions::assertTrue)
.verifyComplete();
}

Expand Down
Loading