Skip to content

Commit

Permalink
datasourceExists() implementation and tests (Azure#258)
Browse files Browse the repository at this point in the history
Adding implementation and tests of datasourceExists()
  • Loading branch information
rabee333 authored Nov 14, 2019
1 parent d6d6869 commit b7b4ab9
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,48 @@ Mono<Response<Void>> deleteDataSourceWithResponse(String dataSourceName,
context).map(Function.identity());
}


/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @return true if the datasource exists; false otherwise.
*/
public Mono<Boolean> datasourceExists(String datasourceName) {
return this.datasourceExistsWithResponse(datasourceName, null).map(Response::getValue);
}

/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return true if the datasource exists; false otherwise.
*/
public Mono<Boolean> datasourceExists(String datasourceName, RequestOptions requestOptions) {
return this.datasourceExistsWithResponse(datasourceName, requestOptions).map(Response::getValue);
}

/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return true if the datasource exists; false otherwise.
*/
public Mono<Response<Boolean>> datasourceExistsWithResponse(String datasourceName, RequestOptions requestOptions) {
return withContext(context -> this.datasourceExistsWithResponse(datasourceName, requestOptions, context));
}

Mono<Response<Boolean>> datasourceExistsWithResponse(String datasourceName,
RequestOptions requestOptions,
Context context) {
return resourceExistsWithResponse(() ->
this.getDataSourceWithResponse(datasourceName, requestOptions, context));
}

/**
* Creates a new Azure Search indexer or updates an indexer if it already exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,45 @@ public Response<Void> deleteDataSourceWithResponse(String dataSourceName,
accessCondition, requestOptions, context).block();
}

/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @return true if the datasource exists; false otherwise.
*/
public Boolean datasourceExists(String datasourceName) {
return asyncClient.datasourceExists(datasourceName).block();
}

/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return true if the datasource exists; false otherwise.
*/
public Boolean datasourceExists(String datasourceName, RequestOptions requestOptions) {
return asyncClient.datasourceExists(datasourceName, requestOptions).block();
}

/**
* Determines whether or not the given datasource exists.
*
* @param datasourceName the name of the datasource
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return true if the datasource exists; false otherwise.
*/
public Response<Boolean> datasourceExistsWithResponse(String datasourceName,
RequestOptions requestOptions,
Context context) {
return asyncClient
.datasourceExistsWithResponse(datasourceName, requestOptions, context)
.block();
}

/**
* @return the created Indexer.
* @throws NotImplementedException not implemented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ public void updateDataSourceIfNotChangedSucceedsWhenResourceUnchanged() {
});
}

@Override
public void existsReturnsFalseForNonExistingDatasource() {
StepVerifier
.create(client.datasourceExists("inExistentDataSourceName"))
.assertNext(Assert::assertFalse)
.verifyComplete();
}

@Override
public void existsReturnsTrueForExistingDatasource() {
DataSource dataSource = createTestDataSource();
client.createOrUpdateDataSource(dataSource).block();

StepVerifier
.create(client.datasourceExists(dataSource.getName()))
.assertNext(Assert::assertTrue)
.verifyComplete();
}

@Override
public void createDataSourceFailsWithUsefulMessageOnUserError() {
DataSource dataSource = createTestSqlDataSource(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ public void updateDataSourceIfNotChangedSucceedsWhenResourceUnchanged() {
Assert.assertNotEquals(createdETag, updatedDataSource.getETag());
}

@Override
public void existsReturnsFalseForNonExistingDatasource() {
Assert.assertFalse(client.datasourceExists("inExistentDataSourceName"));
}

@Override
public void existsReturnsTrueForExistingDatasource() {
DataSource dataSource = createTestDataSource();
client.createOrUpdateDataSource(dataSource);

Assert.assertTrue(client.datasourceExists(dataSource.getName()));
}

@Override
public void createDataSourceReturnsCorrectDefinition() {
SoftDeleteColumnDeletionDetectionPolicy deletionDetectionPolicy =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ protected void beforeTest() {
@Test
public abstract void updateDataSourceIfNotChangedSucceedsWhenResourceUnchanged();

@Test
public abstract void existsReturnsFalseForNonExistingDatasource();

@Test
public abstract void existsReturnsTrueForExistingDatasource();

@Test
public void canUpdateConnectionData() {
// Note: since connection string is not returned when queried from the service, actually saving the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"networkCallRecords" : [ {
"Method" : "GET",
"Uri" : "https://azs-sdk04a58790fc78.search.windows.net/datasources('inExistentDataSourceName')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "d14df4eb-219d-4345-b735-f32438ddf446",
"StatusCode" : "404",
"Date" : "Wed, 13 Nov 2019 15:09:18 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "50",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "133",
"Body" : "{\"error\":{\"code\":\"\",\"message\":\"No data source with the name 'inExistentDataSourceName' was found in service 'azs-sdk04a58790fc78'.\"}}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Language" : "en",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azs-sdk77f119396ba3.search.windows.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" : "2614d0c0-9103-479d-8099-473200f761d8",
"StatusCode" : "201",
"Date" : "Wed, 13 Nov 2019 10:07:25 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D7682148C4E1B5\"",
"elapsed-time" : "80",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "383",
"Body" : "{\"@odata.context\":\"https://azs-sdk77f119396ba3.search.windows.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D7682148C4E1B5\\\"\",\"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-sdk77f119396ba3.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://azs-sdk77f119396ba3.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "4700d870-fc1f-419a-84d5-59c1925c5b6b",
"StatusCode" : "200",
"Date" : "Wed, 13 Nov 2019 10:07:25 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D7682148C4E1B5\"",
"elapsed-time" : "52",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "383",
"Body" : "{\"@odata.context\":\"https://azs-sdk77f119396ba3.search.windows.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D7682148C4E1B5\\\"\",\"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"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit b7b4ab9

Please sign in to comment.