Skip to content

Commit

Permalink
Fix and record tests (Azure#356)
Browse files Browse the repository at this point in the history
* Reduce code duplicates
* Remove unused recorded-sessions
* Make general fixes and improvements to tests
* Record all tests
  • Loading branch information
rabee333 authored Dec 26, 2019
1 parent c063c0b commit 4ee7293
Show file tree
Hide file tree
Showing 285 changed files with 5,075 additions and 6,064 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void getDataSourceThrowsOnNotFound() {
);
}

@Override
@Test
public void canCreateDataSource() {
DataSource expectedDataSource = createTestBlobDataSource(null);

Expand All @@ -377,7 +377,7 @@ public void canCreateDataSource() {
.verifyComplete();
}

@Override
@Test
public void canCreateDataSourceWithResponse() {
DataSource expectedDataSource = createTestBlobDataSource(null);
StepVerifier.create(client.createDataSourceWithResponse(expectedDataSource, new RequestOptions(), null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public void getDataSourceThrowsOnNotFound() {
);
}

@Override
@Test
public void canCreateDataSource() {
DataSource expectedDataSource = createTestBlobDataSource(null);
DataSource actualDataSource = client.createDataSource(expectedDataSource);
Expand All @@ -354,7 +354,7 @@ public void canCreateDataSource() {
Assert.assertEquals(expectedDataSource.getName(), dataSourceList.get(0).getName());
}

@Override
@Test
public void canCreateDataSourceWithResponse() {
DataSource expectedDataSource = createTestBlobDataSource(null);
Response<DataSource> response = client.createDataSourceWithResponse(expectedDataSource, new RequestOptions(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License.
package com.azure.search;

import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.search.models.AccessCondition;
import com.azure.search.models.AnalyzerName;
import com.azure.search.models.CorsOptions;
Expand All @@ -11,6 +13,7 @@
import com.azure.search.models.Index;
import com.azure.search.models.MagnitudeScoringFunction;
import com.azure.search.models.MagnitudeScoringParameters;
import com.azure.search.models.RequestOptions;
import com.azure.search.models.ScoringFunctionAggregation;
import com.azure.search.models.ScoringFunctionInterpolation;
import com.azure.search.models.ScoringProfile;
Expand All @@ -37,14 +40,32 @@ public class IndexManagementAsyncTests extends IndexManagementTestBase {

// commonly used lambda definitions
private BiFunction<Index, AccessOptions, Mono<Index>> createOrUpdateIndexAsyncFunc =
(Index index, AccessOptions ac) -> client.createOrUpdateIndex(index);
(Index index, AccessOptions ac) -> createOrUpdateIndex(index, ac.getAccessCondition(), ac.getRequestOptions());

private Supplier<Index> newIndexFunc = this::createTestIndex;

private Function<Index, Index> mutateIndexFunc = this::mutateCorsOptionsInIndex;

private BiFunction<String, AccessOptions, Mono<Void>> deleteIndexAsyncFunc =
(String name, AccessOptions ac) -> client.deleteIndex(name);
(String name, AccessOptions ac) -> deleteIndex(name, ac.getAccessCondition(), ac.getRequestOptions());

private Mono<Index> createOrUpdateIndex(Index index,
AccessCondition accessCondition,
RequestOptions requestOptions) {
return client.createOrUpdateIndexWithResponse(
index,
false,
accessCondition,
requestOptions,
Context.NONE).map(Response::getValue);
}

private Mono<Void> deleteIndex(String indexName,
AccessCondition accessCondition,
RequestOptions requestOptions) {
return client.deleteIndexWithResponse(indexName, accessCondition, requestOptions)
.flatMap(FluxUtil::toMono);
}

@Override
protected void beforeTest() {
Expand Down Expand Up @@ -257,16 +278,17 @@ public void canCreateAndListIndexes() {
Index index1 = createTestIndex();
Index index2 = createTestIndex().setName("hotels2");

PagedFlux<Index> listResponse = client.listIndexes();

StepVerifier
.create(listResponse.collectList())
.assertNext(result -> {
Assert.assertEquals(2, result.size());
Assert.assertEquals(index1.getName(), result.get(0).getName());
Assert.assertEquals(index2.getName(), result.get(1).getName());
})
.verifyComplete();
.create(
client.createIndex(index1)
.then(client.createIndex(index2))
.then(client.listIndexes().collectList()))
.assertNext(result -> {
Assert.assertEquals(2, result.size());
Assert.assertEquals(index1.getName(), result.get(0).getName());
Assert.assertEquals(index2.getName(), result.get(1).getName());
})
.verifyComplete();
}

@Test
Expand Down Expand Up @@ -326,6 +348,7 @@ public void canUpdateSynonymFieldProperty() {
SynonymMap synonymMap = new SynonymMap()
.setName(synonymMapName)
.setSynonyms("hotel,motel");
client.createSynonymMap(synonymMap).block();

// Create an index
Index index = createTestIndex();
Expand All @@ -348,6 +371,7 @@ true, new AccessCondition(), generateRequestOptions()))
.verifyComplete();
}

@Test
public void canUpdateIndexDefinition() {
Index fullFeaturedIndex = createTestIndex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class IndexManagementSyncTests extends IndexManagementTestBase {
AccessOptions,
Index> createOrUpdateIndexFunc =
(Index index, AccessOptions ac) ->
createIndex(index, ac.getAccessCondition(), ac.getRequestOptions());
createOrUpdateIndex(index, ac.getAccessCondition(), ac.getRequestOptions());

private Supplier<Index> newIndexFunc = this::createTestIndex;

Expand All @@ -55,7 +55,7 @@ public class IndexManagementSyncTests extends IndexManagementTestBase {
(String name, AccessOptions ac) ->
client.deleteIndexWithResponse(name, ac.getAccessCondition(), ac.getRequestOptions(), Context.NONE);

private Index createIndex(Index index,
private Index createOrUpdateIndex(Index index,
AccessCondition accessCondition,
RequestOptions requestOptions) {
return client.createOrUpdateIndexWithResponse(
Expand Down Expand Up @@ -128,7 +128,7 @@ public void createIndexFailsWithUsefulMessageOnUserError() {

try {
client.createIndex(index);
Assert.fail("createIndex did not throw an expected Exception");
Assert.fail("createOrUpdateIndex did not throw an expected Exception");
} catch (Exception ex) {
Assert.assertEquals(HttpResponseException.class, ex.getClass());
Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ((HttpResponseException) ex).getResponse().getStatusCode());
Expand Down Expand Up @@ -336,6 +336,7 @@ public void canUpdateSynonymFieldProperty() {
assertIndexesEqual(existingIndex, updatedIndex);
}

@Test
public void canUpdateIndexDefinition() {
Index fullFeaturedIndex = createTestIndex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void assertIndexesEqual(Index expected, Index actual) {
}

Index mutateCorsOptionsInIndex(Index index) {
index.setCorsOptions(index.getCorsOptions().setAllowedOrigins("*"));
index.getCorsOptions().setAllowedOrigins("*");
return index;
}

Expand All @@ -126,7 +126,7 @@ Field getFieldByName(Index index, String name) {
.findFirst().get();
}

protected void indexeWithSelectedFieldAssertions(Index actualIndex) {
void indexeWithSelectedFieldAssertions(Index actualIndex) {
Assert.assertNull(actualIndex.getFields());
Assert.assertNull(actualIndex.getDefaultScoringProfile());
Assert.assertNull(actualIndex.getCorsOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ public void canRunIndexer() {
client.runIndexer(indexer.getName());

StepVerifier.create(client.getIndexerStatus(indexer.getName()))
.assertNext(indexerExecutionInfo -> Assert.assertEquals(IndexerStatus.RUNNING, indexerExecutionInfo.getStatus()))
.assertNext(indexerExecutionInfo -> Assert.assertEquals(
IndexerStatus.RUNNING, indexerExecutionInfo.getStatus()))
.verifyComplete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.azure.search.test.environment.models.LoudHotel;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

Expand All @@ -41,7 +42,7 @@
public class IndexingAsyncTests extends IndexingTestBase {
private SearchIndexAsyncClient client;

@Override
@Test
public void countingDocsOfNewIndexGivesZero() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand All @@ -53,7 +54,7 @@ public void countingDocsOfNewIndexGivesZero() {
.verifyComplete();
}

@Override
@Test
public void indexDoesNotThrowWhenAllActionsSucceed() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand All @@ -79,7 +80,7 @@ public void indexDoesNotThrowWhenAllActionsSucceed() {
verifyComplete();
}

@Override
@Test
public void canIndexWithPascalCaseFields() {
setupIndexFromJsonFile(BOOKS_INDEX_JSON);
client = getSearchIndexClientBuilder(BOOKS_INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -107,7 +108,7 @@ public void canIndexWithPascalCaseFields() {
verifyComplete();
}

@Override
@Test
public void canIndexStaticallyTypedDocuments() throws ParseException {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -164,7 +165,7 @@ public void canIndexStaticallyTypedDocuments() throws ParseException {
.verifyComplete();
}

@Override
@Test
public void canIndexDynamicDocuments() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -211,7 +212,7 @@ public void canIndexDynamicDocuments() {
.verifyComplete();
}

@Override
@Test
public void indexWithInvalidDocumentThrowsException() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand All @@ -225,7 +226,7 @@ public void indexWithInvalidDocumentThrowsException() {
);
}

@Override
@Test
public void canUseIndexWithReservedName() {
Index indexWithReservedName = new Index()
.setName("prototype")
Expand Down Expand Up @@ -257,7 +258,7 @@ public void canUseIndexWithReservedName() {
.verifyComplete();
}

@Override
@Test
public void canRoundtripBoundaryValues() throws ParseException {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand All @@ -279,7 +280,7 @@ public void canRoundtripBoundaryValues() throws ParseException {

}

@Override
@Test
public void dynamicDocumentDateTimesRoundTripAsUtc() {
setupIndexFromJsonFile(BOOKS_INDEX_JSON);
client = getSearchIndexClientBuilder(BOOKS_INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -325,7 +326,7 @@ public void dynamicDocumentDateTimesRoundTripAsUtc() {
.verifyComplete();
}

@Override
@Test
public void mergeDocumentWithoutExistingKeyThrowsIndexingException() throws ParseException {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand All @@ -346,7 +347,7 @@ public void mergeDocumentWithoutExistingKeyThrowsIndexingException() throws Pars
});
}

@Override
@Test
public void staticallyTypedDateTimesRoundTripAsUtc() {
setupIndexFromJsonFile(BOOKS_INDEX_JSON);
client = getSearchIndexClientBuilder(BOOKS_INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -381,7 +382,7 @@ public void staticallyTypedDateTimesRoundTripAsUtc() {
.verifyComplete();
}

@Override
@Test
public void canMergeStaticallyTypedDocuments() throws ParseException {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -498,7 +499,7 @@ public void canMergeStaticallyTypedDocuments() throws ParseException {
.verifyComplete();
}

@Override
@Test
public void canDeleteBatchByKeys() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -531,7 +532,7 @@ public void canDeleteBatchByKeys() {
.verifyComplete();
}

@Override
@Test
public void indexDoesNotThrowWhenDeletingDocumentWithExtraFields() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -565,7 +566,7 @@ public void indexDoesNotThrowWhenDeletingDocumentWithExtraFields() {
.verifyComplete();
}

@Override
@Test
public void indexDoesNotThrowWhenDeletingDynamicDocumentWithExtraFields() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -600,7 +601,7 @@ public void indexDoesNotThrowWhenDeletingDynamicDocumentWithExtraFields() {
.verifyComplete();
}

@Override
@Test
public void canSetExplicitNullsInStaticallyTypedDocument() throws ParseException {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -728,7 +729,7 @@ public void canSetExplicitNullsInStaticallyTypedDocument() throws ParseException
.verifyComplete();
}

@Override
@Test
public void canMergeDynamicDocuments() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down Expand Up @@ -858,7 +859,7 @@ public void canMergeDynamicDocuments() {
.verifyComplete();
}

@Override
@Test
public void canIndexAndAccessResponse() {
createHotelIndex();
client = getSearchIndexClientBuilder(INDEX_NAME).buildAsyncClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.junit.Rule;
import org.junit.rules.TestName;
import org.reactivestreams.Publisher;
import org.unitils.reflectionassert.ReflectionAssert;
import reactor.test.StepVerifier;

import java.time.Duration;
Expand All @@ -65,9 +66,6 @@
import java.util.Map;
import java.util.UUID;

import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
import static org.unitils.reflectionassert.ReflectionComparatorMode.IGNORE_DEFAULTS;

public abstract class SearchServiceTestBase extends TestBase {

private static final String DEFAULT_DNS_SUFFIX = "search.windows.net";
Expand Down Expand Up @@ -572,7 +570,7 @@ protected SearchIndexClientBuilder getSearchIndexClientBuilder(String indexName)
}

protected void assertIndexesEqual(Index expected, Index actual) {
assertReflectionEquals(expected, actual, IGNORE_DEFAULTS);
ReflectionAssert.assertLenientEquals(expected, actual);
}

protected void waitForIndexing() {
Expand Down
Loading

0 comments on commit 4ee7293

Please sign in to comment.