From 64c854230497fa97a2d639a0c01053509308091b Mon Sep 17 00:00:00 2001 From: LizaShak Date: Sun, 18 Aug 2019 17:08:00 +0300 Subject: [PATCH] fix checkstyle and json recordings --- .../common/DocumentResponseConversions.java | 3 +- .../SearchIndexAsyncClientImplTest.java | 21 +-------- .../canGetDynamicDocument.json | 44 +++++++++++++++++- ...tDocumentThrowsWhenRequestIsMalformed.json | 45 ++++++++++++++++++- 4 files changed, 90 insertions(+), 23 deletions(-) diff --git a/search/data-plane/data/src/main/java/com/azure/search/data/common/DocumentResponseConversions.java b/search/data-plane/data/src/main/java/com/azure/search/data/common/DocumentResponseConversions.java index 7e97b7d1213d8..fb144941b4985 100644 --- a/search/data-plane/data/src/main/java/com/azure/search/data/common/DocumentResponseConversions.java +++ b/search/data-plane/data/src/main/java/com/azure/search/data/common/DocumentResponseConversions.java @@ -74,8 +74,7 @@ private static ArrayList convertArray(ArrayList array) { for (Object arrayValue : array) { if (arrayValue instanceof LinkedHashMap) { convertedArray.add(convertLinkedHashMapToMap(arrayValue)); - } - else { + } else { convertedArray.add(arrayValue); } } diff --git a/search/data-plane/data/src/test/java/com/azure/search/data/test/customization/SearchIndexAsyncClientImplTest.java b/search/data-plane/data/src/test/java/com/azure/search/data/test/customization/SearchIndexAsyncClientImplTest.java index 2a5a087ff319d..3a3d9e5476352 100644 --- a/search/data-plane/data/src/test/java/com/azure/search/data/test/customization/SearchIndexAsyncClientImplTest.java +++ b/search/data-plane/data/src/test/java/com/azure/search/data/test/customization/SearchIndexAsyncClientImplTest.java @@ -5,20 +5,13 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.exception.ResourceNotFoundException; import com.azure.search.data.SearchIndexAsyncClient; -import com.azure.search.data.generated.models.IndexAction; -import com.azure.search.data.generated.models.IndexActionType; -import com.azure.search.data.generated.models.IndexBatch; import io.netty.handler.codec.http.HttpResponseStatus; import org.junit.Assert; import org.junit.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; - -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -36,16 +29,6 @@ protected void beforeTest() { asyncClient = builderSetup().indexName(INDEX_NAME).buildAsyncClient(); } - private void uploadDocument(HashMap object) throws IOException { - List indexActions = new LinkedList<>(); - indexActions.add(new IndexAction() - .actionType(IndexActionType.UPLOAD) - .additionalProperties(object)); - - asyncClient.index( - new IndexBatch().actions(indexActions)).block(); - } - @Test public void canGetDynamicDocument() { @@ -109,7 +92,7 @@ public void canGetDynamicDocument() { //TODO: Support GeoTypes try { - uploadDocument(expectedDoc); + super.indexDocument(asyncClient, expectedDoc); } catch (Exception e) { e.printStackTrace(); @@ -146,7 +129,7 @@ public void getDocumentThrowsWhenRequestIsMalformed() { selectedFields.add("ThisFieldDoesNotExist"); try { - uploadDocument(hotelDoc); + super.indexDocument(asyncClient, hotelDoc); } catch (Exception e) { e.printStackTrace(); diff --git a/search/data-plane/data/src/test/resources/session-records/canGetDynamicDocument.json b/search/data-plane/data/src/test/resources/session-records/canGetDynamicDocument.json index ba5f37f8f8555..631a4649bdd5a 100644 --- a/search/data-plane/data/src/test/resources/session-records/canGetDynamicDocument.json +++ b/search/data-plane/data/src/test/resources/session-records/canGetDynamicDocument.json @@ -1,4 +1,46 @@ { - "networkCallRecords" : [ ], + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk29d07193466e.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" : "85bc3b63-4d17-4a3a-8f79-15f0fe4bde20", + "StatusCode" : "200", + "Date" : "Sun, 18 Aug 2019 13:55:02 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "155", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "227", + "Body" : "{\"@odata.context\":\"https://azs-sdk29d07193466e.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"1\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "GET", + "Uri" : "https://azs-sdk29d07193466e.search.windows.net/indexes('hotels')/docs('1')?api-version=2019-05-06", + "Headers" : { }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "5fedd590-bfc8-499f-9530-f4acfd7fd508", + "StatusCode" : "200", + "Date" : "Sun, 18 Aug 2019 13:55:02 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "17", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "1672", + "Body" : "{\"@odata.context\":\"https://azs-sdk29d07193466e.search.windows.net/indexes('hotels')/$metadata#docs(*)/$entity\",\"HotelId\":\"1\",\"HotelName\":\"Secret Point Motel\",\"Description\":\"The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.\",\"Description_fr\":\"L'h\\u00f4tel est id\\u00e9alement situ\\u00e9 sur la principale art\\u00e8re commerciale de la ville en plein c\\u0153ur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'int\\u00e9r\\u00eat qui font de New York l'une des villes les plus attractives et cosmopolites de l'Am\\u00e9rique.\",\"Category\":\"Boutique\",\"Tags\":[\"pool\",\"air conditioning\",\"concierge\"],\"ParkingIncluded\":false,\"SmokingAllowed\":true,\"LastRenovationDate\":\"1970-01-18T00:00:00Z\",\"Rating\":3,\"Location\":null,\"Address\":{\"StreetAddress\":\"677 5th Ave\",\"City\":\"New York\",\"StateProvince\":\"NY\",\"PostalCode\":\"10022\",\"Country\":\"USA\"},\"Rooms\":[{\"Description\":\"Budget Room, 1 Queen Bed (Cityside)\",\"Description_fr\":\"Chambre \\u00c9conomique, 1 grand lit (c\\u00f4t\\u00e9 ville)\",\"Type\":\"Budget Room\",\"BaseRate\":9.69,\"BedOptions\":\"1 Queen Bed\",\"SleepsCount\":2,\"SmokingAllowed\":true,\"Tags\":[\"vcr/dvd\"]},{\"Description\":\"Budget Room, 1 King Bed (Mountain View)\",\"Description_fr\":\"Chambre \\u00c9conomique, 1 tr\\u00e8s grand lit (Mountain View)\",\"Type\":\"Budget Room\",\"BaseRate\":8.09,\"BedOptions\":\"1 King Bed\",\"SleepsCount\":2,\"SmokingAllowed\":true,\"Tags\":[\"vcr/dvd\",\"jacuzzi tub\"]}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], "variables" : [ ] } \ No newline at end of file diff --git a/search/data-plane/data/src/test/resources/session-records/getDocumentThrowsWhenRequestIsMalformed.json b/search/data-plane/data/src/test/resources/session-records/getDocumentThrowsWhenRequestIsMalformed.json index ba5f37f8f8555..ca3e4b9bf3c22 100644 --- a/search/data-plane/data/src/test/resources/session-records/getDocumentThrowsWhenRequestIsMalformed.json +++ b/search/data-plane/data/src/test/resources/session-records/getDocumentThrowsWhenRequestIsMalformed.json @@ -1,4 +1,47 @@ { - "networkCallRecords" : [ ], + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk5ec62844b14d.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" : "34dbd47a-664f-4d56-8e5b-d074af0fec81", + "StatusCode" : "200", + "Date" : "Sun, 18 Aug 2019 14:03:56 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "190", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "227", + "Body" : "{\"@odata.context\":\"https://azs-sdk5ec62844b14d.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"2\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "GET", + "Uri" : "https://azs-sdk5ec62844b14d.search.windows.net/indexes('hotels')/docs('2')?$select=HotelId%2cThisFieldDoesNotExist&api-version=2019-05-06", + "Headers" : { }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "eccce0dc-ce1e-4e7d-8c7e-2a7ee26ad3d7", + "StatusCode" : "400", + "Date" : "Sun, 18 Aug 2019 14:03:56 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "7", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "163", + "Body" : "{\"error\":{\"code\":\"\",\"message\":\"Invalid expression: Could not find a property named 'ThisFieldDoesNotExist' on type 'search.document'.\\r\\nParameter name: $select\"}}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Language" : "en", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], "variables" : [ ] } \ No newline at end of file