Skip to content

Commit

Permalink
createOrUpdateSynonym map if exists tests (Azure#217)
Browse files Browse the repository at this point in the history
createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource and createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource tests
  • Loading branch information
chenmliu authored Oct 30, 2019
1 parent 3fcb31c commit e569f66
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,33 @@ public void createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource() {

@Override
public void createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap, generateEmptyAccessCondition()).block();
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
Mono<SynonymMap> updatedResource = client.createOrUpdateSynonymMap(mutatedResource, generateIfExistsAccessCondition());

StepVerifier
.create(updatedResource)
.assertNext(res -> {
Assert.assertFalse(res.getETag().isEmpty());
Assert.assertNotEquals(createdResource.getETag(), res.getETag());
})
.verifyComplete();
}

@Override
public void createOrUpdateSynonymMapIfExistsFailsOnNoResource() {
SynonymMap resource = createTestSynonymMap();

StepVerifier
.create(client.createOrUpdateSynonymMap(resource, generateIfExistsAccessCondition()))
.verifyErrorSatisfies(error -> {
Assert.assertEquals(HttpResponseException.class, error.getClass());
Assert.assertEquals(HttpResponseStatus.PRECONDITION_FAILED.code(), ((HttpResponseException) error).getResponse().getStatusCode());
});

// The resource should never have been created on the server, and thus it should not have an ETag
Assert.assertNull(resource.getETag());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,28 @@ public void createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource() {

@Override
public void createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap, generateEmptyAccessCondition());
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
SynonymMap updatedResource = client.createOrUpdateSynonymMap(mutatedResource, generateIfExistsAccessCondition());

Assert.assertFalse(updatedResource.getETag().isEmpty());
Assert.assertNotEquals(createdResource.getETag(), updatedResource.getETag());
}

@Override
public void createOrUpdateSynonymMapIfExistsFailsOnNoResource() {
SynonymMap resource = createTestSynonymMap();

try {
client.createOrUpdateSynonymMap(resource, generateIfExistsAccessCondition());
Assert.fail("createOrUpdateIndex did not throw an expected Exception");
} catch (Exception ex) {
Assert.assertEquals(HttpResponseException.class, ex.getClass());
Assert.assertEquals(HttpResponseStatus.PRECONDITION_FAILED.code(), ((HttpResponseException) ex).getResponse().getStatusCode());
}
// The resource should never have been created on the server, and thus it should not have an ETag
Assert.assertNull(resource.getETag());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public abstract class SynonymMapManagementTestBase extends SearchServiceTestBase
@Test
public abstract void createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource();

@Test
public abstract void createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource();

@Test
public abstract void createOrUpdateSynonymMapIfExistsFailsOnNoResource();

public abstract void createOrUpdateSynonymMapIfNotChangedSucceedsWhenResourceUnchanged();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azs-sdka7c49316cd9c.search.windows.net/synonymmaps('test-synonym')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "991bdb4c-a156-4872-bbb0-f70ca2f90fe2",
"StatusCode" : "412",
"Date" : "Wed, 30 Oct 2019 21:29:38 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "28",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "160",
"Body" : "{\"error\":{\"code\":\"\",\"message\":\"The precondition given in one of the request headers evaluated to false. No change was made to the resource from this request.\"}}",
"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,53 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azs-sdka4f17586afe3.search.windows.net/synonymmaps('test-synonym')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "61b047a9-7106-4055-91fe-a3f52a86c642",
"StatusCode" : "201",
"Date" : "Wed, 30 Oct 2019 21:29:18 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D75D8038BFB80E\"",
"elapsed-time" : "37",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "198",
"Body" : "{\"@odata.context\":\"https://azs-sdka4f17586afe3.search.windows.net/$metadata#synonymmaps/$entity\",\"@odata.etag\":\"\\\"0x8D75D8038BFB80E\\\"\",\"name\":\"test-synonym\",\"format\":\"solr\",\"synonyms\":\"word1,word2\"}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdka4f17586afe3.search.windows.net/synonymmaps('test-synonym')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdka4f17586afe3.search.windows.net/synonymmaps('test-synonym')?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "96e7375f-dc00-4aa9-b948-2b8376d52a77",
"StatusCode" : "200",
"Date" : "Wed, 30 Oct 2019 21:29:18 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D75D8038D7FF5E\"",
"elapsed-time" : "19",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "205",
"Body" : "{\"@odata.context\":\"https://azs-sdka4f17586afe3.search.windows.net/$metadata#synonymmaps/$entity\",\"@odata.etag\":\"\\\"0x8D75D8038D7FF5E\\\"\",\"name\":\"test-synonym\",\"format\":\"solr\",\"synonyms\":\"mutated1, mutated2\"}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit e569f66

Please sign in to comment.