Skip to content

Commit

Permalink
Feature/Test coverage for Index, skillset, synonym maps client methods (
Browse files Browse the repository at this point in the history
  • Loading branch information
Humoiz authored Nov 22, 2019
1 parent 0c5b7b9 commit 6cb8d03
Show file tree
Hide file tree
Showing 95 changed files with 2,191 additions and 1,271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.azure.search.models.DataType;
import com.azure.search.models.Field;
import com.azure.search.models.Index;
import com.azure.search.models.IndexGetStatisticsResult;
import com.azure.search.models.ScoringProfile;
import com.azure.search.models.MagnitudeScoringParameters;
import com.azure.search.models.MagnitudeScoringFunction;
Expand Down Expand Up @@ -51,6 +50,20 @@ public void createIndexReturnsCorrectDefinition() {
assertIndexesEqual(index, createdIndex);
})
.verifyComplete();

StepVerifier
.create(client.createIndex(index.setName("hotel1"), generateRequestOptions()))
.assertNext(createdIndex -> {
assertIndexesEqual(index, createdIndex);
})
.verifyComplete();

StepVerifier
.create(client.createIndexWithResponse(index.setName("hotel2"), generateRequestOptions()))
.assertNext(createdIndex -> {
assertIndexesEqual(index, createdIndex.getValue());
})
.verifyComplete();
}

@Override
Expand Down Expand Up @@ -115,6 +128,20 @@ public void getIndexReturnsCorrectDefinition() {
assertIndexesEqual(index, res);
})
.verifyComplete();

StepVerifier
.create(client.getIndex(index.getName(), generateRequestOptions()))
.assertNext(res -> {
assertIndexesEqual(index, res);
})
.verifyComplete();

StepVerifier
.create(client.getIndexWithResponse(index.getName(), generateRequestOptions()))
.assertNext(res -> {
assertIndexesEqual(index, res.getValue());
})
.verifyComplete();
}

@Override
Expand All @@ -137,6 +164,16 @@ public void existsReturnsTrueForExistingIndex() {
.create(client.indexExists(index.getName()))
.assertNext(res -> Assert.assertTrue(res))
.verifyComplete();

StepVerifier
.create(client.indexExists(index.getName(), generateRequestOptions()))
.assertNext(res -> Assert.assertTrue(res))
.verifyComplete();

StepVerifier
.create(client.indexExistsWithResponse(index.getName(), generateRequestOptions()))
.assertNext(res -> Assert.assertTrue(res.getValue()))
.verifyComplete();
}

@Override
Expand All @@ -162,11 +199,8 @@ public void deleteIndexIfNotChangedWorksOnlyOnCurrentResource() {
});

Response<Void> response = client.deleteIndexWithResponse(index.getName(),
generateIfNotChangedAccessCondition(currentResource.getETag()),
null,
null
)
.block();
generateIfNotChangedAccessCondition(currentResource.getETag()), generateRequestOptions()).block();

Assert.assertEquals(HttpResponseStatus.NO_CONTENT.code(), response.getStatusCode());
}

Expand Down Expand Up @@ -195,29 +229,29 @@ public void deleteIndexIsIdempotent() {
.setKey(true)
));
StepVerifier
.create(client.deleteIndexWithResponse(index.getName(), null, null, null))
.create(client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions()))
.assertNext(indexResponse -> {
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), indexResponse.getStatusCode());
})
.verifyComplete();

StepVerifier
.create(client.createIndexWithResponse(index, null, null))
.create(client.createIndexWithResponse(index, generateRequestOptions()))
.assertNext(indexResponse -> {
Assert.assertEquals(HttpResponseStatus.CREATED.code(), indexResponse.getStatusCode());
})
.verifyComplete();

// Delete the same index twice
StepVerifier
.create(client.deleteIndexWithResponse(index.getName(), null, null, null))
.create(client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions()))
.assertNext(indexResponse -> {
Assert.assertEquals(HttpResponseStatus.NO_CONTENT.code(), indexResponse.getStatusCode());
})
.verifyComplete();

StepVerifier
.create(client.deleteIndexWithResponse(index.getName(), null, null, null))
.create(client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions()))
.assertNext(indexResponse -> {
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), indexResponse.getStatusCode());
})
Expand Down Expand Up @@ -482,11 +516,22 @@ true, new AccessCondition(), generateRequestOptions()))

