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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.core;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class DocumentTest {
@Test
public void simpleCaseOk() {
String docId = "doc id";
String docContent = "foo";
Document document = new Document(docId, docContent.getBytes(), null);
assertThat(document.getDocumentId(), is(docId));
assertThat(document.getData(), is(ByteBuffer.wrap(docContent.getBytes())));
assertThat(document.getDataAsString().toString(), is(docContent));
// Make sure that data is not modified on retrieval.
assertThat(document.getDataAsString().toString(), is(docContent));
assertThat(document.getData(), is(ByteBuffer.wrap(docContent.getBytes())));
assertThat(document.getDocumentId(), is(docId));
}
@Test(expected = ReadOnlyBufferException.class)
public void notMutablePutTest() {
Document document = new Document("id", null, "data", null /* context */);
document.getData().put("a".getBytes());
}
@Test(expected = ReadOnlyBufferException.class)
public void notMutableCompactTest() {
Document document = new Document("id", null, "data", null /* context */);
document.getData().compact();
}
}
|