Search in sources :

Example 1 with DefaultErrorHit

use of com.yahoo.search.result.DefaultErrorHit in project vespa by vespa-engine.

the class DefaultErrorHitTestCase method testErrorHitRenderingWithException.

@SuppressWarnings("null")
public void testErrorHitRenderingWithException() throws IOException {
    NullPointerException cause = null;
    try {
        Object a = null;
        a.toString();
    } catch (NullPointerException e) {
        cause = e;
    }
    StringWriter w = new StringWriter();
    SearchRendererAdaptor.simpleRenderDefaultErrorHit(w, new DefaultErrorHit("test", new ErrorMessage(79, "Myerror", "Mydetail", cause)));
    String sep = System.getProperty("line.separator");
    assertEquals("<errordetails>\n" + "  <error source=\"test\" error=\"Myerror\" code=\"79\">Mydetail\n" + "    <cause>\n" + "java.lang.NullPointerException" + sep + "\tat ", w.toString().substring(0, 119 + sep.length()));
}
Also used : StringWriter(java.io.StringWriter) ErrorMessage(com.yahoo.search.result.ErrorMessage) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit)

Example 2 with DefaultErrorHit

use of com.yahoo.search.result.DefaultErrorHit in project vespa by vespa-engine.

the class HitGroupTestCase method testErrorsConsistencyUsingErrorOperations.

@Test
public void testErrorsConsistencyUsingErrorOperations() {
    HitGroup hits = new HitGroup();
    Query query = new Query();
    query.errors().add(ErrorMessage.createIllegalQuery("test1"));
    query.errors().add(ErrorMessage.createTimeout("test2"));
    hits.setQuery(query);
    hits.addError(ErrorMessage.createForbidden("test3"));
    hits.addError(ErrorMessage.createUnspecifiedError("test4"));
    assertEquals(4, hits.getErrorHit().errors().size());
    assertEquals(0, query.errors().size());
    assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList()));
    DefaultErrorHit removedErrors = hits.removeErrorHit();
    assertNotNull(removedErrors);
    assertEquals(4, removedErrors.errors().size());
    assertNull(hits.get(removedErrors.getId().toString()));
    assertFalse(errorHitIn(hits.asList()).isPresent());
    assertNull(hits.removeErrorHit());
}
Also used : Query(com.yahoo.search.Query) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 3 with DefaultErrorHit

use of com.yahoo.search.result.DefaultErrorHit in project vespa by vespa-engine.

the class HitGroupTestCase method testErrorsConsistencyUsingHitOperations.

@Test
public void testErrorsConsistencyUsingHitOperations() {
    HitGroup hits = new HitGroup();
    Query query = new Query();
    query.errors().add(ErrorMessage.createIllegalQuery("test1"));
    query.errors().add(ErrorMessage.createTimeout("test2"));
    hits.setQuery(query);
    DefaultErrorHit errors = new DefaultErrorHit("source", ErrorMessage.createForbidden("test3"));
    errors.addError(ErrorMessage.createUnspecifiedError("test4"));
    hits.add(errors);
    assertEquals(4, hits.getErrorHit().errors().size());
    assertEquals(0, query.errors().size());
    assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList()));
    DefaultErrorHit removedErrors = (DefaultErrorHit) hits.remove(errors.getId());
    assertNotNull(removedErrors);
    assertEquals(4, removedErrors.errors().size());
    assertNull(hits.get(removedErrors.getId().toString()));
    assertFalse(errorHitIn(hits.asList()).isPresent());
    assertNull(hits.remove(errors.getId()));
}
Also used : Query(com.yahoo.search.Query) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 4 with DefaultErrorHit

use of com.yahoo.search.result.DefaultErrorHit in project vespa by vespa-engine.

the class ErrorHitRenderTestCase method testXMLEscaping.

@Test
public void testXMLEscaping() throws java.io.IOException {
    ErrorHit h = new DefaultErrorHit("testcase", ErrorMessage.createUnspecifiedError("<>\"&"));
    StringWriter writer = new StringWriter();
    SearchRendererAdaptor.renderMessageDefaultErrorHit(new XMLWriter(writer), h.errors().iterator().next());
    assertEquals("<error source=\"testcase\" error=\"Unspecified error\" code=\"5\">&lt;&gt;\"&amp;</error>\n", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) ErrorHit(com.yahoo.search.result.ErrorHit) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) XMLWriter(com.yahoo.text.XMLWriter) Test(org.junit.Test)

Aggregations

DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)4 Test (org.junit.Test)3 Query (com.yahoo.search.Query)2 HitGroup (com.yahoo.search.result.HitGroup)2 StringWriter (java.io.StringWriter)2 ErrorHit (com.yahoo.search.result.ErrorHit)1 ErrorMessage (com.yahoo.search.result.ErrorMessage)1 XMLWriter (com.yahoo.text.XMLWriter)1