Search in sources :

Example 26 with XContentLocation

use of org.opensearch.common.xcontent.XContentLocation in project OpenSearch by opensearch-project.

the class ClientYamlTestSuiteTests method testAddingDoWithWarningWithoutSkipWarnings.

public void testAddingDoWithWarningWithoutSkipWarnings() {
    int lineNumber = between(1, 10000);
    DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
    doSection.setExpectedWarningHeaders(singletonList("foo"));
    doSection.setApiCallSection(new ApiCallSection("test"));
    ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
    Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
    assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [do] with a [warnings] section without a corresponding " + "[\"skip\": \"features\": \"warnings\"] so runners that do not support the [warnings] section can skip the test " + "at line [" + lineNumber + "]"));
}
Also used : XContentLocation(org.opensearch.common.xcontent.XContentLocation) ParsingException(org.opensearch.common.ParsingException)

Example 27 with XContentLocation

use of org.opensearch.common.xcontent.XContentLocation in project OpenSearch by opensearch-project.

the class ClientYamlTestSuiteTests method testAddingContainsWithoutSkipContains.

public void testAddingContainsWithoutSkipContains() {
    int lineNumber = between(1, 10000);
    ContainsAssertion containsAssertion = new ContainsAssertion(new XContentLocation(lineNumber, 0), randomAlphaOfLength(randomIntBetween(3, 30)), randomDouble());
    ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, containsAssertion);
    Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
    assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [contains] assertion without a corresponding " + "[\"skip\": \"features\": \"contains\"] so runners that do not support the [contains] assertion " + "can skip the test at line [" + lineNumber + "]"));
}
Also used : XContentLocation(org.opensearch.common.xcontent.XContentLocation) ParsingException(org.opensearch.common.ParsingException)

Example 28 with XContentLocation

use of org.opensearch.common.xcontent.XContentLocation in project OpenSearch by opensearch-project.

the class MatchAssertionTests method testNullInMap.

public void testNullInMap() {
    XContentLocation xContentLocation = new XContentLocation(0, 0);
    MatchAssertion matchAssertion = new MatchAssertion(xContentLocation, "field", singletonMap("a", null));
    matchAssertion.doAssert(singletonMap("a", null), matchAssertion.getExpectedValue());
    AssertionError e = expectThrows(AssertionError.class, () -> matchAssertion.doAssert(emptyMap(), matchAssertion.getExpectedValue()));
    assertThat(e.getMessage(), containsString("expected [null] but not found"));
}
Also used : XContentLocation(org.opensearch.common.xcontent.XContentLocation)

Aggregations

XContentLocation (org.opensearch.common.xcontent.XContentLocation)28 ParsingException (org.opensearch.common.ParsingException)12 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NamedObjectNotFoundException (org.opensearch.common.xcontent.NamedObjectNotFoundException)2 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)2 SearchParseException (org.opensearch.search.SearchParseException)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Matcher (java.util.regex.Matcher)1 ByteArrayStreamOutput (org.codelibs.fesen.client.io.stream.ByteArrayStreamOutput)1 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)1 ShardSearchFailure (org.opensearch.action.search.ShardSearchFailure)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1 Tuple (org.opensearch.common.collect.Tuple)1 ToXContentObject (org.opensearch.common.xcontent.ToXContentObject)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1