-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mather GetResponseContainOnlyDocumentIdMatcher added so that DNFOF te…
…st still are green after rebase. Signed-off-by: Lukasz Soszynski <[email protected]>
- Loading branch information
1 parent
bfa2fca
commit e40de27
Showing
3 changed files
with
57 additions
and
3 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
51 changes: 51 additions & 0 deletions
51
...t/java/org/opensearch/test/framework/matcher/GetResponseContainOnlyDocumentIdMatcher.java
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,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.test.framework.matcher; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.TypeSafeDiagnosingMatcher; | ||
|
||
import org.opensearch.action.get.GetResponse; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
class GetResponseContainOnlyDocumentIdMatcher extends TypeSafeDiagnosingMatcher<GetResponse> { | ||
|
||
private final String indexName; | ||
private final String documentId; | ||
|
||
public GetResponseContainOnlyDocumentIdMatcher(String indexName, String documentId) { | ||
this.indexName = requireNonNull(indexName, "Index name is required"); | ||
this.documentId = requireNonNull(documentId, "Document id is required"); | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(GetResponse response, Description mismatchDescription) { | ||
if(indexName.equals(response.getIndex()) == false ) { | ||
mismatchDescription.appendText(" index name ").appendValue(response.getIndex()).appendText(" is incorrect "); | ||
return false; | ||
} | ||
if(documentId.equals(response.getId()) == false) { | ||
mismatchDescription.appendText(" id ").appendValue(response.getId()).appendText(" is incorrect "); | ||
return false; | ||
} | ||
if(response.isExists()) { | ||
mismatchDescription.appendText(" document exist what is not desired "); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Response should contain document id from index ").appendValue(indexName).appendText(" with id ") | ||
.appendValue(documentId).appendText(" but document should not be present "); | ||
} | ||
} |
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