blob: 0d73138e0775337761d0647b8ec5a2939d5473af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.update;
import com.yahoo.document.*;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.serialization.*;
import java.io.FileOutputStream;
/**
* @author <a href="mailto:bratseth@yahoo-inc.com">Jon Bratseth</a>
*/
public class SerializationTestCase extends junit.framework.TestCase {
private DocumentType documentType;
private Field field;
public SerializationTestCase(String name) {
super(name);
}
public void setUp() {
documentType=new DocumentType("document1");
field=new Field("field1", DataType.getArray(DataType.STRING));
documentType.addField(field);
}
public void testAddSerialization() {
FieldUpdate update=FieldUpdate.createAdd(field, new StringFieldValue("value1"));
DocumentSerializer buffer = DocumentSerializerFactory.create42();
update.serialize(buffer);
buffer.getBuf().rewind();
try{
FileOutputStream fos = new FileOutputStream("src/test/files/addfieldser.dat");
fos.write(buffer.getBuf().array(), 0, buffer.getBuf().remaining());
fos.close();
} catch (Exception e) {}
FieldUpdate deserializedUpdate = new FieldUpdate(DocumentDeserializerFactory.create42(new DocumentTypeManager(), buffer.getBuf()), documentType, Document.SERIALIZED_VERSION);
assertEquals("'field1' [add value1 1]", deserializedUpdate.toString());
}
public void testClearSerialization() {
FieldUpdate update=FieldUpdate.createClear(field);
DocumentSerializer buffer = DocumentSerializerFactory.create42();
update.serialize(buffer);
buffer.getBuf().rewind();
FieldUpdate deserializedUpdate = new FieldUpdate(DocumentDeserializerFactory.create42(new DocumentTypeManager(), buffer.getBuf()), documentType, Document.SERIALIZED_VERSION);
assertEquals("'field1' [clear]", deserializedUpdate.toString());
}
}
|