Skip to content

Commit

Permalink
createOrUpdateSynonym map if not changed tests (Azure#218)
Browse files Browse the repository at this point in the history
createOrUpdateSynonymMapIfNotChangedSucceedsWhenResourceUnchanged and createOrUpdateSynonymMapIfNotChangedFailsWhenResourceChanged tests
  • Loading branch information
chenmliu authored Oct 31, 2019
1 parent 1492bbd commit 6f1b3ba
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void createOrUpdateIndexCreatesWhenIndexDoesNotExist() {
@Override
public void createOrUpdateIndexIfNotExistsFailsOnExistingResource() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition()).block();
Index createdResource = client.createOrUpdateIndex(index).block();
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);

StepVerifier
Expand All @@ -488,7 +488,7 @@ public void createOrUpdateIndexIfNotExistsSucceedsOnNoResource() {
@Override
public void createOrUpdateIndexIfExistsSucceedsOnExistingResource() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition()).block();
Index createdResource = client.createOrUpdateIndex(index).block();
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Mono<Index> updatedResource = client.createOrUpdateIndex(mutatedResource, generateIfExistsAccessCondition());

Expand Down Expand Up @@ -519,7 +519,7 @@ public void createOrUpdateIndexIfExistsFailsOnNoResource() {
@Override
public void createOrUpdateIndexIfNotChangedSucceedsWhenResourceUnchanged() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition()).block();
Index createdResource = client.createOrUpdateIndex(index).block();
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Mono<Index> updatedResource = client.createOrUpdateIndex(mutatedResource, generateIfMatchAccessCondition(createdResource.getETag()));

Expand All @@ -536,9 +536,9 @@ public void createOrUpdateIndexIfNotChangedSucceedsWhenResourceUnchanged() {
@Override
public void createOrUpdateIndexIfNotChangedFailsWhenResourceChanged() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition()).block();
Index createdResource = client.createOrUpdateIndex(index).block();
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Index updatedResource = client.createOrUpdateIndex(mutatedResource, generateEmptyAccessCondition()).block();
Index updatedResource = client.createOrUpdateIndex(mutatedResource).block();

