Skip to content

Commit

Permalink
Create IndexClient from ServiceClient UT (Azure#232)
Browse files Browse the repository at this point in the history
* SearchClient generate IndexClient UT

* codestyle fix
  • Loading branch information
navalev authored Nov 7, 2019
1 parent f385821 commit 7df18a0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import org.junit.Assert;
import org.junit.Test;

public class SearchServiceSubclientTests {
public class SearchServiceSubClientTests extends SearchServiceTestBase {


@Test
public void canGetIndexClientFromSearchClient() {
SearchServiceClient serviceClient = new SearchServiceClientBuilder()
.endpoint("https://test1.search.windows.net")
.credential(new ApiKeyCredentials("api-key"))
.buildClient();
SearchServiceClient serviceClient = getSearchService();

SearchIndexClient indexClient = serviceClient.getIndexClient("hotels");

Expand All @@ -36,10 +34,8 @@ public void canGetIndexClientFromSearchClient() {

@Test
public void canGetIndexAsyncClientFromSearchClient() {
SearchServiceAsyncClient serviceClient = new SearchServiceClientBuilder()
.endpoint("https://test1.search.windows.net")
.credential(new ApiKeyCredentials("api-key"))
.buildAsyncClient();
SearchServiceAsyncClient serviceClient = getAsyncSearchService();

SearchIndexAsyncClient indexClient = serviceClient.getIndexClient("hotels");

// Validate the client was created
Expand All @@ -58,4 +54,48 @@ public void canGetIndexAsyncClientFromSearchClient() {
// Validate that the client uses the specified index
Assert.assertEquals("hotels", indexClient.getIndexName());
}

@Test
public void canGetIndexClientAfterUsingServiceClient() {
SearchServiceClient serviceClient = getSearchService();
try {
// this is expected to fail
serviceClient.deleteIndex("thisindexdoesnotexist");
} catch (Exception e) {
// deleting the index should fail as it does not exist
}

// This should not fail
SearchIndexClient indexClient = serviceClient.getIndexClient("hotels");
Assert.assertEquals("hotels", indexClient.getIndexName());
}

@Test
public void canGetIndexAsyncClientAfterUsingServiceClient() {
SearchServiceAsyncClient serviceClient = getAsyncSearchService();
try {
// this is expected to fail
serviceClient.deleteIndex("thisindexdoesnotexist");
} catch (Exception e) {
// deleting the index should fail as it does not exist
}

// This should not fail
SearchIndexAsyncClient indexClient = serviceClient.getIndexClient("hotels");
Assert.assertEquals("hotels", indexClient.getIndexName());
}

private SearchServiceClient getSearchService() {
return new SearchServiceClientBuilder()
.endpoint("https://test1.search.windows.net")
.credential(new ApiKeyCredentials("api-key"))
.buildClient();
}

private SearchServiceAsyncClient getAsyncSearchService() {
return new SearchServiceClientBuilder()
.endpoint("https://test1.search.windows.net")
.credential(new ApiKeyCredentials("api-key"))
.buildAsyncClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"networkCallRecords" : [ ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"networkCallRecords" : [ ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"networkCallRecords" : [ ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"networkCallRecords" : [ ],
"variables" : [ ]
}

0 comments on commit 7df18a0

Please sign in to comment.