Skip to content

Commit

Permalink
Add Missing Tests and Remove Exists APIs (#8274)
Browse files Browse the repository at this point in the history
* Add missing tests

* Merged in master

* General code style refactoring and test cleanup

* Removing more JUnit 4 code and use Java Base64.encodeToString

* Removed Apache Commons code from tests

* Update Azure Core version to fix dependency conflicts

* Finished cleaning up client documentation and removed async test classes

* Fixed Java 8 issues and update to use recording framework tools

* Fix another Java 8 issue

* Fixing unit tests

* Fixing unit tests, making AccessConditionTests a static helper class

* Update session playback records
  • Loading branch information
alzimmermsft authored Feb 24, 2020
1 parent 21a1305 commit 10ed766
Show file tree
Hide file tree
Showing 353 changed files with 9,840 additions and 18,026 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

package com.azure.search;

import com.azure.core.http.HttpHeaders;
import com.azure.core.http.rest.Page;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.search.models.AutocompleteItem;
import com.azure.search.models.AutocompleteResult;

import java.util.stream.Collectors;

/**
* Represents an HTTP response from the autocomplete API request
* that contains a list of items deserialized into a {@link Page}.
* Represents an HTTP response from the autocomplete API request that contains a list of items deserialized into a
* {@link Page}.
*/
public class AutocompletePagedResponse extends PagedResponseBase<String, AutocompleteItem> {
public class AutocompletePagedResponse extends PagedResponseBase<Void, AutocompleteItem> {

/**
* Constructor
*
* @param autocompleteResponse an http response with the results
*/
public AutocompletePagedResponse(SimpleResponse<AutocompleteResult> autocompleteResponse) {
Expand All @@ -28,12 +26,6 @@ public AutocompletePagedResponse(SimpleResponse<AutocompleteResult> autocomplete
autocompleteResponse.getHeaders(),
autocompleteResponse.getValue().getResults(),
null,
deserializeHeaders(autocompleteResponse.getHeaders()));
}

private static String deserializeHeaders(HttpHeaders headers) {
return headers.toMap().entrySet().stream().map((entry) ->
entry.getKey() + "," + entry.getValue()
).collect(Collectors.joining(","));
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ public class DataSources {
* @param sqlConnectionString The connection string for the Azure SQL database.
* @param tableOrViewName The name of the table or view from which to read rows.
* @param description Optional. Description of the data source.
* @param changeDetectionPolicy The change detection policy for the data source.
* Note that only high watermark change detection
* is allowed for Azure SQL when deletion detection is enabled.
* @param changeDetectionPolicy The change detection policy for the data source. Note that only high watermark
* change detection is allowed for Azure SQL when deletion detection is enabled.
* @param deletionDetectionPolicy Optional. The data deletion detection policy for the data source.
* @throws IllegalArgumentException if name, tableName or ConnectionString are null or empty.
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, tableName or ConnectionString are null or empty.
*/
public static DataSource azureSql(
String name,
String sqlConnectionString,
String tableOrViewName,
String description,
DataChangeDetectionPolicy changeDetectionPolicy,
public static DataSource azureSql(String name, String sqlConnectionString, String tableOrViewName,
String description, DataChangeDetectionPolicy changeDetectionPolicy,
DataDeletionDetectionPolicy deletionDetectionPolicy) {
if (CoreUtils.isNullOrEmpty(name)) {
throw new IllegalArgumentException("name cannot be null or empty");
Expand Down Expand Up @@ -66,36 +61,27 @@ public static DataSource azureSql(
* @param tableOrViewName The name of the table or view from which to read rows.
* @return A new DataSource instance.
*/
public static DataSource azureSql(
String name,
String sqlConnectionString,
String tableOrViewName) {
public static DataSource azureSql(String name, String sqlConnectionString, String tableOrViewName) {
return DataSources.azureSql(name, sqlConnectionString, tableOrViewName, null, null, null);
}

/**
* Creates a new DataSource to connect to an Azure Blob container.
*
* @param name The name of the data source.
* @param storageConnectionString The connection string for the Azure Storage account.
* It must follow this format: "DefaultEndpointsProtocol=https;AccountName=[your storage account];
* AccountKey=[your account key];" Note that HTTPS is required.
* @param storageConnectionString The connection string for the Azure Storage account. It must follow this format:
* "DefaultEndpointsProtocol=https;AccountName=[your storage account]; AccountKey=[your account key];" Note that
* HTTPS is required.
* @param containerName The name of the container from which to read blobs.
* @param pathPrefix Optional. If specified, the data source will include only blobs
* with names starting with this prefix. This is useful when blobs are
* organized into "virtual folders", for example.
* @param pathPrefix Optional. If specified, the data source will include only blobs with names starting with this
* prefix. This is useful when blobs are organized into "virtual folders", for example.
* @param description Optional. Description of the data source
* @param deletionDetectionPolicy Optional. The data deletion detection policy for the data source
* @throws IllegalArgumentException if name, containerName or storageConnectionString are null or empty.
* @return A new Azure Blob DataSource instance.
* @throws IllegalArgumentException if name, containerName or storageConnectionString are null or empty.
*/
public static DataSource azureBlobStorage(
String name,
String storageConnectionString,
String containerName,
String pathPrefix,
String description,
DataDeletionDetectionPolicy deletionDetectionPolicy) {
public static DataSource azureBlobStorage(String name, String storageConnectionString, String containerName,
String pathPrefix, String description, DataDeletionDetectionPolicy deletionDetectionPolicy) {
if (CoreUtils.isNullOrEmpty(name)) {
throw new IllegalArgumentException("name cannot be null or empty");
}
Expand All @@ -121,41 +107,32 @@ public static DataSource azureBlobStorage(
* Creates a new DataSource to connect to an Azure Blob container.
*
* @param name The name of the data source.
* @param storageConnectionString The connection string for the Azure Storage account.
* It must follow this format: "DefaultEndpointsProtocol=https;AccountName=[your storage account];
* AccountKey=[your account key];" Note that HTTPS is required.
* @param storageConnectionString The connection string for the Azure Storage account. It must follow this format:
* "DefaultEndpointsProtocol=https;AccountName=[your storage account]; AccountKey=[your account key];" Note that
* HTTPS is required.
* @param containerName The name of the container from which to read blobs.
* @return A new Azure Blob DataSource instance.
*/
public static DataSource azureBlobStorage(
String name,
String storageConnectionString,
String containerName) {
public static DataSource azureBlobStorage(String name, String storageConnectionString, String containerName) {
return DataSources.azureBlobStorage(name, storageConnectionString, containerName, null, null, null);
}

/**
* Creates a new DataSource to connect to an Azure Table.
*
* @param name The name of the data source.
* @param storageConnectionString The connection string for the Azure Storage account.
* It must follow this format: "DefaultEndpointsProtocol=https;
* AccountName=[your storage account];AccountKey=[your account key];"
* Note that HTTPS is required.
* @param storageConnectionString The connection string for the Azure Storage account. It must follow this format:
* "DefaultEndpointsProtocol=https; AccountName=[your storage account];AccountKey=[your account key];" Note that
* HTTPS is required.
* @param tableName The name of the Azure table from which to read rows.
* @param query Optional. A query that is applied to the table when reading rows.
* @param description Optional. Description of the data source
* @param deletionDetectionPolicy Optional. The data deletion detection policy for the data source.
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, tableName or storageConnectionString are null or empty.
*/
public static DataSource azureTableStorage(
String name,
String storageConnectionString,
String tableName,
String query,
String description,
DataDeletionDetectionPolicy deletionDetectionPolicy) {
public static DataSource azureTableStorage(String name, String storageConnectionString, String tableName,
String query, String description, DataDeletionDetectionPolicy deletionDetectionPolicy) {
if (CoreUtils.isNullOrEmpty(name)) {
throw new IllegalArgumentException("name cannot be null or empty");
}
Expand All @@ -181,28 +158,24 @@ public static DataSource azureTableStorage(
* Creates a new DataSource to connect to an Azure Table.
*
* @param name The name of the data source.
* @param storageConnectionString The connection string for the Azure Storage account.
* It must follow this format: "DefaultEndpointsProtocol=https;
* AccountName=[your storage account];AccountKey=[your account key];"
* Note that HTTPS is required.
* @param storageConnectionString The connection string for the Azure Storage account. It must follow this format:
* "DefaultEndpointsProtocol=https; AccountName=[your storage account];AccountKey=[your account key];" Note that
* HTTPS is required.
* @param tableName The name of the Azure table from which to read rows.
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, tableName or storageConnectionString are null or empty.
*/
public static DataSource azureTableStorage(
String name,
String storageConnectionString,
String tableName) {
public static DataSource azureTableStorage(String name, String storageConnectionString, String tableName) {
return DataSources.azureTableStorage(name, storageConnectionString, tableName, null, null, null);
}

/**
/**
* Creates a new DataSource to connect to a Cosmos database.
*
* @param name The name of the data source.
* @param cosmosConnectionString The connection string for the Cosmos database. It must follow this format:
* AccountName|AccountEndpoint=[your account name or endpoint];
* AccountKey=[your account key];Database=[your database name]"
* AccountName|AccountEndpoint=[your account name or endpoint]; AccountKey=[your account key];Database=[your
* database name]"
* @param collectionName The name of the collection from which to read documents.
* @param query Optional. A query that is applied to the collection when reading documents.
* @param useChangeDetection Optional. Indicates whether to use change detection when indexing. Default is true.
Expand All @@ -211,14 +184,8 @@ public static DataSource azureTableStorage(
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, collectionName or cosmosConnectionString are null or empty.
*/
public static DataSource cosmos(
String name,
String cosmosConnectionString,
String collectionName,
String query,
Boolean useChangeDetection,
String description,
DataDeletionDetectionPolicy deletionDetectionPolicy) {
public static DataSource cosmos(String name, String cosmosConnectionString, String collectionName, String query,
Boolean useChangeDetection, String description, DataDeletionDetectionPolicy deletionDetectionPolicy) {
if (CoreUtils.isNullOrEmpty(name)) {
throw new IllegalArgumentException("name cannot be null or empty");
}
Expand Down Expand Up @@ -249,17 +216,14 @@ public static DataSource cosmos(
*
* @param name The name of the data source.
* @param cosmosDbConnectionString The connection string for the CosmosDb database. It must follow this format:
* AccountName|AccountEndpoint=[your account name or endpoint];
* AccountKey=[your account key];Database=[your database name]"
* AccountName|AccountEndpoint=[your account name or endpoint]; AccountKey=[your account key];Database=[your
* database name]"
* @param collectionName The name of the collection from which to read documents
* @param useChangeDetection Optional. Indicates whether to use change detection when indexing. Default is true.
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, collectionName or cosmosDbConnectionString are null or empty.
*/
public static DataSource cosmos(
String name,
String cosmosDbConnectionString,
String collectionName,
public static DataSource cosmos(String name, String cosmosDbConnectionString, String collectionName,
Boolean useChangeDetection) {
return DataSources.cosmos(
name, cosmosDbConnectionString, collectionName, null, useChangeDetection, null, null);
Expand All @@ -270,16 +234,13 @@ public static DataSource cosmos(
*
* @param name The name of the data source.
* @param cosmosDbConnectionString The connection string for the CosmosDb database. It must follow this format:
* AccountName|AccountEndpoint=[your account name or endpoint];
* AccountKey=[your account key];Database=[your database name]"
* AccountName|AccountEndpoint=[your account name or endpoint]; AccountKey=[your account key];Database=[your
* database name]"
* @param collectionName The name of the collection from which to read documents
* @return A new DataSource instance.
* @throws IllegalArgumentException if name, collectionName or cosmosDbConnectionString are null or empty.
*/
public static DataSource cosmos(
String name,
String cosmosDbConnectionString,
String collectionName) {
public static DataSource cosmos(String name, String cosmosDbConnectionString, String collectionName) {
return DataSources.cosmos(name, cosmosDbConnectionString, collectionName, null, true, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public Document() {
}

/**
* Constructs a new {@code Document} with the same mappings as the
* specified {@code Map}.
* Constructs a new {@code Document} with the same mappings as the specified {@code Map}.
*
* @param m the map whose mappings are to be placed in this map
* @param m the map whose mappings are to be placed in this map
*/
public Document(Map<? extends String, ?> m) {
super(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Internal utility class for Document Response conversions.
*/
class DocumentResponseConversions {
final class DocumentResponseConversions {

private static final String ODATA_CONTEXT = "@odata.context";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package com.azure.search;

/**
* Credentials that authorize requests to Azure Cognitive Search. It uses content within the HTTP request to
* generate the correct "api-key" header value
* Credentials that authorize requests to Azure Cognitive Search. It uses content within the HTTP request to generate
* the correct "api-key" header value
*
* @see SearchIndexClientBuilder
* @see SearchServiceClientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Policy that adds the Cognitive Search Service api-key into the request's Authorization header.
*/
public class SearchApiKeyPipelinePolicy implements HttpPipelinePolicy {
private static final String API_KEY = "api-key";

private final SearchApiKeyCredential apiKey;

Expand All @@ -25,14 +26,13 @@ public class SearchApiKeyPipelinePolicy implements HttpPipelinePolicy {
* @throws IllegalArgumentException when the api key is an empty string
*/
public SearchApiKeyPipelinePolicy(SearchApiKeyCredential apiKey) {
Objects.requireNonNull(apiKey);
Objects.requireNonNull(apiKey, "'apiKey' cannot be null.");
this.apiKey = apiKey;
}

@Override
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
context.getHttpRequest()
.setHeader("api-key", this.apiKey.getApiKey());
context.getHttpRequest().setHeader(API_KEY, this.apiKey.getApiKey());
return next.process();
}
}
Loading

0 comments on commit 10ed766

Please sign in to comment.