UserArchiveQueryHandler implements QueryHandler { @Override public List<Stanza> handle(Query query, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) { try { return doHandle(query, serverRuntimeContext, sessionContext); } catch (XMLSemanticError xmlSemanticError) { Stanza internalServerError = ServerErrorResponses.getStanzaError(StanzaErrorCondition.INTERNAL_SERVER_ERROR, query.iqStanza(), StanzaErrorType.CANCEL, null, null, null); return Collections.singletonList(internalServerError); } }  @Override boolean supports(Query query, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext); @Override List<Stanza> handle(Query query, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext);  }
@Test public void untargetedQueryEndsUpInInitiatingEntityArchive() throws XMLSemanticError { archives.givenArchive(INITIATING_ENTITY.getBareJID()); List<Stanza> stanzas = tested.handle(untargetedQuery, serverRuntimeContext, sessionContext); assertEquals(1, stanzas.size()); Stanza stanza = stanzas.get(0); assertEquals("iq", stanza.getName()); assertNotNull(stanza.getSingleInnerElementsNamed("fin")); }
@Test public void preventsUserFromQueryingOtherUserArchive() throws XMLSemanticError { List<Stanza> stanzas = tested.handle(romeoTargetingQuery, serverRuntimeContext, sessionContext); assertError(stanzas, StanzaErrorCondition.FORBIDDEN); }
@Test public void unexistingArchiveLeadsToItemNotFound() throws XMLSemanticError { List<Stanza> stanzas = tested.handle(untargetedQuery, serverRuntimeContext, sessionContext); assertError(stanzas, StanzaErrorCondition.ITEM_NOT_FOUND); }