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

Added spock test framework and tests for queue service #4940

Merged
merged 14 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
4 changes: 4 additions & 0 deletions eng/jacoco-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<configuration>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/test-coverage</outputDirectory>
<excludes>
<exclude>**/model/.*</exclude>
<exclude>**/implementation/.*</exclude>
</excludes>
</configuration>
</execution>
</executions>
Expand Down
17 changes: 4 additions & 13 deletions sdk/storage/azure-storage-queue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,22 @@
<version>1.0.0-preview.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.spockframework/spock-core -->
<dependency>
<groupId>com.azure</groupId>
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>azure-identity</artifactId>
<version>1.0.0-preview.3</version>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.3-groovy-2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public final class StorageErrorCode extends ExpandableStringEnum<StorageErrorCod
*/
public static final StorageErrorCode ACCOUNT_IS_DISABLED = fromString("AccountIsDisabled");

/**
* Static value AuthenticationError for StorageErrorCode.
*/
public static final StorageErrorCode AUTHENTICATION_ERROR = fromString("AuthenticationError");
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved

/**
* Static value AuthenticationFailed for StorageErrorCode.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Contains helper methods for unit tests.
*/
class TestHelpers {
private final String azureStorageConnectionString = "AZURE_STORAGE_CONNECTION_STRING";
private final String azureStorageConnectionString = "AZURE_STORAGE_QUEUE_CONNECTION_STRING";
private final String azureStorageQueueEndpoint = "AZURE_STORAGE_QUEUE_ENDPOINT";

<T> T setupClient(BiFunction<String, String, T> clientBuilder, boolean isPlaybackMode, ClientLogger logger) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.queue.spock

import com.azure.core.test.InterceptorManager
import com.azure.core.test.TestMode
import com.azure.core.test.utils.TestResourceNamer
import com.azure.core.util.configuration.ConfigurationManager
import com.azure.core.util.logging.ClientLogger
import com.azure.storage.queue.QueueClientBuilder
import com.azure.storage.queue.QueueServiceClient
import com.azure.storage.queue.QueueServiceClientBuilder
import org.junit.Rule
import org.junit.rules.ExpectedException
import org.junit.rules.TestName
import spock.lang.Specification

class APISpec extends Specification {
// Field common used for all APIs.
def logger = new ClientLogger(APISpec.class)
def AZURE_TEST_MODE = "AZURE_TEST_MODE"
def interceptorManager
def testResourceName

// Clients for API tests
def primaryQueueServiceClient
def primaryQueueServiceAsyncClient


// Test name for test method name.
@Rule
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
TestName testName = new TestName()
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
@Rule
ExpectedException thrown = ExpectedException.none()
def testMode = getTestMode()
def connectionString = ConfigurationManager.getConfiguration().get("AZURE_STORAGE_QUEUE_CONNECTION_STRING")


/**
* Setup the QueueServiceClient and QueueClient common used for the API tests.
*/
def setup() {
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
def methodName = testName.getMethodName()
logger.info("Test Mode: {}, Name: {}", testMode, methodName)
interceptorManager = new InterceptorManager(methodName, testMode)
testResourceName = new TestResourceNamer(methodName, testMode,
interceptorManager.getRecordedData())
}

/**
* Clean up the test queues and messages for the account.
*/
def cleanup() {
interceptorManager.close()
if (getTestMode() == TestMode.RECORD) {
QueueServiceClient cleanupQueueServiceClient = new QueueServiceClientBuilder()
.connectionString(connectionString)
.buildClient()
cleanupQueueServiceClient.listQueues().each {
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
queueItem -> cleanupQueueServiceClient.deleteQueue(queueItem.name())
}
}
}

/**
* Test mode is initialized whenever test is executed. Helper method which is used to determine what to do under
* certain test mode.
* @return The TestMode:
* <ul>
* <li>Playback: (default if no test mode setup)</li>
* </ul>
*/
def getTestMode() {
def azureTestMode = ConfigurationManager.getConfiguration().get("AZURE_TEST_MODE")
rickle-msft marked this conversation as resolved.
Show resolved Hide resolved

if (azureTestMode != null) {
try {
return TestMode.valueOf(azureTestMode.toUpperCase(Locale.US))
} catch (IllegalArgumentException e) {
logger.error("Could not parse '{}' into TestEnum. Using 'Playback' mode.", azureTestMode)
return TestMode.PLAYBACK
}
}

logger.info("Environment variable '{}' has not been set yet. Using 'Playback' mode.", AZURE_TEST_MODE)
return TestMode.PLAYBACK
}

def queueServiceBuilderHelper(final InterceptorManager interceptorManager) {
if (testMode == TestMode.RECORD) {
return new QueueServiceClientBuilder()
.connectionString(connectionString)
.addPolicy(interceptorManager.getRecordPolicy())
} else {
return new QueueServiceClientBuilder()
.connectionString(connectionString)
.httpClient(interceptorManager.getPlaybackClient())
}
}

def queueBuilderHelper(final InterceptorManager interceptorManager) {
def queueName = testResourceName.randomName("queue", 16)
if (testMode == TestMode.RECORD) {
return new QueueClientBuilder()
.connectionString(connectionString)
.queueName(queueName)
.addPolicy(interceptorManager.getRecordPolicy())
} else {
return new QueueClientBuilder()
.connectionString(connectionString)
.queueName(queueName)
.httpClient(interceptorManager.getPlaybackClient())
}
}
}
Loading