Skip to content

Commit

Permalink
Merge pull request Azure#10 from samvaity/text-analytics
Browse files Browse the repository at this point in the history
Text analytics sync test ci update
  • Loading branch information
samvaity authored Dec 7, 2019
2 parents 39f4a7c + d7e698e commit 690cf56
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 44 deletions.
2 changes: 1 addition & 1 deletion sdk/textanalytics/azure-cs-textanalytics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-core;current} -->
<version>1.2.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void beforeTest() {
}

/**
* Test Detect batch input langugaes with show statistics.
* Verify that we can get statistics on the collection result when given a batch input with options.
*/
@Test
public void detectLanguagesBatchInputShowStatistics() {
Expand All @@ -41,22 +41,22 @@ public void detectLanguagesBatchInputShowStatistics() {
}

/**
* Test Detect batch input langugaes with show statistics.
* Test Detect batch input languages.
*/
@Test
public void detectLanguagesBatchInputShowStatisticsNew() {
detectLanguageShowStatisticsRunner((inputs, options) -> {
StepVerifier.create(client.detectBatchLanguages(inputs, options))
public void detectLanguagesBatchInput() {
detectLanguageRunner((inputs) -> {
StepVerifier.create(client.detectBatchLanguages(inputs))
.assertNext(response -> validateBatchResult(response, getExpectedBatchDetectedLanguages(), "Language"))
.verifyComplete();
});
}

/**
* Verifies that a batch collection is returned on batch input for detectLanguages.
* Test Detect batch languages for List of String input with country Hint.
*/
@Test
public void detectLanguagesBatchStringList() {
public void detectLanguagesBatchListCountryHint() {
detectLanguagesCountryHintRunner((inputs, countryHint) -> {
StepVerifier.create(client.detectLanguages(inputs, countryHint))
.assertNext(response -> validateBatchResult(response, getExpectedBatchDetectedLanguages(), "Language"))
Expand All @@ -65,7 +65,7 @@ public void detectLanguagesBatchStringList() {
}

/**
* Verifies that a batch collection is returned on batch input for detectLanguages.
* Test Detect batch languages for List of String input.
*/
@Test
public void detectLanguagesBatchStringInput() {
Expand All @@ -77,34 +77,11 @@ public void detectLanguagesBatchStringInput() {
}

/**
* Verifies that a batch collection is returned on batch input for detectLanguages.
*/
@Test
public void detectLanguagesBatchInput() {
detectLanguageRunner((inputs) -> {
StepVerifier.create(client.detectBatchLanguages(inputs))
.assertNext(response -> validateBatchResult(response, getExpectedBatchDetectedLanguages(), "Language"))
.verifyComplete();
});
}

/**
* Verifies that a Null pointer exception is thrown when null text is passed.
*/
@Test
public void detectLanguagesNullInput() {
detectLanguageRunner((inputs) -> {
StepVerifier.create(client.detectBatchLanguagesWithResponse(null, null))
.verifyError(NullPointerException.class);
});
}

/**
* Verifies that a single DetectLanguageResult is returned for a single text input to detectLanguages.
* Verifies that a single DetectLanguageResult is returned for a text input to detectLanguages.
*
*/
@Test
public void detectLanguage() {
public void detectSingleTextLanguage() {
DetectedLanguage primaryLanguage = new DetectedLanguage().setName("English").setIso6391Name("en").setScore(1.0);
List<DetectedLanguage> expectedLanguageList = new ArrayList<>(Arrays.asList(primaryLanguage));
StepVerifier.create(client.detectLanguage("This is a test English Text"))
Expand All @@ -113,7 +90,7 @@ public void detectLanguage() {
}

/**
* Verifies that a single error DetectLanguageResult is returned for a single text input with invalid country hint.
* Verifies that an error DetectLanguageResult is returned for a text input with invalid country hint.
*
* TODO: update error Model. #6559
*/
Expand All @@ -140,6 +117,17 @@ public void detectLanguage() {
// .verifyComplete();
// }

/**
* Verifies that a Null pointer exception is thrown when null text is passed.
*/
@Test
public void detectLanguagesNullInput() {
detectLanguageRunner((inputs) -> {
StepVerifier.create(client.detectBatchLanguagesWithResponse(null, null))
.verifyError(NullPointerException.class);
});
}

/**
* Verifies that the error result is returned when empty text is passed.
*/
Expand All @@ -159,7 +147,7 @@ public void detectLanguageNullText() {
}

/**
* Verifies that an document returns with an error when error text is passed.
* Verifies that detectLanguage returns an "UNKNOWN" result when faulty text is passed.
*/
@Test
public void detectLanguageFaultyText() {
Expand All @@ -168,4 +156,6 @@ public void detectLanguageFaultyText() {
assertEquals(response.getPrimaryLanguage().getIso6391Name(), "(Unknown)"))
.verifyComplete();
}

// TODO: add with response tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
package com.azure.cs.textanalytics;

import com.azure.core.util.logging.ClientLogger;
import com.azure.cs.textanalytics.models.DetectLanguageResult;
import com.azure.cs.textanalytics.models.DetectedLanguage;
import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class TextAnalyticsClientTest extends TextAnalyticsClientTestBase {

Expand All @@ -24,13 +30,86 @@ protected void beforeTest() {
.buildClient());
}

/**
* Verify that we can get statistics on the collection result when given a batch input with options.
*/
@Test
public void detectLanguage() {

public void detectLanguagesBatchInputShowStatistics() {
detectLanguageShowStatisticsRunner((inputs, options) ->
validateBatchResult(client.detectBatchLanguages(inputs, options), getExpectedBatchDetectedLanguages(),
"Language"));
}

@Override
/**
* Test Detect batch input languages.
*/
@Test
public void detectLanguagesBatchInput() {
detectLanguageRunner((inputs) -> validateBatchResult(client.detectBatchLanguages(inputs),
getExpectedBatchDetectedLanguages(), "Language"));
}

/**
* Test Detect batch languages for List of String input with country Hint.
*/
@Test
public void detectLanguagesBatchListCountryHint() {
detectLanguagesCountryHintRunner((inputs, countryHint) -> validateBatchResult(
client.detectLanguages(inputs, countryHint), getExpectedBatchDetectedLanguages(), "Language"));
}

/**
* Test Detect batch languages for List of String input.
*/
@Test
public void detectLanguagesBatchStringInput() {
detectLanguageStringInputRunner((inputs) -> validateBatchResult(client.detectLanguages(inputs),
getExpectedBatchDetectedLanguages(), "Language"));
}

/**
* Verifies that a single DetectLanguageResult is returned for a text input to detectLanguages.
*
*/
@Test
public void detectSingleTextLanguage() {
DetectedLanguage primaryLanguage = new DetectedLanguage().setName("English").setIso6391Name("en").setScore(1.0);
List<DetectedLanguage> expectedLanguageList = new ArrayList<>(Arrays.asList(primaryLanguage));
validateDetectedLanguages(
client.detectLanguage("This is a test English Text").getDetectedLanguages(), expectedLanguageList);
}

/**
* Verifies that an exception is thrown when null text is passed.
*/
@Test
public void detectLanguagesNullInput() {
assertRunnableThrowsException(() -> client.detectBatchLanguages(null, null), NullPointerException.class);
}

/**
* Verifies that the error result is returned when empty text is passed.
*/
@Test
public void detectLanguageEmptyText() {
DetectLanguageResult result = client.detectLanguage("");
assertNotNull(result.getError());
}

/**
* Verifies that it returns an exception is thrown when null text is passed.
*/
@Test
public void detectLanguageNullText() {
assertRunnableThrowsException(() -> client.detectLanguage(null), NullPointerException.class);
}

/**
* Verifies that detectLanguage returns an "UNKNOWN" result when faulty text is passed.
*/
@Test
public void detectLanguageFaultyText() {
DetectLanguageResult result = client.detectLanguage("!@#%%");
assertEquals(result.getPrimaryLanguage().getIso6391Name(), "(Unknown)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <T> T clientSetup(Function<HttpPipeline, T> clientBuilder) {
}

@Test
public abstract void detectLanguage();
public abstract void detectSingleTextLanguage();

@Test
public abstract void detectLanguagesBatchInput();
Expand Down Expand Up @@ -335,4 +335,18 @@ static void validateDetectedLanguages(List<DetectedLanguage> expectedLanguageLis
validatePrimaryLanguage(expectedDetectedLanguage, actualDetectedLanguage);
}
}

/**
* Helper method to verify that a command throws an IllegalArgumentException.
*
* @param exceptionThrower Command that should throw the exception
*/
static <T> void assertRunnableThrowsException(Runnable exceptionThrower, Class<T> exception) {
try {
exceptionThrower.run();
fail();
} catch (Exception ex) {
assertEquals(exception, ex.getClass());
}
}
}
4 changes: 2 additions & 2 deletions sdk/textanalytics/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trigger:
- release/*
paths:
include:
- sdk/cognitiveservices/azure-cs-textanalytics
- sdk/textanalytics/azure-cs-textanalytics

pr:
branches:
Expand All @@ -31,7 +31,7 @@ pr:
- release/*
paths:
include:
- sdk/cognitiveservices/azure-cs-textanalytics
- sdk/textanalytics/azure-cs-textanalytics

stages:
- template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
Expand Down

0 comments on commit 690cf56

Please sign in to comment.