Skip to content

Commit

Permalink
Merge branch 'master' into feature/suggest-test-minimum-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
LizaShak committed Sep 22, 2019
2 parents 7087915 + 7f55949 commit 86a7c3f
Show file tree
Hide file tree
Showing 15 changed files with 528 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void initializeClient() {
}

@Override
public void autocompleteThrowsWhenGivenBadSuggesterName() throws Exception {
public void canAutocompleteThrowsWhenGivenBadSuggesterName() {
AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);

Expand All @@ -46,7 +46,7 @@ public void autocompleteThrowsWhenGivenBadSuggesterName() throws Exception {
}

@Override
public void autocompleteDefaultsToOneTermMode() throws Exception {
public void canAutocompleteDefaultsToOneTermMode() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular");

Expand All @@ -55,7 +55,7 @@ public void autocompleteDefaultsToOneTermMode() throws Exception {
}

@Override
public void autocompleteExcludesFieldsNotInSuggester() throws Exception {
public void canAutocompleteExcludesFieldsNotInSuggester() {
AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);
params.searchFields(Arrays.asList("HotelName"));
Expand All @@ -69,7 +69,7 @@ public void autocompleteExcludesFieldsNotInSuggester() throws Exception {
}

@Override
public void autocompleteFuzzyIsOffByDefault() throws Exception {
public void canAutocompleteFuzzyIsOffByDefault() {
AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);

Expand All @@ -81,7 +81,7 @@ public void autocompleteFuzzyIsOffByDefault() throws Exception {
}

@Override
public void autocompleteOneTerm() throws Exception {
public void canAutocompleteOneTerm() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular");

Expand All @@ -93,7 +93,45 @@ public void autocompleteOneTerm() throws Exception {
}

@Override
public void autocompleteStaticallyTypedDocuments() throws Exception {
public void canAutocompleteOneTermWithContext() {
List<String> expectedText = Arrays.asList("very police", "very polite", "very popular");
List<String> expectedQueryPlusText = Arrays.asList("looking for very police", "looking for very polite", "looking for very popular");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM_WITH_CONTEXT);

PagedFlux<AutocompleteItem> results = client.autocomplete("looking for very po", "sg", null, params);
validateResults(expectedText, expectedQueryPlusText, results);
}

@Override
public void canAutocompleteOneTermWithFuzzy() {
List<String> expectedText = Arrays.asList("model", "modern", "morel", "motel");
List<String> expectedQueryPlusText = Arrays.asList("model", "modern", "morel", "motel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);
params.useFuzzyMatching(true);

PagedFlux<AutocompleteItem> results = client.autocomplete("mod", "sg", null, params);
validateResults(expectedText, expectedQueryPlusText, results);
}

@Override
public void canAutocompleteOneTermWithContextWithFuzzy() {
List<String> expectedText = Arrays.asList("very polite", "very police");
List<String> expectedQueryPlusText = Arrays.asList("very polite", "very police");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM_WITH_CONTEXT);
params.useFuzzyMatching(true);

PagedFlux<AutocompleteItem> results = client.autocomplete("very polit", "sg", null, params);
validateResults(expectedText, expectedQueryPlusText, results);
}

@Override
public void canAutocompleteStaticallyTypedDocuments() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("very point", "very police", "very polite", "very pool", "very popular");

Expand All @@ -106,7 +144,7 @@ public void autocompleteStaticallyTypedDocuments() throws Exception {
}

@Override
public void autocompleteThrowsWhenRequestIsMalformed() throws Exception {
public void canAutocompleteThrowsWhenRequestIsMalformed() {
PagedFlux<AutocompleteItem> results = client.autocomplete("very po", "");
StepVerifier
.create(results)
Expand All @@ -117,6 +155,32 @@ public void autocompleteThrowsWhenRequestIsMalformed() throws Exception {
});
}

@Override
public void canAutocompleteTwoTerms() {
List<String> expectedText = Arrays.asList("point motel", "police station", "polite staff", "pool a", "popular hotel");
List<String> expectedQueryPlusText = Arrays.asList("point motel", "police station", "polite staff", "pool a", "popular hotel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.TWO_TERMS);

PagedFlux<AutocompleteItem> results = client.autocomplete("po", "sg", null, params);
validateResults(expectedText, expectedQueryPlusText, results);
}

@Override
public void canAutocompleteTwoTermsWithFuzzy() {
List<String> expectedText = Arrays.asList("model suites", "modern architecture", "modern stay", "morel coverings", "motel");
List<String> expectedQueryPlusText = Arrays.asList("model suites", "modern architecture", "modern stay", "morel coverings", "motel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.TWO_TERMS);
params.useFuzzyMatching(true);


PagedFlux<AutocompleteItem> results = client.autocomplete("mod", "sg", null, params);
validateResults(expectedText, expectedQueryPlusText, results);
}

/**
* Validate the text and query plus text results
* @param expectedText
Expand All @@ -125,7 +189,6 @@ public void autocompleteThrowsWhenRequestIsMalformed() throws Exception {
*/
private void validateResults(List<String> expectedText, List<String> expectedQueryPlusText, PagedFlux<AutocompleteItem> results) {
StepVerifier.create(results.byPage()).assertNext(pageResult -> {
Assert.assertEquals(5, pageResult.items().size());
List<String> textResults = new ArrayList<>();
List<String> queryPlusTextResults = new ArrayList<>();
pageResult.items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void initializeClient() {
}

@Test
public void autocompleteThrowsWhenGivenBadSuggesterName() {
public void canAutocompleteThrowsWhenGivenBadSuggesterName() {
thrown.expect(HttpResponseException.class);
thrown.expectMessage("The specified suggester name 'Invalid suggester' does not exist in this index definition.\\r\\nParameter name: name");

Expand All @@ -47,8 +47,8 @@ public void autocompleteThrowsWhenGivenBadSuggesterName() {
results.iterableByPage().iterator().next();
}

@Test
public void autocompleteDefaultsToOneTermMode() {
@Override
public void canAutocompleteDefaultsToOneTermMode() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular");

Expand All @@ -59,8 +59,55 @@ public void autocompleteDefaultsToOneTermMode() {
validateResults(results, expectedText, expectedQueryPlusText);
}

@Override
public void canAutocompleteOneTermWithContext() {
List<String> expectedText = Arrays.asList("very police", "very polite", "very popular");
List<String> expectedQueryPlusText = Arrays.asList("looking for very police", "looking for very polite", "looking for very popular");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM_WITH_CONTEXT);

PagedIterable<AutocompleteItem> results = client.autocomplete("looking for very po", "sg", null, params);
results.iterableByPage().iterator().next();

Assert.assertNotNull(results);
validateResults(results, expectedText, expectedQueryPlusText);
}

@Override
public void canAutocompleteOneTermWithFuzzy() {
List<String> expectedText = Arrays.asList("model", "modern", "morel", "motel");
List<String> expectedQueryPlusText = Arrays.asList("model", "modern", "morel", "motel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);
params.useFuzzyMatching(true);

PagedIterable<AutocompleteItem> results = client.autocomplete("mod", "sg", null, params);
results.iterableByPage().iterator().next();

Assert.assertNotNull(results);
validateResults(results, expectedText, expectedQueryPlusText);
}

@Override
public void canAutocompleteOneTermWithContextWithFuzzy() {
List<String> expectedText = Arrays.asList("very polite", "very police");
List<String> expectedQueryPlusText = Arrays.asList("very polite", "very police");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM_WITH_CONTEXT);
params.useFuzzyMatching(true);

PagedIterable<AutocompleteItem> results = client.autocomplete("very polit", "sg", null, params);
results.iterableByPage().iterator().next();

Assert.assertNotNull(results);
validateResults(results, expectedText, expectedQueryPlusText);
}

@Test
public void autocompleteExcludesFieldsNotInSuggester() throws Exception {
public void canAutocompleteExcludesFieldsNotInSuggester() {
AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);
params.searchFields(Arrays.asList("HotelName"));
Expand All @@ -75,7 +122,7 @@ public void autocompleteExcludesFieldsNotInSuggester() throws Exception {
}

@Test
public void autocompleteFuzzyIsOffByDefault() throws Exception {
public void canAutocompleteFuzzyIsOffByDefault() {
AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.ONE_TERM);

Expand All @@ -89,7 +136,7 @@ public void autocompleteFuzzyIsOffByDefault() throws Exception {
}

@Test
public void autocompleteOneTerm() throws Exception {
public void canAutocompleteOneTerm() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular");

Expand All @@ -104,7 +151,7 @@ public void autocompleteOneTerm() throws Exception {
}

@Test
public void autocompleteStaticallyTypedDocuments() throws Exception {
public void canAutocompleteStaticallyTypedDocuments() {
List<String> expectedText = Arrays.asList("point", "police", "polite", "pool", "popular");
List<String> expectedQueryPlusText = Arrays.asList("very point", "very police", "very polite", "very pool", "very popular");

Expand All @@ -120,14 +167,44 @@ public void autocompleteStaticallyTypedDocuments() throws Exception {
}

@Test
public void autocompleteThrowsWhenRequestIsMalformed() throws Exception {
public void canAutocompleteThrowsWhenRequestIsMalformed() {
thrown.expect(HttpResponseException.class);
thrown.expectMessage("Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\\r\\nParameter name: suggestions");

PagedIterable<AutocompleteItem> results = client.autocomplete("very po", "");
results.iterableByPage().iterator().next();
}

@Override
public void canAutocompleteTwoTerms() {
List<String> expectedText = Arrays.asList("point motel", "police station", "polite staff", "pool a", "popular hotel");
List<String> expectedQueryPlusText = Arrays.asList("point motel", "police station", "polite staff", "pool a", "popular hotel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.TWO_TERMS);

PagedIterable<AutocompleteItem> results = client.autocomplete("po", "sg", null, params);
results.iterableByPage().iterator().next();

Assert.assertNotNull(results);
validateResults(results, expectedText, expectedQueryPlusText);
}

@Override
public void canAutocompleteTwoTermsWithFuzzy() {
List<String> expectedText = Arrays.asList("model suites", "modern architecture", "modern stay", "morel coverings", "motel");
List<String> expectedQueryPlusText = Arrays.asList("model suites", "modern architecture", "modern stay", "morel coverings", "motel");

AutocompleteParameters params = new AutocompleteParameters();
params.autocompleteMode(AutocompleteMode.TWO_TERMS);
params.useFuzzyMatching(true);

PagedIterable<AutocompleteItem> results = client.autocomplete("mod", "sg", null, params);
results.iterableByPage().iterator().next();

Assert.assertNotNull(results);
validateResults(results, expectedText, expectedQueryPlusText);
}

/**
* Compare the autocomplete results with the expected strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,39 @@ protected void beforeTest() {
protected abstract void initializeClient();

@Test
public abstract void autocompleteThrowsWhenGivenBadSuggesterName() throws Exception;
public abstract void canAutocompleteThrowsWhenGivenBadSuggesterName() throws Exception;

@Test
public abstract void autocompleteDefaultsToOneTermMode() throws Exception;
public abstract void canAutocompleteDefaultsToOneTermMode() throws Exception;

@Test
public abstract void autocompleteExcludesFieldsNotInSuggester() throws Exception;
public abstract void canAutocompleteExcludesFieldsNotInSuggester() throws Exception;

@Test
public abstract void autocompleteFuzzyIsOffByDefault() throws Exception;
public abstract void canAutocompleteFuzzyIsOffByDefault() throws Exception;

@Test
public abstract void autocompleteOneTerm() throws Exception;
public abstract void canAutocompleteOneTerm() throws Exception;

@Test
public abstract void autocompleteStaticallyTypedDocuments() throws Exception;
public abstract void canAutocompleteOneTermWithContext() throws Exception;

@Test
public abstract void autocompleteThrowsWhenRequestIsMalformed() throws Exception;
public abstract void canAutocompleteOneTermWithFuzzy() throws Exception;

@Test
public abstract void canAutocompleteOneTermWithContextWithFuzzy() throws Exception;

@Test
public abstract void canAutocompleteStaticallyTypedDocuments() throws Exception;

@Test
public abstract void canAutocompleteThrowsWhenRequestIsMalformed() throws Exception;

@Test
public abstract void canAutocompleteTwoTerms() throws Exception;

@Test
public abstract void canAutocompleteTwoTermsWithFuzzy() throws Exception;

}
Loading

0 comments on commit 86a7c3f

Please sign in to comment.