Add roundtrip testing to RatedDocumentKey

This commit is contained in:
Isabel Drost-Fromm 2016-08-24 15:32:44 +02:00
parent 94497871b5
commit 87367be4e7
2 changed files with 49 additions and 2 deletions

View File

@ -21,18 +21,20 @@ package org.elasticsearch.index.rankeval;
import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.FromXContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
public class RatedDocumentKey extends ToXContentToBytes implements Writeable {
public class RatedDocumentKey extends ToXContentToBytes implements Writeable, FromXContentBuilder<RatedDocumentKey> {
public static final ParseField DOC_ID_FIELD = new ParseField("doc_id");
public static final ParseField TYPE_FIELD = new ParseField("type");
public static final ParseField INDEX_FIELD = new ParseField("index");
@ -103,7 +105,18 @@ public class RatedDocumentKey extends ToXContentToBytes implements Writeable {
out.writeString(type);
out.writeString(docId);
}
@Override
public RatedDocumentKey fromXContent(XContentParser parser, ParseFieldMatcher matcher) throws IOException {
return RatedDocumentKey.fromXContent(parser, new ParseFieldMatcherSupplier() {
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return matcher;
}
});
}
public static RatedDocumentKey fromXContent(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException {
return PARSER.apply(parser, context);
}

View File

@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.rankeval;
import java.io.IOException;
public class RatedDocumentKeyTests extends XContentRoundtripTestCase<RatedDocumentKey> {
public void testXContentRoundtrip() throws IOException {
String index = randomAsciiOfLengthBetween(0, 10);
String type = randomAsciiOfLengthBetween(0, 10);
String docId = randomAsciiOfLengthBetween(0, 10);
RatedDocumentKey testItem = new RatedDocumentKey(index, type, docId);
roundtrip(testItem);
}
}