@Override
public void createOrUpdateIndexCreatesWhenIndexDoesNotExist() {
Index index = createTestIndex();
Index expected = createTestIndex();

StepVerifier
.create(client.createOrUpdateIndex(expected))
.assertNext(res -> assertIndexesEqual(expected, res))
.verifyComplete();

StepVerifier
.create(client.createOrUpdateIndex(expected.setName("hotel1"),
false, new AccessCondition(), generateRequestOptions()))
.assertNext(res -> assertIndexesEqual(expected, res))
.verifyComplete();

StepVerifier
.create(client.createOrUpdateIndexWithResponse(index,
false, null, null))
.create(client.createOrUpdateIndexWithResponse(expected.setName("hotel2"),
false, new AccessCondition(), generateRequestOptions()))
.assertNext(res -> Assert.assertEquals(HttpResponseStatus.CREATED.code(), res.getStatusCode()))
.verifyComplete();
}
Expand Down Expand Up @@ -591,16 +636,31 @@ false, generateIfNotChangedAccessCondition(createdResource.getETag()), generateR
@Override
public void canCreateAndGetIndexStats() {
Index testIndex = createTestIndex();
Mono<IndexGetStatisticsResult> indexStatistics = client.createOrUpdateIndex(testIndex)
.flatMap(index -> client.getIndexStatistics(index.getName()));
Index index = client.createOrUpdateIndex(testIndex).block();

StepVerifier
.create(indexStatistics)
.create(client.getIndexStatistics(index.getName()))
.assertNext(stats -> {
Assert.assertEquals(0, stats.getDocumentCount());
Assert.assertEquals(0, stats.getStorageSize());
})
.verifyComplete();

StepVerifier
.create(client.getIndexStatistics(index.getName(), generateRequestOptions()))
.assertNext(stats -> {
Assert.assertEquals(0, stats.getDocumentCount());
Assert.assertEquals(0, stats.getStorageSize());
})
.verifyComplete();

StepVerifier
.create(client.getIndexStatisticsWithResponse(index.getName(), generateRequestOptions()))
.assertNext(stats -> {
Assert.assertEquals(0, stats.getValue().getDocumentCount());
Assert.assertEquals(0, stats.getValue().getStorageSize());
})
.verifyComplete();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ protected void beforeTest() {
public void createIndexReturnsCorrectDefinition() {
Index index = createTestIndex();
Index createdIndex = client.createIndex(index);
assertIndexesEqual(index, createdIndex);

createdIndex = client.createIndex(index.setName("hotel1"), generateRequestOptions());
assertIndexesEqual(index, createdIndex);

Response<Index> createIndexResponse = client.createIndexWithResponse(index.setName("hotel2"), generateRequestOptions(), Context.NONE);
assertIndexesEqual(index, createIndexResponse.getValue());
}

@Override
Expand Down Expand Up @@ -102,8 +107,13 @@ public void getIndexReturnsCorrectDefinition() {
Index index = createTestIndex();
client.createIndex(index);
Index createdIndex = client.getIndex(index.getName());
assertIndexesEqual(index, createdIndex);

createdIndex = client.getIndex(index.getName(), generateRequestOptions());
assertIndexesEqual(index, createdIndex);

Response<Index> getIndexResponse = client.getIndexWithResponse(index.getName(), generateRequestOptions(), Context.NONE);
assertIndexesEqual(index, getIndexResponse.getValue());
}

@Override
Expand All @@ -124,6 +134,8 @@ public void existsReturnsTrueForExistingIndex() {
client.createIndex(index);

Assert.assertTrue(client.indexExists(index.getName()));
Assert.assertTrue(client.indexExists(index.getName(), generateRequestOptions()));
Assert.assertTrue(client.indexExistsWithResponse(index.getName(), generateRequestOptions(), Context.NONE).getValue());
}

@Override
Expand All @@ -146,9 +158,8 @@ public void deleteIndexIfNotChangedWorksOnlyOnCurrentResource() {
}

Response<Void> response = client.deleteIndexWithResponse(index.getName(),
generateIfNotChangedAccessCondition(currentResource.getETag()),
null,
null);
generateIfNotChangedAccessCondition(currentResource.getETag()), generateRequestOptions(), Context.NONE);

Assert.assertEquals(HttpResponseStatus.NO_CONTENT.code(), response.getStatusCode());
}

Expand Down Expand Up @@ -177,17 +188,17 @@ public void deleteIndexIsIdempotent() {
.setType(DataType.EDM_STRING)
.setKey(true)
));
Response<Void> deleteResponse = client.deleteIndexWithResponse(index.getName(), null, null, null);
Response<Void> deleteResponse = client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions(), Context.NONE);
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), deleteResponse.getStatusCode());

Response<Index> createResponse = client.createIndexWithResponse(index, null, null);
Response<Index> createResponse = client.createIndexWithResponse(index, generateRequestOptions(), Context.NONE);
Assert.assertEquals(HttpResponseStatus.CREATED.code(), createResponse.getStatusCode());

// Delete the same index twice
deleteResponse = client.deleteIndexWithResponse(index.getName(), null, null, null);
deleteResponse = client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions(), Context.NONE);
Assert.assertEquals(HttpResponseStatus.NO_CONTENT.code(), deleteResponse.getStatusCode());

deleteResponse = client.deleteIndexWithResponse(index.getName(), null, null, null);
deleteResponse = client.deleteIndexWithResponse(index.getName(), new AccessCondition(), generateRequestOptions(), Context.NONE);
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), deleteResponse.getStatusCode());
}

Expand Down Expand Up @@ -221,9 +232,8 @@ public void canCreateAndListIndexes() {
Assert.assertEquals(index1.getName(), result.get(0).getName());
Assert.assertEquals(index2.getName(), result.get(1).getName());

Context context = new Context("key", "value");
PagedResponse<Index> listResponse = client.listIndexesWithResponse("name",
generateRequestOptions(), context);
generateRequestOptions(), Context.NONE);
result = listResponse.getItems();

Assert.assertEquals(2, result.size());
Expand Down Expand Up @@ -416,14 +426,17 @@ public void createOrUpdateIndexThrowsWhenUpdatingSuggesterWithExistingIndexField

@Override
public void createOrUpdateIndexCreatesWhenIndexDoesNotExist() {
Index index = createTestIndex();
Index expected = createTestIndex();

Response<Index> createOrUpdateResponse = client.createOrUpdateIndexWithResponse(index,
false,
null,
null,
Context.NONE);
Index actual = client.createOrUpdateIndex(expected);
assertIndexesEqual(expected, actual);

actual = client.createOrUpdateIndex(expected.setName("hotel1"),
false, new AccessCondition(), generateRequestOptions());
assertIndexesEqual(expected, actual);

Response<Index> createOrUpdateResponse = client.createOrUpdateIndexWithResponse(expected.setName("hotel2"),
false, new AccessCondition(), generateRequestOptions(), Context.NONE);
Assert.assertEquals(HttpResponseStatus.CREATED.code(), createOrUpdateResponse.getStatusCode());
}

Expand Down Expand Up @@ -516,12 +529,20 @@ public void createOrUpdateIndexIfNotChangedFailsWhenResourceChanged() {
@Override
public void canCreateAndGetIndexStats() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index);
client.createOrUpdateIndex(index);
IndexGetStatisticsResult indexStatistics = client.getIndexStatistics(index.getName());
Assert.assertEquals(0, indexStatistics.getDocumentCount());
Assert.assertEquals(0, indexStatistics.getStorageSize());

indexStatistics = client.getIndexStatistics(index.getName(), generateRequestOptions());
Assert.assertEquals(0, indexStatistics.getDocumentCount());
Assert.assertEquals(0, indexStatistics.getStorageSize());

Response<IndexGetStatisticsResult> indexStatisticsResponse = client.getIndexStatisticsWithResponse(index.getName(),
generateRequestOptions(), Context.NONE);
Assert.assertEquals(0, indexStatisticsResponse.getValue().getDocumentCount());
Assert.assertEquals(0, indexStatisticsResponse.getValue().getStorageSize());


}
}
Loading

0 comments on commit 6cb8d03

Please sign in to comment.