use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.
@Test
public final void testCompleteFeedWithCreateAndCondition() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
smokeTestDoc(doc);
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
checkSimpleArrayAdd(update);
assertThat(update.getCreateIfNonExistent(), is(true));
assertThat(update.getCondition().getSelection(), is("bla"));
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithEmptyDoc.
@Test
public final void testCompleteFeedWithEmptyDoc() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": {}}" + ", " + "{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": {}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
assertEquals("smoke", doc.getId().getDocType());
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
assertEquals("testarray", update.getId().getDocType());
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonReaderTestCase method testFeedWithTestAndSetCondition.
private void testFeedWithTestAndSetCondition(String jsonDoc) {
final ByteArrayInputStream parseInfoDoc = new ByteArrayInputStream(Utf8.toBytes(jsonDoc));
final JsonReader reader = new JsonReader(types, parseInfoDoc, parserFactory);
final int NUM_OPERATIONS_IN_FEED = 3;
for (int i = 0; i < NUM_OPERATIONS_IN_FEED; i++) {
DocumentOperation operation = reader.next();
assertTrue("A test and set condition should be present", operation.getCondition().isPresent());
assertEquals("DocumentOperation's test and set condition should be equal to the one in the JSON feed", "smoke.something == \"smoketest\"", operation.getCondition().getSelection());
}
assertNull(reader.next());
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonWriterTestCase method removeTest.
@Test
public void removeTest() {
final DocumentId documentId = new DocumentId("id:unittest:smoke::whee");
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[" + Utf8.toString(JsonWriter.documentRemove(documentId)) + "]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation actualRemoveAsBaseType = r.next();
assertSame(DocumentRemove.class, actualRemoveAsBaseType.getClass());
assertEquals(actualRemoveAsBaseType.getId(), documentId);
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class IndexingProcessorTestCase method requireThatIndexerProcessesDocuments.
@Test
public void requireThatIndexerProcessesDocuments() {
Document input = new Document(indexer.getDocumentTypeManager().getDocumentType("music"), "doc:scheme:");
input.setFieldValue("artist", new StringFieldValue("69"));
DocumentOperation op = process(new DocumentPut(input));
assertTrue(op instanceof DocumentPut);
Document output = ((DocumentPut) op).getDocument();
assertEquals(new StringFieldValue("69"), output.getFieldValue("title"));
assertEquals("music", output.getDataType().getName());
}
Aggregations