use of com.yahoo.document.DocumentId in project vespa by vespa-engine.
the class JsonRendererTestCase method testJsonCallback.
@Test
public final void testJsonCallback() throws IOException, InterruptedException, ExecutionException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"documentid\": \"id:unittest:smoke::whee\"\n" + " },\n" + " \"id\": \"id:unittest:smoke::whee\",\n" + " \"relevance\": 1.0\n" + " }\n" + " ],\n" + " \"fields\": {\n" + " \"totalCount\": 1\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
String jsonCallback = "some_function_name";
Result r = newEmptyResult(new String[] { "query=a", "jsoncallback=" + jsonCallback });
Hit h = new Hit("jsonCallbackTest");
h.setField("documentid", new DocumentId("id:unittest:smoke::whee"));
r.hits().add(h);
r.setTotalHitCount(1L);
String summary = render(r);
String jsonCallbackBegin = summary.substring(0, jsonCallback.length() + 1);
String jsonCallbackEnd = summary.substring(summary.length() - 2);
String json = summary.substring(jsonCallback.length() + 1, summary.length() - 2);
assertEquals(jsonCallback + "(", jsonCallbackBegin);
assertEqualJson(expected, json);
assertEquals(");", jsonCallbackEnd);
}
use of com.yahoo.document.DocumentId in project vespa by vespa-engine.
the class SimpleDocumentProcessorTestCase method requireThatProcessingMultipleOperationsWork.
@Test
public void requireThatProcessingMultipleOperationsWork() {
DocumentType type = new DocumentType("foobar");
type.addField("title", DataType.STRING);
Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentUpdate(type, "doc:this:is:an:update"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")));
DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
service.getExecutor().process(p);
assertThat(p.getDocumentOperations().size(), is(3));
assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
assertThat(p.getDocumentOperations().get(1) instanceof DocumentUpdate, is(true));
assertThat(p.getDocumentOperations().get(2) instanceof DocumentRemove, is(true));
assertThat(p.getDocumentOperations().get(2).getId().toString(), is("userdoc:foobar:1234:something"));
}
use of com.yahoo.document.DocumentId in project vespa by vespa-engine.
the class SimpleDocumentProcessorTestCase method requireThatThrowingTerminatesIteration.
@Test
public void requireThatThrowingTerminatesIteration() {
DocumentType type = new DocumentType("foobar");
type.addField("title", DataType.STRING);
Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")), new DocumentPut(type, "doc:this:is:a:document2"));
DocprocService service = setupDocprocService(new SimpleDocumentProcessorThrowingOnRemovesAndUpdates());
try {
service.getExecutor().process(p);
} catch (RuntimeException re) {
// ok
}
assertThat(p.getDocumentOperations().size(), is(3));
assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true));
assertThat(p.getDocumentOperations().get(1).getId().toString(), is("doc:this:is:a:remove"));
assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), nullValue());
}
use of com.yahoo.document.DocumentId in project vespa by vespa-engine.
the class AccessesAnnotationTestCase method requireThatFieldsAreRestricted.
@Test
public void requireThatFieldsAreRestricted() {
DocumentType type = new DocumentType("album");
type.addField("title", DataType.STRING);
type.addField("artist", DataType.STRING);
type.addField("year", DataType.INT);
Document doc = new Document(type, new DocumentId("doc:map:test:1"));
MyDocProc docProc = new MyDocProc();
DocumentPut put = new DocumentPut(doc);
Document proxy = new Call(docProc).configDoc(docProc, put).getDocument();
proxy.setFieldValue("title", new StringFieldValue("foo"));
try {
proxy.setFieldValue("year", new IntegerFieldValue(69));
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
proxy.getFieldValue("title");
try {
proxy.getFieldValue("year");
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
}
use of com.yahoo.document.DocumentId in project vespa by vespa-engine.
the class CallbackTestCase method setUp.
public void setUp() {
service = new DocprocService("callback");
service.setCallStack(new CallStack().addNext(new TestCallbackDp()));
service.setInService(true);
// Create documents
DocumentType type = new DocumentType("test");
type.addField("status", DataType.STRING);
put1 = new DocumentPut(type, new DocumentId("doc:callback:test:1"));
put2 = new DocumentPut(type, new DocumentId("doc:callback:test:2"));
operations.add(new DocumentPut(type, new DocumentId("doc:callback:test:3")));
operations.add(new DocumentPut(type, new DocumentId("doc:callback:test:4")));
}
Aggregations