Search in sources :

Example 41 with DocumentId

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);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) DocumentId(com.yahoo.document.DocumentId) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 42 with DocumentId

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"));
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 43 with DocumentId

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());
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 44 with DocumentId

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.*"));
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 45 with DocumentId

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")));
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Aggregations

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2