[TESTS] Fix Inline template tests
This change adds a method to WatcherTestUtils to compare two json structures since order is not guaranteed in template parameters. The Inline template tests in SearchInputTests and SearchTransformTests now use this instead of string comparision. Original commit: elastic/x-pack-elasticsearch@c433545128
This commit is contained in:
parent
8fad9937f7
commit
9a5455f573
|
@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.watcher.actions.ActionWrapper;
|
||||
|
@ -31,7 +30,6 @@ import org.elasticsearch.watcher.license.LicenseService;
|
|||
import org.elasticsearch.watcher.support.WatcherUtils;
|
||||
import org.elasticsearch.watcher.support.clock.ClockMock;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.template.Template;
|
||||
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
|
||||
import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger;
|
||||
|
@ -41,7 +39,10 @@ import org.elasticsearch.watcher.watch.Watch;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
|
@ -51,10 +52,9 @@ import static org.elasticsearch.index.query.QueryBuilders.filteredQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.areJsonEquivalent;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.getRandomSupportedSearchType;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
||||
|
@ -131,7 +131,7 @@ public class SearchInputTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
|
||||
SearchInput.Result executedResult = executeSearchInput(request);
|
||||
assertThat(executedResult.executedRequest().templateSource().toUtf8(), equalTo(expectedQuery));
|
||||
assertThat(areJsonEquivalent(executedResult.executedRequest().templateSource().toUtf8(), expectedQuery), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -9,12 +9,15 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.base.Charsets;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
|
@ -221,4 +224,11 @@ public final class WatcherTestUtils {
|
|||
return randomFrom(searchTypes.toArray(new SearchType[searchTypes.size()]));
|
||||
}
|
||||
|
||||
public static boolean areJsonEquivalent(String json1, String json2) throws IOException {
|
||||
XContentParser parser1 = XContentHelper.createParser(json1.getBytes(Charsets.UTF_8), 0, json1.getBytes(Charsets.UTF_8).length);
|
||||
XContentParser parser2 = XContentHelper.createParser(json2.getBytes(Charsets.UTF_8), 0, json2.getBytes(Charsets.UTF_8).length);
|
||||
Map<String, Object> map1 = parser1.map();
|
||||
Map<String, Object> map2 = parser2.map();
|
||||
return map1.equals(map2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.watcher.actions.ActionWrapper;
|
||||
|
@ -34,7 +33,6 @@ import org.elasticsearch.watcher.support.WatcherUtils;
|
|||
import org.elasticsearch.watcher.support.clock.ClockMock;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.template.Template;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
|
||||
import org.elasticsearch.watcher.transform.Transform;
|
||||
import org.elasticsearch.watcher.transform.TransformBuilders;
|
||||
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
|
||||
|
@ -45,7 +43,10 @@ import org.elasticsearch.watcher.watch.Watch;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
|
@ -268,7 +269,7 @@ public class SearchTransformTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchTransform.Result executedResult = executeSearchTransform(request);
|
||||
|
||||
assertThat(executedResult.executedRequest().templateSource().toUtf8(), equalTo(expectedQuery));
|
||||
assertThat(areJsonEquivalent(executedResult.executedRequest().templateSource().toUtf8(), expectedQuery), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue