Skip to content

Commit

Permalink
Adding unit test to verify indexer's skillset can be changed (Azure#275)
Browse files Browse the repository at this point in the history
* Adding unit test to verify indexer's skillset can be changed
Task 1486
  • Loading branch information
eladiw authored Nov 20, 2019
1 parent e088e35 commit d25c7bb
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.azure.search.models.IndexerExecutionStatus;
import com.azure.search.models.IndexerStatus;
import com.azure.search.models.IndexingParameters;
import com.azure.search.models.Skillset;
import org.junit.Assert;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand All @@ -38,9 +39,9 @@ protected Index createIndex(Index index) {
return client.createOrUpdateIndex(index).block();
}

protected Indexer createIndexer(Indexer indexer) {
return client.createOrUpdateIndexer(indexer).block();
}
protected Indexer createIndexer(Indexer indexer) { return client.createOrUpdateIndexer(indexer).block(); }

protected Skillset createSkillset(Skillset skillset) { return client.createOrUpdateSkillset(skillset).block(); }

@Override
protected Indexer getIndexer(String indexerName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.search.models.IndexerExecutionStatus;
import com.azure.search.models.IndexerStatus;
import com.azure.search.models.IndexingParameters;
import com.azure.search.models.Skillset;
import org.junit.Assert;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -40,6 +41,10 @@ protected Indexer createIndexer(Indexer indexer) {
return client.createOrUpdateIndexer(indexer);
}

protected Skillset createSkillset(Skillset skillset) {
return client.createOrUpdateSkillset(skillset);
}

@Override
protected Indexer getIndexer(String indexerName) {
return client.getIndexer(indexerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import com.azure.search.models.Indexer;
import com.azure.search.models.IndexingParameters;
import com.azure.search.models.IndexingSchedule;
import com.azure.search.models.InputFieldMappingEntry;
import com.azure.search.models.OcrSkill;
import com.azure.search.models.OutputFieldMappingEntry;
import com.azure.search.models.Skill;
import com.azure.search.models.Skillset;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -158,6 +163,57 @@ public void canCreateIndexerWithBlobParams() {
createAndValidateIndexer(indexer);
}

@Test
public void canUpdateIndexerSkillset() {
DataSource datasource = createTestSqlDataSource();
createDatasource(datasource);

// Create a new skillset object
// todo: task 1544 - change all over the code that that the object creation and actual service creation will
// have meaningful and differentiated names
Skillset skillset = createSkillsetObject();

// create the skillset in the search service
createSkillset(skillset);
Indexer updatedExpected = createIndexerWithDifferentSkillset(skillset.getName());
createUpdateAndValidateIndexer(updatedExpected, SQL_DATASOURCE_NAME);
}

/**
* Create a new valid skillset object
* @return the newly created skillset object
*/
private Skillset createSkillsetObject() {
List<InputFieldMappingEntry> inputs = Arrays.asList(
new InputFieldMappingEntry()
.setName("url")
.setSource("/document/url"),
new InputFieldMappingEntry()
.setName("queryString")
.setSource("/document/queryString")
);

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

List<Skill> skills = Collections.singletonList(
new OcrSkill()
.setShouldDetectOrientation(true)
.setName("myocr")
.setDescription("Tested OCR skill")
.setContext("/document")
.setInputs(inputs)
.setOutputs(outputs)
);
return new Skillset()
.setName("ocr-skillset")
.setDescription("Skillset for testing default configuration")
.setSkills(skills);
}

@Test
public void deleteIndexerIsIdempotent() {
// Create Datasource
Expand Down Expand Up @@ -400,6 +456,18 @@ Indexer createIndexerWithDifferentSchedule() {
return indexer;
}

/**
* Create a new indexer and change its skillset
* @return the created indexer
*/
Indexer createIndexerWithDifferentSkillset(String skillsetName) {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer")
.setSkillsetName(skillsetName);

return indexer;
}

/**
* Create a new indexer and change its indexing parameters
* @return the created indexer
Expand Down Expand Up @@ -467,4 +535,6 @@ List<Indexer> prepareIndexersForCreateAndListIndexers() {
protected abstract Indexer getIndexer(String indexerName);

protected abstract Response<Void> deleteIndexer(Indexer indexer);

protected abstract Skillset createSkillset(Skillset skillset);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/datasources('azs-java-test-sql')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "f58410b7-a225-455d-a984-d44f2e016d66",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 09:44:48 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B42C99DBDD1\"",
"elapsed-time" : "52",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "395",
"Body" : "{\"@odata.context\":\"https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D76B42C99DBDD1\\\"\",\"name\":\"azs-java-test-sql\",\"description\":\"Some data source\",\"type\":\"azuresql\",\"subtype\":null,\"credentials\":{\"connectionString\":null},\"container\":{\"name\":\"GeoNamesRI\",\"query\":null},\"dataChangeDetectionPolicy\":null,\"dataDeletionDetectionPolicy\":null}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/datasources('azs-java-test-sql')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/skillsets('ocr-skillset')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "933b2f05-f904-4c0e-9584-58706a02597f",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 09:44:48 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B42C9C3C475\"",
"elapsed-time" : "41",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "708",
"Body" : "{\"@odata.context\":\"https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/$metadata#skillsets/$entity\",\"@odata.etag\":\"\\\"0x8D76B42C9C3C475\\\"\",\"name\":\"ocr-skillset\",\"description\":\"Skillset for testing default configuration\",\"skills\":[{\"@odata.type\":\"#Microsoft.Skills.Vision.OcrSkill\",\"name\":\"myocr\",\"description\":\"Tested OCR skill\",\"context\":\"/document\",\"textExtractionAlgorithm\":null,\"lineEnding\":null,\"defaultLanguageCode\":null,\"detectOrientation\":true,\"inputs\":[{\"name\":\"url\",\"source\":\"/document/url\",\"sourceContext\":null,\"inputs\":[]},{\"name\":\"queryString\",\"source\":\"/document/queryString\",\"sourceContext\":null,\"inputs\":[]}],\"outputs\":[{\"name\":\"text\",\"targetName\":\"mytext\"}]}],\"cognitiveServices\":null}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/skillsets('ocr-skillset')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "018ffdbf-c9d2-4f35-989d-fc5bd896e3a8",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 09:44:50 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B42CA4DAB2F\"",
"elapsed-time" : "785",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "982",
"Body" : "{\"@odata.context\":\"https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/$metadata#indexes/$entity\",\"@odata.etag\":\"\\\"0x8D76B42CA4DAB2F\\\"\",\"name\":\"indexforindexers\",\"defaultScoringProfile\":null,\"fields\":[{\"name\":\"county_name\",\"type\":\"Edm.String\",\"searchable\":false,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"state\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"feature_id\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":false,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":true,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]}],\"scoringProfiles\":[],\"corsOptions\":null,\"suggesters\":[],\"analyzers\":[],\"tokenizers\":[],\"tokenFilters\":[],\"charFilters\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/indexers('indexer')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "640e4a9d-058a-42e8-ab1c-414880006623",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 09:44:50 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B42CA81BE91\"",
"elapsed-time" : "49",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "417",
"Body" : "{\"@odata.context\":\"https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D76B42CA81BE91\\\"\",\"name\":\"indexer\",\"description\":null,\"dataSourceName\":\"azs-java-test-sql\",\"skillsetName\":null,\"targetIndexName\":\"indexforindexers\",\"disabled\":true,\"schedule\":{\"interval\":\"P1D\",\"startTime\":\"0001-01-01T00:00:00Z\"},\"parameters\":null,\"fieldMappings\":[],\"outputFieldMappings\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/indexers('indexer')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/indexers('indexer')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "d401b671-0915-44cb-8234-6d87a592c3ff",
"StatusCode" : "200",
"Date" : "Sun, 17 Nov 2019 09:44:50 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B42CAC5DAEE\"",
"elapsed-time" : "375",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "427",
"Body" : "{\"@odata.context\":\"https://azs-sdka1a74632a90c.search-dogfood.windows-int.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D76B42CAC5DAEE\\\"\",\"name\":\"indexer\",\"description\":null,\"dataSourceName\":\"azs-java-test-sql\",\"skillsetName\":\"ocr-skillset\",\"targetIndexName\":\"indexforindexers\",\"disabled\":null,\"schedule\":{\"interval\":\"P1D\",\"startTime\":\"0001-01-01T00:00:00Z\"},\"parameters\":null,\"fieldMappings\":[],\"outputFieldMappings\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit d25c7bb

Please sign in to comment.