Skip to content

Commit

Permalink
Add Custom Annotation to Parameterize Tests with more Complex Scenari…
Browse files Browse the repository at this point in the history
…os (#20484)

Add Custom Annotation to Parameterize Tests with more Complex Scenarios
  • Loading branch information
alzimmermsft authored Jul 21, 2021
1 parent 7f20a43 commit 551d307
Show file tree
Hide file tree
Showing 23 changed files with 1,431 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2512,4 +2512,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)
.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

0 comments on commit 551d307

Please sign in to comment.