Search in sources :

Example 11 with NamedXContentRegistry

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

the class HighlightBuilderTests method init.

/**
 * setup for the whole base test class
 */
@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Example 12 with NamedXContentRegistry

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

the class CollapseBuilderTests method init.

@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Example 13 with NamedXContentRegistry

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

the class OpenSearchClientYamlSuiteTestCase method createParameters.

/**
 * Create parameters for this parameterized test.
 */
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception {
    // default to all tests under the test root
    String[] paths = resolvePathsProperty(REST_TESTS_SUITE, "");
    Map<String, Set<Path>> yamlSuites = loadSuites(paths);
    List<ClientYamlTestSuite> suites = new ArrayList<>();
    IllegalArgumentException validationException = null;
    // yaml suites are grouped by directory (effectively by api)
    for (String api : yamlSuites.keySet()) {
        List<Path> yamlFiles = new ArrayList<>(yamlSuites.get(api));
        for (Path yamlFile : yamlFiles) {
            ClientYamlTestSuite suite = ClientYamlTestSuite.parse(executeableSectionRegistry, api, yamlFile);
            suites.add(suite);
            try {
                suite.validate();
            } catch (IllegalArgumentException e) {
                if (validationException == null) {
                    validationException = new IllegalArgumentException("Validation errors for the following test suites:\n- " + e.getMessage());
                } else {
                    String previousMessage = validationException.getMessage();
                    Throwable[] suppressed = validationException.getSuppressed();
                    validationException = new IllegalArgumentException(previousMessage + "\n- " + e.getMessage());
                    for (Throwable t : suppressed) {
                        validationException.addSuppressed(t);
                    }
                }
                validationException.addSuppressed(e);
            }
        }
    }
    if (validationException != null) {
        throw validationException;
    }
    List<Object[]> tests = new ArrayList<>();
    for (ClientYamlTestSuite yamlTestSuite : suites) {
        for (ClientYamlTestSection testSection : yamlTestSuite.getTestSections()) {
            tests.add(new Object[] { new ClientYamlTestCandidate(yamlTestSuite, testSection) });
        }
    }
    // sort the candidates so they will always be in the same order before being shuffled, for repeatability
    tests.sort(Comparator.comparing(o -> ((ClientYamlTestCandidate) o[0]).getTestPath()));
    return tests;
}
Also used : Path(java.nio.file.Path) RequestOptions(org.opensearch.client.RequestOptions) Arrays(java.util.Arrays) WarningsHandler(org.opensearch.client.WarningsHandler) OpenSearchNodesSniffer(org.opensearch.client.sniff.OpenSearchNodesSniffer) BeforeClass(org.junit.BeforeClass) TimeoutSuite(com.carrotsearch.randomizedtesting.annotations.TimeoutSuite) ClientYamlTestSection(org.opensearch.test.rest.yaml.section.ClientYamlTestSection) Version(org.opensearch.Version) HashMap(java.util.HashMap) Request(org.opensearch.client.Request) Strings(org.opensearch.common.Strings) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Locale(java.util.Locale) Map(java.util.Map) RestClient(org.opensearch.client.RestClient) RestClientBuilder(org.opensearch.client.RestClientBuilder) ClientYamlSuiteRestApi(org.opensearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi) Path(java.nio.file.Path) Before(org.junit.Before) Node(org.opensearch.client.Node) AfterClass(org.junit.AfterClass) ClientYamlSuiteRestSpec(org.opensearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec) Files(java.nio.file.Files) TimeUnits(org.apache.lucene.tests.util.TimeUnits) ExecutableSection(org.opensearch.test.rest.yaml.section.ExecutableSection) Set(java.util.Set) IOException(java.io.IOException) ClientYamlTestSuite(org.opensearch.test.rest.yaml.section.ClientYamlTestSuite) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Tuple(org.opensearch.common.collect.Tuple) IOUtils(org.opensearch.core.internal.io.IOUtils) OpenSearchRestTestCase(org.opensearch.test.rest.OpenSearchRestTestCase) List(java.util.List) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Comparator(java.util.Comparator) HttpHost(org.apache.http.HttpHost) Response(org.opensearch.client.Response) PathUtils(org.opensearch.common.io.PathUtils) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) ClientYamlTestSection(org.opensearch.test.rest.yaml.section.ClientYamlTestSection) ClientYamlTestSuite(org.opensearch.test.rest.yaml.section.ClientYamlTestSuite)

Example 14 with NamedXContentRegistry

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

the class AggregatorFactoriesBuilderTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // register aggregations as NamedWriteable
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    namedXContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Before(org.junit.Before)

Example 15 with NamedXContentRegistry

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

the class AggregatorFactoriesTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    xContentRegistry = new NamedXContentRegistry(new SearchModule(settings, emptyList()).getNamedXContents());
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Settings(org.opensearch.common.settings.Settings) AbstractQueryTestCase(org.opensearch.test.AbstractQueryTestCase)

Aggregations

NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)33 SearchModule (org.opensearch.search.SearchModule)16 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)13 XContentParser (org.opensearch.common.xcontent.XContentParser)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 BeforeClass (org.junit.BeforeClass)10 Settings (org.opensearch.common.settings.Settings)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 List (java.util.List)8 ClusterService (org.opensearch.cluster.service.ClusterService)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ActionListener (org.opensearch.action.ActionListener)6 MapperService (org.opensearch.index.mapper.MapperService)6 ClusterState (org.opensearch.cluster.ClusterState)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Collections.singletonList (java.util.Collections.singletonList)4