use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class AbstractSerializingTestCase method testFromXContent.
/**
* Generic test that creates new instance from the test instance and checks
* both for equality and asserts equality on the two instances.
*/
public void testFromXContent() throws IOException {
for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
T testInstance = createTestInstance();
XContentType xContentType = randomFrom(XContentType.values());
XContentBuilder builder = toXContent(testInstance, xContentType);
XContentBuilder shuffled = shuffleXContent(builder);
assertParsedInstance(xContentType, shuffled.bytes(), testInstance);
for (Map.Entry<String, T> alternateVersion : getAlternateVersions().entrySet()) {
String instanceAsString = alternateVersion.getKey();
assertParsedInstance(XContentType.JSON, new BytesArray(instanceAsString), alternateVersion.getValue());
}
}
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class AbstractStreamableXContentTestCase method testFromXContent.
/**
* Generic test that creates new instance from the test instance and checks
* both for equality and asserts equality on the two queries.
*/
public void testFromXContent() throws IOException {
for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
T testInstance = createTestInstance();
XContentType xContentType = randomFrom(XContentType.values());
XContentBuilder builder = toXContent(testInstance, xContentType);
XContentBuilder shuffled = shuffleXContent(builder);
assertParsedInstance(xContentType, shuffled.bytes(), testInstance);
for (Map.Entry<String, T> alternateVersion : getAlternateVersions().entrySet()) {
String instanceAsString = alternateVersion.getKey();
assertParsedInstance(XContentType.JSON, new BytesArray(instanceAsString), alternateVersion.getValue());
}
}
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class SearchSortValuesTests method testFromXContent.
public void testFromXContent() throws IOException {
SearchSortValues sortValues = createTestItem();
XContentType xcontentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(sortValues, xcontentType, humanReadable);
SearchSortValues parsed;
try (XContentParser parser = createParser(xcontentType.xContent(), originalBytes)) {
// skip to the elements start array token, fromXContent advances from there if called
parser.nextToken();
parser.nextToken();
parser.nextToken();
parsed = SearchSortValues.fromXContent(parser);
parser.nextToken();
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xcontentType, humanReadable), xcontentType);
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class NestedIdentityTests method testFromXContent.
public void testFromXContent() throws IOException {
NestedIdentity nestedIdentity = createTestItem(randomInt(3));
XContentType xcontentType = randomFrom(XContentType.values());
XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
if (randomBoolean()) {
builder.prettyPrint();
}
builder = nestedIdentity.innerToXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = createParser(builder);
NestedIdentity parsedNestedIdentity = NestedIdentity.fromXContent(parser);
assertEquals(nestedIdentity, parsedNestedIdentity);
assertNull(parser.nextToken());
}
use of org.elasticsearch.common.xcontent.XContentType in project crate by crate.
the class ColumnPolicyIntegrationTest method testStrictPartitionedTableUpdate.
@Test
public void testStrictPartitionedTableUpdate() throws Exception {
execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
ensureYellow();
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "numbers")).execute().actionGet();
assertThat(response.getIndexTemplates().size(), is(1));
IndexTemplateMetaData template = response.getIndexTemplates().get(0);
CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(mappingStr, is(notNullValue()));
Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
@SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(mapping.get("dynamic")), is(ColumnPolicy.STRICT.value()));
execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
execute("refresh table numbers");
MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("numbers", Arrays.asList(new BytesRef("true"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(ColumnPolicy.STRICT.value()));
expectedException.expect(SQLActionException.class);
expectedException.expectMessage("Column perfect unknown");
execute("update numbers set num=?, perfect=? where num=6", new Object[] { 28, true });
}
Aggregations