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()));
}
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());
}
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()));
}
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\"><>\"&</error>\n", writer.toString());
}
Aggregations