@Test public void testJustIndex() throws Exception { Resource res = createResource("foo/_all"); assertEquals("foo/_all", res.toString()); }
@Test public void testJustType() throws Exception { Resource res = createResource("_all/foo"); assertEquals("_all/foo", res.toString()); }
@Test public void testUnderscore() throws Exception { Resource res = createResource("fo_o/ba_r"); assertEquals("fo_o/ba_r", res.toString()); }
@Test public void testIndexAndType() throws Exception { Resource res = createResource("foo/bar"); assertEquals("foo/bar", res.toString()); }
@Test public void createFieldExtractor() { Settings settings = new TestSettings(); settings.setResourceWrite("test/{field}"); settings.setInternalVersion(EsMajorVersion.V_7_X); InitializationUtils.setFieldExtractorIfNotSet(settings, MapFieldExtractor.class, LOG); IndexExtractor iformat = ObjectUtils.instantiate(settings.getMappingIndexExtractorClassName(), settings); iformat.compile(new Resource(settings, false).toString()); assertThat(iformat.hasPattern(), is(true)); Map<String, String> data = new HashMap<String, String>(); data.put("field", "data"); Object field = iformat.field(data); assertThat(field.toString(), equalTo("\"_index\":\"test\",\"_type\":\"data\"")); }
@Test public void testAllTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Resource res = createResource("_all"); assertEquals("_all", res.toString()); }
@Test public void testUnderscoreTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Resource res = createResource("fo_o"); assertEquals("fo_o", res.toString()); }
@Test(expected = EsHadoopIllegalArgumentException.class) public void testQueryUriConflictWithParams() throws Exception { Settings s = new TestSettings(); s.setProperty(ConfigurationOptions.ES_QUERY, "{\"match_all\":{}}"); Resource res = createResource("foo/bar/_search=?somequery&bla=bla", s); assertEquals("foo/bar", res.toString()); }
@Test public void testIndexTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Resource res = createResource("foo"); assertEquals("foo", res.toString()); }
@Test(expected = EsHadoopIllegalArgumentException.class) public void testQueryUriConflict() throws Exception { Settings s = new TestSettings(); s.setProperty(ConfigurationOptions.ES_QUERY, "{\"match_all\":{}}"); Resource res = createResource("foo/bar/_search=?somequery", s); assertEquals("foo/bar", res.toString()); }
@Test public void testQueryUri() throws Exception { Settings s = new TestSettings(); Resource res = createResource("foo/bar/_search=?somequery", s); assertEquals("foo/bar", res.toString()); assertEquals("?somequery", s.getQuery()); }
@Test public void testQueryUriWithParams() throws Exception { Settings s = new TestSettings(); Resource res = createResource("foo/bar/_search=?somequery&bla=bla", s); assertEquals("foo/bar", res.toString()); assertEquals("?somequery&bla=bla", s.getQuery()); }
@Test(expected = EsHadoopIllegalArgumentException.class) public void createFieldExtractorNull() { Settings settings = new TestSettings(); settings.setResourceWrite("test/{field}"); settings.setInternalVersion(EsMajorVersion.V_7_X); InitializationUtils.setFieldExtractorIfNotSet(settings, MapFieldExtractor.class, LOG); IndexExtractor iformat = ObjectUtils.instantiate(settings.getMappingIndexExtractorClassName(), settings); iformat.compile(new Resource(settings, false).toString()); assertThat(iformat.hasPattern(), is(true)); Map<String, String> data = new HashMap<String, String>(); data.put("field", null); iformat.field(data); fail(); }
@Test(expected = EsHadoopIllegalArgumentException.class) public void createFieldExtractorFailure() { Settings settings = new TestSettings(); settings.setResourceWrite("test/{optional}"); settings.setInternalVersion(EsMajorVersion.V_7_X); InitializationUtils.setFieldExtractorIfNotSet(settings, MapFieldExtractor.class, LOG); IndexExtractor iformat = ObjectUtils.instantiate(settings.getMappingIndexExtractorClassName(), settings); iformat.compile(new Resource(settings, false).toString()); assertThat(iformat.hasPattern(), is(true)); Map<String, String> data = new HashMap<String, String>(); data.put("field", "data"); iformat.field(data); fail(); } }
@Test(expected = EsHadoopIllegalArgumentException.class) public void testQueryUriConflictTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Settings s = new TestSettings(); s.setProperty(ConfigurationOptions.ES_QUERY, "{\"match_all\":{}}"); Resource res = createResource("foo/_search=?somequery", s); assertEquals("foo", res.toString()); }
@Test(expected = EsHadoopIllegalArgumentException.class) public void testQueryUriConflictWithParamsTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Settings s = new TestSettings(); s.setProperty(ConfigurationOptions.ES_QUERY, "{\"match_all\":{}}"); Resource res = createResource("foo/_search=?somequery&bla=bla", s); assertEquals("foo", res.toString()); }
@Test public void testQueryUriWithParamsTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Settings s = new TestSettings(); Resource res = createResource("foo/_search=?somequery&bla=bla", s); assertEquals("foo", res.toString()); assertEquals("?somequery&bla=bla", s.getQuery()); }
@Test public void testQueryUriTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Settings s = new TestSettings(); Resource res = createResource("foo/_search=?somequery", s); assertEquals("foo", res.toString()); assertEquals("?somequery", s.getQuery()); }
@Test public void testBulkWithIngestPipeline() throws Exception { Settings settings = new TestSettings(); settings.setProperty(ConfigurationOptions.ES_INGEST_PIPELINE, "ingest-pipeline"); Resource res = createResource("pipeline/test", settings); assertEquals("pipeline/test", res.toString()); assertEquals("pipeline/_aliases", res.aliases()); assertEquals("pipeline/test/_bulk?pipeline=ingest-pipeline", res.bulk()); assertEquals("pipeline/_refresh", res.refresh()); }
@Test public void testBulkWithIngestPipelineTypeless() throws Exception { Assume.assumeTrue("Typeless api only accepted 7.X and up for writes. Running [" + testVersion + ", " + readResource + "]", (testVersion.onOrAfter(EsMajorVersion.V_7_X) || readResource)); Settings settings = new TestSettings(); settings.setProperty(ConfigurationOptions.ES_INGEST_PIPELINE, "ingest-pipeline"); Resource res = createResource("pipeline", settings); assertEquals("pipeline", res.toString()); assertEquals("pipeline/_aliases", res.aliases()); assertEquals("pipeline/_bulk?pipeline=ingest-pipeline", res.bulk()); assertEquals("pipeline/_refresh", res.refresh()); }