forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/search-with-result-count
- Loading branch information
Showing
6 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Test Framework | ||
|
||
This SDK uses the TestBase core class to record and playback http sessions, to perform integration tests with Search service in Azure. | ||
|
||
## Usage | ||
|
||
The class: **SearchIndexClientTestBase** is the base test class which other test classes, that need to perform integration tests, must extend it. | ||
|
||
These test classes then can use the base client builder, and run the relevant build method. | ||
|
||
### Code example | ||
|
||
```$java | ||
public class SyncTests extends SearchIndexClientTestBase { | ||
private SearchIndexClient asyncClient; | ||
@Override | ||
void beforeTest() { | ||
super.beforeTest(); | ||
asyncClient = builderSetup().indexName("IndexName").buildAsyncClient(); | ||
} | ||
@Test | ||
public void indexResultSucceeds() throws Exception { | ||
// initialize indexActions | ||
DocumentIndexResult result = asyncClient.index(new IndexBatch().actions(indexActions)).block(); | ||
assert result.results().get(0).statusCode() == 200; | ||
} | ||
} | ||
``` | ||
|
||
Before running the tests on PLAYBACK mode, you need to run them on RECORD mode to record the http sessions. | ||
|
||
### Recording http sessions: | ||
|
||
1. Add the following environment variables to your development SDK to be used in JUnit runs: | ||
* AZURE_SERVICE_PRINCIPAL_APP_ID: *The Service Principal application ID* | ||
* AZURE_SERVICE_PRINCIPAL_APP_SECRET: *Service Principal Secret* | ||
* AZURE_DOMAIN_ID: *Azure domain ID* | ||
* AZURE_SUBSCRIPTION_ID: *Azure subscription ID* | ||
* AZURE_TEST_MODE: **RECORD** *for recording* (**PLAYBACK** *for playback mode*) | ||
* INDEX_FILE_NAME: *The json filename where the index configuration is stored (in the resources folder)* | ||
|
||
2. Run the tests. | ||
|
||
> Please note: In RECORD mode, every test is creating a new testing environment in Azure before the test, and deleting it after the test. This process takes some time, so the tests in this mode (RECORD) are slower. | ||
3. After test runs finish, you can find the recorded sessions under the project's target folder: | ||
|
||
`target/test-classes/session-records` | ||
|
||
Every test will have its own session file. | ||
|
||
4. Copy the records to the project's test resources folder: | ||
|
||
`test/resources/session-records` | ||
|
||
> The session files should also be submitted to the project's repository, so the tests in the CI build will use them in playback mode. | ||
### Running tests in PLAYBACK mode | ||
|
||
To run tests in Playback mode: | ||
|
||
1. Set the value of the **AZURE_TEST_MODE** environment variable to *'RECORD'* (or delete it). You can also delete all other environment variables. | ||
2. Run the tests. | ||
|
||
## Example of creating test environment in Azure | ||
|
||
You can find an example of preparing a test environment in Azure here: | ||
|
||
`/test/java/com/azure/search/data/env/samples/CreateTestResources.java` | ||
|
||
This example creates a Resource Group and Search Service in Azure, creates a new index and uploads documents to it. | ||
|
||
This is for self testing purposes, and shows the usage of the Azure client and Search Service client. | ||
|
||
> This is the same process during the Search Tests in RECORDING mode, that creates the test environment before every test, and cleans it after the test ends. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../azure-search-data/src/test/resources/session-records/testCanSearchWithSearchModeAll.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"networkCallRecords" : [ { | ||
"Method" : "POST", | ||
"Uri" : "https://azs-sdk2dd3609540a3.search.windows.net/indexes('hotels')/docs/search.index?api-version=2019-05-06", | ||
"Headers" : { | ||
"Content-Type" : "application/json; charset=utf-8" | ||
}, | ||
"Response" : { | ||
"Pragma" : "no-cache", | ||
"retry-after" : "0", | ||
"request-id" : "4569dce8-0dbc-4378-ab47-a1609e8b0e41", | ||
"StatusCode" : "200", | ||
"Date" : "Wed, 21 Aug 2019 13:31:27 GMT", | ||
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains", | ||
"Cache-Control" : "no-cache", | ||
"elapsed-time" : "204", | ||
"OData-Version" : "4.0", | ||
"Expires" : "-1", | ||
"Content-Length" : "795", | ||
"Body" : "{\"@odata.context\":\"https://azs-sdk2dd3609540a3.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"1\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"2\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"3\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"4\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"5\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"6\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"7\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"8\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"9\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"10\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}", | ||
"Preference-Applied" : "odata.include-annotations=\"*\"", | ||
"Content-Type" : "application/json; odata.metadata=minimal" | ||
} | ||
}, { | ||
"Method" : "POST", | ||
"Uri" : "https://azs-sdk2dd3609540a3.search.windows.net/indexes('hotels')/docs/search.post.search?api-version=2019-05-06", | ||
"Headers" : { | ||
"Content-Type" : "application/json; charset=utf-8" | ||
}, | ||
"Response" : { | ||
"Pragma" : "no-cache", | ||
"retry-after" : "0", | ||
"request-id" : "663a4c7c-e95b-46fd-be77-95b4721dac58", | ||
"StatusCode" : "200", | ||
"Date" : "Wed, 21 Aug 2019 13:31:29 GMT", | ||
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains", | ||
"Cache-Control" : "no-cache", | ||
"elapsed-time" : "32", | ||
"OData-Version" : "4.0", | ||
"Expires" : "-1", | ||
"Content-Length" : "605", | ||
"Body" : "{\"@odata.context\":\"https://azs-sdk2dd3609540a3.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.score\":0.29120865,\"HotelId\":\"2\",\"HotelName\":\"Roach Motel\",\"Description\":\"Cheapest hotel in town. Infact, a motel.\",\"Description_fr\":\"H\\u00f4tel le moins cher en ville. Infact, un motel.\",\"Category\":\"Budget\",\"Tags\":[\"motel\",\"budget\"],\"ParkingIncluded\":true,\"SmokingAllowed\":true,\"LastRenovationDate\":\"1982-04-28T00:00:00Z\",\"Rating\":1,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,49.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]}]}", | ||
"Preference-Applied" : "odata.include-annotations=\"*\"", | ||
"Content-Type" : "application/json; odata.metadata=minimal" | ||
} | ||
} ], | ||
"variables" : [ ] | ||
} |
Oops, something went wrong.