Add roundtrip testing to RatedDocumentKey
This commit is contained in:
parent
94497871b5
commit
87367be4e7
|
@ -21,18 +21,20 @@ package org.elasticsearch.index.rankeval;
|
||||||
|
|
||||||
import org.elasticsearch.action.support.ToXContentToBytes;
|
import org.elasticsearch.action.support.ToXContentToBytes;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
|
import org.elasticsearch.common.xcontent.FromXContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
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 DOC_ID_FIELD = new ParseField("doc_id");
|
||||||
public static final ParseField TYPE_FIELD = new ParseField("type");
|
public static final ParseField TYPE_FIELD = new ParseField("type");
|
||||||
public static final ParseField INDEX_FIELD = new ParseField("index");
|
public static final ParseField INDEX_FIELD = new ParseField("index");
|
||||||
|
@ -104,6 +106,17 @@ public class RatedDocumentKey extends ToXContentToBytes implements Writeable {
|
||||||
out.writeString(docId);
|
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 {
|
public static RatedDocumentKey fromXContent(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException {
|
||||||
return PARSER.apply(parser, context);
|
return PARSER.apply(parser, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue