use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testMappingStructsInArrays.
public void testMappingStructsInArrays() {
Document doc = getDoc();
DocumentProcessor proc = new TestMappingStructInArrayProcessor();
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("name", "listeners[0].firstname");
ProxyDocument mapped = new ProxyDocument(proc, doc, fieldMap);
Processing p = Processing.of(new DocumentPut(mapped));
proc.process(p);
assertEquals(2, ((Array<Struct>) doc.getFieldValue("listeners")).size());
assertEquals("peter", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("firstname")).getString()));
assertEquals("olsen", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("lastname")).getString()));
assertEquals("anders", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("firstname")).getString()));
assertEquals("and", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("lastname")).getString()));
fieldMap.clear();
fieldMap.put("name", "listeners[2].firstname");
mapped = new ProxyDocument(proc, doc, fieldMap);
p = Processing.of(new DocumentPut(mapped));
try {
proc.process(p);
fail("Should not have worked");
} catch (IllegalArgumentException iae) {
// ok!
}
assertEquals(2, ((Array<Struct>) doc.getFieldValue("listeners")).size());
assertEquals("peter", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("firstname")).getString()));
assertEquals("olsen", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("lastname")).getString()));
assertEquals("anders", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("firstname")).getString()));
assertEquals("and", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("lastname")).getString()));
// test remove:
proc = new TestRemovingMappingStructInArrayProcessor();
fieldMap.clear();
fieldMap.put("name", "listeners[1].lastname");
mapped = new ProxyDocument(proc, doc, fieldMap);
p = Processing.of(new DocumentPut(mapped));
proc.process(p);
assertEquals(2, ((Array<Struct>) doc.getFieldValue("listeners")).size());
assertEquals("peter", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("firstname")).getString()));
assertEquals("olsen", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("lastname")).getString()));
assertEquals("anders", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("firstname")).getString()));
assertNull(((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("lastname"));
fieldMap.clear();
fieldMap.put("name", "listeners[2].lastname");
mapped = new ProxyDocument(proc, doc, fieldMap);
p = Processing.of(new DocumentPut(mapped));
try {
proc.process(p);
fail("Should not have worked");
} catch (IllegalArgumentException iae) {
// ok!
}
assertEquals(2, ((Array<Struct>) doc.getFieldValue("listeners")).size());
assertEquals("peter", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("firstname")).getString()));
assertEquals("olsen", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(0).getFieldValue("lastname")).getString()));
assertEquals("anders", (((StringFieldValue) ((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("firstname")).getString()));
assertNull(((Array<Struct>) doc.getFieldValue("listeners")).get(1).getFieldValue("lastname"));
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testProxyAndSecure.
public void testProxyAndSecure() {
DocumentProcessor procOK = new TestDPSecure();
Map<Pair<String, String>, String> fieldMap = new HashMap<>();
fieldMap.put(new Pair<>("album", "titleMapped"), "title");
procOK.setFieldMap(fieldMap);
DocumentPut put = new DocumentPut(getDoc());
Document proxyDoc = new Call(procOK).configDoc(procOK, put).getDocument();
procOK.process(Processing.of(new DocumentPut(proxyDoc)));
assertEquals(proxyDoc.getFieldValue("title").toString(), "MyTitle MyTitle");
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class JsonFeedReader method read.
@Override
public void read(Operation operation) throws Exception {
DocumentOperation documentOperation = reader.next();
if (documentOperation == null) {
stream.close();
operation.setInvalid();
return;
}
if (documentOperation instanceof DocumentUpdate) {
operation.setDocumentUpdate((DocumentUpdate) documentOperation);
} else if (documentOperation instanceof DocumentRemove) {
operation.setRemove(documentOperation.getId());
} else if (documentOperation instanceof DocumentPut) {
operation.setDocument(((DocumentPut) documentOperation).getDocument());
} else {
throw new IllegalStateException("Got unknown class from JSON reader: " + documentOperation.getClass().getName());
}
operation.setCondition(documentOperation.getCondition());
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class SingleSender method put.
@Override
public void put(Document doc, TestAndSetCondition condition) {
PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(doc));
message.setCondition(condition);
send(message);
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class IndexingProcessorTestCase method requireThatIndexerForwardsDocumentsOfUnknownType.
@Test
public void requireThatIndexerForwardsDocumentsOfUnknownType() {
Document input = new Document(new DocumentType("unknown"), "doc:scheme:");
DocumentOperation output = process(new DocumentPut(input));
assertTrue(output instanceof DocumentPut);
assertSame(input, ((DocumentPut) output).getDocument());
}
Aggregations