### Question:
TraverseByObjectSearchDelegate implements Delegate { public ResultSet<?> handle(TraverseGraphByObjectSearchRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, OperationTimeoutException { securityContext.checkPermission(TiFunctionConstants.traverseThreatIntelFact); FactSearchCriteria criteria = requestConverter.apply(request.getSearch()); ResultContainer<ObjectRecord> searchResult = objectFactDao.searchObjects(criteria); Collection<UUID> objectIds = set(searchResult.iterator(), ObjectRecord::getId); if (objectIds.isEmpty()) { return StreamingResultSet.builder().build(); } return traverseGraphHandler.traverse( objectIds, request.getTraverse().getQuery(), TraverseParams.builder() .setIncludeRetracted(request.getTraverse().getIncludeRetracted()) .setAfterTimestamp(request.getTraverse().getAfter()) .setBeforeTimestamp(request.getTraverse().getBefore()) .setLimit(request.getTraverse().getLimit()) .build()); } @Inject  TraverseByObjectSearchDelegate(TiSecurityContext securityContext,
                                        TraverseGraphHandler traverseGraphHandler,
                                        SearchObjectRequestConverter requestConverter,
                                        ObjectFactDao objectFactDao); ResultSet<?> handle(TraverseGraphByObjectSearchRequest request);  }### Answer:
@Test public void testTraverseGraphByObjectSearchWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.traverseThreatIntelFact); assertThrows(AccessDeniedException.class, () -> delegate.handle(new TraverseGraphByObjectSearchRequest())); }
@Test public void testTraverseGraphByObjectSearchWithoutSearchResult() throws Exception { when(objectFactDao.searchObjects(any())).thenReturn(ResultContainer.<ObjectRecord>builder().build()); ResultSet<?> result = delegate.handle(new TraverseGraphByObjectSearchRequest().setSearch(new SearchObjectRequest())); assertFalse(result.iterator().hasNext()); verify(requestConverter).apply(notNull()); verify(objectFactDao).searchObjects(notNull()); verifyNoInteractions(traverseGraphHandler); }
@Test public void testTraverseWithSearchAndParams() throws Exception { UUID objectId1 = UUID.randomUUID(); UUID objectId2 = UUID.randomUUID(); String query = "g.outE()"; Long after = 2L; Long before = 1L; TraverseGraphByObjectSearchRequest request = new TraverseGraphByObjectSearchRequest() .setSearch(new SearchObjectRequest()) .setTraverse(new TraverseGraphRequest() .setQuery(query) .setIncludeRetracted(true) .setAfter(after) .setBefore(before) .setLimit(10) ); Iterator<ObjectRecord> searchResult = set(new ObjectRecord().setId(objectId1), new ObjectRecord().setId(objectId2)).iterator(); when(objectFactDao.searchObjects(any())).thenReturn(ResultContainer.<ObjectRecord>builder().setValues(searchResult).build()); delegate.handle(request); verify(traverseGraphHandler).traverse( eq(set(objectId1, objectId2)), eq(query), argThat(traverseParams -> { assertTrue(traverseParams.isIncludeRetracted()); assertEquals(after, traverseParams.getAfterTimestamp()); assertEquals(before, traverseParams.getBeforeTimestamp()); assertEquals(10, traverseParams.getLimit()); return true; })); }