StepVerifier
.create(client.createOrUpdateIndex(updatedResource, generateIfMatchAccessCondition(createdResource.getETag())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void createOrUpdateIndexCreatesWhenIndexDoesNotExist() {
@Override
public void createOrUpdateIndexIfNotExistsFailsOnExistingResource() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition());
Index createdResource = client.createOrUpdateIndex(index);
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);

try {
Expand All @@ -427,7 +427,7 @@ public void createOrUpdateIndexIfNotExistsSucceedsOnNoResource() {
@Override
public void createOrUpdateIndexIfExistsSucceedsOnExistingResource() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition());
Index createdResource = client.createOrUpdateIndex(index);
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Index updatedResource = client.createOrUpdateIndex(mutatedResource, generateIfExistsAccessCondition());

Expand All @@ -453,7 +453,7 @@ public void createOrUpdateIndexIfExistsFailsOnNoResource() {
@Override
public void createOrUpdateIndexIfNotChangedSucceedsWhenResourceUnchanged() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition());
Index createdResource = client.createOrUpdateIndex(index);
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Index updatedResource = client.createOrUpdateIndex(mutatedResource, generateIfMatchAccessCondition(createdResource.getETag()));

Expand All @@ -465,9 +465,9 @@ public void createOrUpdateIndexIfNotChangedSucceedsWhenResourceUnchanged() {
@Override
public void createOrUpdateIndexIfNotChangedFailsWhenResourceChanged() {
Index index = createTestIndex();
Index createdResource = client.createOrUpdateIndex(index, generateEmptyAccessCondition());
Index createdResource = client.createOrUpdateIndex(index);
Index mutatedResource = mutateCorsOptionsInIndex(createdResource);
Index updatedResource = client.createOrUpdateIndex(mutatedResource, generateEmptyAccessCondition());
Index updatedResource = client.createOrUpdateIndex(mutatedResource);

try {
client.createOrUpdateIndex(updatedResource, generateIfMatchAccessCondition(createdResource.getETag()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,4 @@ protected AccessCondition generateIfExistsAccessCondition() {
// Setting this access condition modifies the request to include the HTTP If-Match conditional header set to "*"
return new AccessCondition().setIfMatch("*");
}

/**
* Constructs an empty access condition.
* @return an empty AccessCondition object
*/
protected AccessCondition generateEmptyAccessCondition() {
return new AccessCondition();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,59 @@ public void createOrUpdateSynonymMapCreatesWhenSynonymMapDoesNotExist() {
@Override
public void createOrUpdateSynonymMapIfNotExistsFailsOnExistingResource() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap, generateEmptyAccessCondition()).block();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap).block();
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
RequestOptions requestOptions = new RequestOptions()
.setClientRequestId(UUID.randomUUID());

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

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

StepVerifier
.create(client.createOrUpdateSynonymMapWithResponse(mutatedResource, generateIfNotExistsAccessCondition(), requestOptions))
.verifyErrorSatisfies(error -> {
Assert.assertEquals(HttpResponseException.class, error.getClass());
Assert.assertEquals(HttpResponseStatus.PRECONDITION_FAILED.code(), ((HttpResponseException) error).getResponse().getStatusCode());
});
}

@Override
public void createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource() {
SynonymMap resource = createTestSynonymMap();
Mono<SynonymMap> updatedResource = client.createOrUpdateSynonymMap(resource, generateIfNotExistsAccessCondition());
RequestOptions requestOptions = new RequestOptions()
.setClientRequestId(UUID.randomUUID());

StepVerifier
.create(updatedResource)
.create(client.createOrUpdateSynonymMap(resource, generateIfNotExistsAccessCondition()))
.assertNext(res -> Assert.assertFalse(res.getETag().isEmpty()))
.verifyComplete();

StepVerifier
.create(client.createOrUpdateSynonymMap(resource.setName("test-synonym1"), generateIfNotExistsAccessCondition(), requestOptions))
.assertNext(res -> Assert.assertFalse(res.getETag().isEmpty()))
.verifyComplete();

StepVerifier
.create(client.createOrUpdateSynonymMapWithResponse(resource.setName("test-synonym2"), generateIfNotExistsAccessCondition(), requestOptions))
.assertNext(res -> Assert.assertFalse(res.getValue().getETag().isEmpty()))
.verifyComplete();
}

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

Expand Down Expand Up @@ -204,12 +231,37 @@ public void createOrUpdateSynonymMapIfExistsFailsOnNoResource() {

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

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

@Override
public void createOrUpdateSynonymMapIfNotChangedFailsWhenResourceChanged() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap).block();
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
SynonymMap updatedResource = client.createOrUpdateSynonymMap(mutatedResource).block();

StepVerifier
.create(client.createOrUpdateSynonymMap(updatedResource, generateIfMatchAccessCondition(createdResource.getETag())))
.verifyErrorSatisfies(error -> {
Assert.assertEquals(HttpResponseException.class, error.getClass());
Assert.assertEquals(HttpResponseStatus.PRECONDITION_FAILED.code(), ((HttpResponseException) error).getResponse().getStatusCode());
});
Assert.assertFalse(createdResource.getETag().isEmpty());
Assert.assertFalse(updatedResource.getETag().isEmpty());
Assert.assertNotEquals(createdResource.getETag(), updatedResource.getETag());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,39 @@ public void createOrUpdateSynonymMapCreatesWhenSynonymMapDoesNotExist() {
@Override
public void createOrUpdateSynonymMapIfNotExistsFailsOnExistingResource() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap, generateEmptyAccessCondition());
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap);
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
RequestOptions requestOptions = new RequestOptions()
.setClientRequestId(UUID.randomUUID());
Context context = new Context("key", "value");

try {
client.createOrUpdateSynonymMap(mutatedResource, generateIfNotExistsAccessCondition());
Assert.fail("createOrUpdateIndex did not throw an expected Exception");
Assert.fail("createOrUpdateSynonymMap 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());
}

try {
client.createOrUpdateSynonymMap(mutatedResource, generateIfNotExistsAccessCondition(), requestOptions);
Assert.fail("createOrUpdateSynonymMap 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());
}

try {
client.createOrUpdateSynonymMap(mutatedResource, generateIfNotExistsAccessCondition(), requestOptions, context);
Assert.fail("createOrUpdateSynonymMap 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());
}

try {
client.createOrUpdateSynonymMapWithResponse(mutatedResource, generateIfNotExistsAccessCondition(), requestOptions, context);
Assert.fail("createOrUpdateSynonymMap 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());
Expand All @@ -137,15 +164,29 @@ public void createOrUpdateSynonymMapIfNotExistsFailsOnExistingResource() {
@Override
public void createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource() {
SynonymMap resource = createTestSynonymMap();
RequestOptions requestOptions = new RequestOptions()
.setClientRequestId(UUID.randomUUID());
Context context = new Context("key", "value");

SynonymMap updatedResource = client.createOrUpdateSynonymMap(resource, generateIfNotExistsAccessCondition());
Assert.assertFalse(updatedResource.getETag().isEmpty());

updatedResource = client.createOrUpdateSynonymMap(resource.setName("test-synonym1"),
generateIfNotExistsAccessCondition(),
requestOptions);
Assert.assertFalse(updatedResource.getETag().isEmpty());

Response<SynonymMap> updatedResponse = client.createOrUpdateSynonymMapWithResponse(resource.setName("test-synonym2"),
generateIfNotExistsAccessCondition(),
requestOptions,
context);
Assert.assertFalse(updatedResponse.getValue().getETag().isEmpty());
}

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

Expand All @@ -159,7 +200,7 @@ public void createOrUpdateSynonymMapIfExistsFailsOnNoResource() {

try {
client.createOrUpdateSynonymMap(resource, generateIfExistsAccessCondition());
Assert.fail("createOrUpdateIndex did not throw an expected Exception");
Assert.fail("createOrUpdateSynonymMap 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());
Expand All @@ -170,12 +211,33 @@ public void createOrUpdateSynonymMapIfExistsFailsOnNoResource() {

@Override
public void createOrUpdateSynonymMapIfNotChangedSucceedsWhenResourceUnchanged() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap);
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
SynonymMap updatedResource = client.createOrUpdateSynonymMap(mutatedResource, generateIfMatchAccessCondition(createdResource.getETag()));

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

@Override
public void createOrUpdateSynonymMapIfNotChangedFailsWhenResourceChanged() {
SynonymMap synonymMap = createTestSynonymMap();
SynonymMap createdResource = client.createOrUpdateSynonymMap(synonymMap);
SynonymMap mutatedResource = mutateSynonymsInSynonymMap(createdResource);
SynonymMap updatedResource = client.createOrUpdateSynonymMap(mutatedResource);

try {
client.createOrUpdateSynonymMap(updatedResource, generateIfMatchAccessCondition(createdResource.getETag()));
Assert.fail("createOrUpdateSynonymMap 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());
}
Assert.assertFalse(createdResource.getETag().isEmpty());
Assert.assertFalse(updatedResource.getETag().isEmpty());
Assert.assertNotEquals(createdResource.getETag(), updatedResource.getETag());
}

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

@Test
public abstract void createOrUpdateSynonymMapIfNotChangedSucceedsWhenResourceUnchanged();

@Test
public abstract void createOrUpdateSynonymMapIfNotChangedFailsWhenResourceChanged();

public abstract void deleteSynonymMapIfNotChangedWorksOnlyOnCurrentResource();
Expand Down
Loading

0 comments on commit 6f1b3ba

Please sign in to comment.