Skip to content

Commit

Permalink
Add test for creating custom skillsets (Azure#260)
Browse files Browse the repository at this point in the history
* Add test for creating custom skillsets
  • Loading branch information
sakintoye authored Nov 13, 2019
1 parent 47258a1 commit 941cbe7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ public void createSkillsetReturnsCorrectDefinitionWithSplitDefaultSettings() {
.verifyComplete();
}

@Override
public void createCustomSkillsetReturnsCorrectDefinition() {
Skillset expected = createSkillsetWithCustomSkills();

StepVerifier
.create(client.createSkillset(expected))
.assertNext(actual -> assertSkillsetsEqual(expected, actual))
.verifyComplete();
}

@Override
public void getSkillsetThrowsOnNotFound() {
String skillsetName = "thisdoesnotexist";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ public void createSkillsetReturnsCorrectDefinitionWithSplitDefaultSettings() {
assertSkillsetsEqual(expectedSkillset, actualSkillset);
}

@Override
public void createCustomSkillsetReturnsCorrectDefinition() {
Skillset expected = createSkillsetWithCustomSkills();
Skillset actual = client.createSkillset(expected);

assertSkillsetsEqual(expected, actual);
}

@Override
public void getSkillsetThrowsOnNotFound() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import com.azure.search.models.TextExtractionAlgorithm;
import com.azure.search.models.TextSplitMode;
import com.azure.search.models.VisualFeature;
import com.azure.search.models.WebApiSkill;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
Expand Down Expand Up @@ -119,6 +121,9 @@ public abstract class SkillsetManagementTestBase extends SearchServiceTestBase {
@Test
public abstract void existsReturnsTrueForExistingSkillset();

@Test
public abstract void createCustomSkillsetReturnsCorrectDefinition();

protected void assertSkillsetsEqual(Skillset expected, Skillset actual) {
expected.setETag("none");
actual.setETag("none");
Expand Down Expand Up @@ -749,4 +754,35 @@ protected Skillset createSkillsetWithSplitDefaultSettings() {
.setDescription("Skillset for testing default configuration")
.setSkills(skills);
}

protected Skillset createSkillsetWithCustomSkills() {
HashMap<String, String> headers = new HashMap<>();
headers.put("Ocp-Apim-Subscription-Key", "foobar");

List<InputFieldMappingEntry> inputs = Collections.singletonList(
new InputFieldMappingEntry()
.setName("text")
.setSource("/document/mytext")
);

List<OutputFieldMappingEntry> outputs = Collections.singletonList(
new OutputFieldMappingEntry()
.setName("textItems")
.setTargetName("myTextItems")
);

Skill webApiSkill = new WebApiSkill()
.setUri("https://indexer-e2e-webskill.azurewebsites.net/api/InvokeTextAnalyticsV3?code=foo")
.setHttpMethod("POST")
.setHttpHeaders(headers)
.setInputs(inputs)
.setOutputs(outputs)
.setName("webapi-skill")
.setDescription("Calls an Azure function, which in turn calls Bing Entity Search");

return new Skillset()
.setName("custom-skillset")
.setDescription("Skillset for testing custom skillsets")
.setSkills(Collections.singletonList(webApiSkill));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://azs-sdkb83450069ebf.search.windows.net/skillsets?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "37dffb9e-f9ba-463e-a695-89f5bea422df",
"StatusCode" : "201",
"Date" : "Wed, 13 Nov 2019 18:54:10 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D7686ADE4EC9C3\"",
"elapsed-time" : "98",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "790",
"Body" : "{\"@odata.context\":\"https://azs-sdkb83450069ebf.search.windows.net/$metadata#skillsets/$entity\",\"@odata.etag\":\"\\\"0x8D7686ADE4EC9C3\\\"\",\"name\":\"custom-skillset\",\"description\":\"Skillset for testing custom skillsets\",\"skills\":[{\"@odata.type\":\"#Microsoft.Skills.Custom.WebApiSkill\",\"name\":\"webapi-skill\",\"description\":\"Calls an Azure function, which in turn calls Bing Entity Search\",\"context\":null,\"uri\":\"https://indexer-e2e-webskill.azurewebsites.net/api/InvokeTextAnalyticsV3?code=foo\",\"httpMethod\":\"POST\",\"timeout\":null,\"batchSize\":null,\"degreeOfParallelism\":null,\"inputs\":[{\"name\":\"text\",\"source\":\"/document/mytext\",\"sourceContext\":null,\"inputs\":[]}],\"outputs\":[{\"name\":\"textItems\",\"targetName\":\"myTextItems\"}],\"httpHeaders\":{\"Ocp-Apim-Subscription-Key\":\"foobar\"}}],\"cognitiveServices\":null}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdkb83450069ebf.search.windows.net/skillsets('custom-skillset')?api-version=2019-05-06"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit 941cbe7

Please sign in to comment.