diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementAsyncTests.java b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementAsyncTests.java index 4017a7c80c9ca..678fbc2881993 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementAsyncTests.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementAsyncTests.java @@ -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"; diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementSyncTests.java b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementSyncTests.java index 0cd8c28d05c91..5ce90b5190dcd 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementSyncTests.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementSyncTests.java @@ -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 { diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementTestBase.java b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementTestBase.java index ed18ee78fcd8f..d20a0eaf5447b 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementTestBase.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/SkillsetManagementTestBase.java @@ -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; @@ -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"); @@ -749,4 +754,35 @@ protected Skillset createSkillsetWithSplitDefaultSettings() { .setDescription("Skillset for testing default configuration") .setSkills(skills); } + + protected Skillset createSkillsetWithCustomSkills() { + HashMap headers = new HashMap<>(); + headers.put("Ocp-Apim-Subscription-Key", "foobar"); + + List inputs = Collections.singletonList( + new InputFieldMappingEntry() + .setName("text") + .setSource("/document/mytext") + ); + + List 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)); + } } diff --git a/sdk/search/azure-search/src/test/resources/session-records/createCustomSkillsetReturnsCorrectDefinition.json b/sdk/search/azure-search/src/test/resources/session-records/createCustomSkillsetReturnsCorrectDefinition.json new file mode 100644 index 0000000000000..27ee7377a9f01 --- /dev/null +++ b/sdk/search/azure-search/src/test/resources/session-records/createCustomSkillsetReturnsCorrectDefinition.json @@ -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" : [ ] +} \ No newline at end of file