### Question:
TraverseGraphDelegate implements Delegate { public ResultSet<?> handle(TraverseByObjectIdRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, OperationTimeoutException { securityContext.checkPermission(TiFunctionConstants.traverseThreatIntelFact); return handle(objectFactDao.getObject(request.getId()), request.getQuery()); } @Inject  TraverseGraphDelegate(TiSecurityContext securityContext,
                               ObjectFactDao objectFactDao,
                               ObjectManager objectManager,
                               FactManager factManager,
                               ObjectSearchDelegate objectSearch,
                               ObjectResponseConverter objectResponseConverter,
                               FactResponseConverter factResponseConverter,
                               ObjectTypeHandler objectTypeHandler); ResultSet<?> handle(TraverseByObjectIdRequest request); ResultSet<?> handle(TraverseByObjectTypeValueRequest request); ResultSet<?> handle(TraverseByObjectSearchRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testTraverseGraphByObjectIdWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.traverseThreatIntelFact); delegate.handle(new TraverseByObjectIdRequest()); }
@Test public void testTraverseGraphByObjectIdWithoutObject() throws Exception { TraverseByObjectIdRequest request = new TraverseByObjectIdRequest().setId(UUID.randomUUID()); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission((ObjectRecord) isNull()); try { delegate.handle(request); fail(); } catch (AccessDeniedException ignored) { verify(objectFactDao).getObject(request.getId()); } }
@Test(expected = AccessDeniedException.class) public void testTraverseGraphByObjectTypeValueWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.traverseThreatIntelFact); delegate.handle(new TraverseByObjectTypeValueRequest()); }
@Test(expected = InvalidArgumentException.class) public void testTraverseGraphByObjectTypeValueWithoutObjectType() throws Exception { TraverseByObjectTypeValueRequest request = new TraverseByObjectTypeValueRequest().setType("type").setValue("value"); doThrow(InvalidArgumentException.class).when(objectTypeHandler).assertObjectTypeExists(request.getType(), "type"); delegate.handle(request); }
@Test public void testTraverseGraphByObjectTypeValueWithoutObject() throws Exception { TraverseByObjectTypeValueRequest request = new TraverseByObjectTypeValueRequest().setType("type").setValue("value"); when(objectManager.getObjectType(request.getType())).thenReturn(new ObjectTypeEntity()); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission((ObjectRecord) isNull()); try { delegate.handle(request); fail(); } catch (AccessDeniedException ignored) { verify(objectTypeHandler).assertObjectTypeExists(request.getType(), "type"); verify(objectFactDao).getObject(request.getType(), request.getValue()); } }
@Test(expected = AccessDeniedException.class) public void testTraverseGraphByObjectSearchWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.traverseThreatIntelFact); delegate.handle(new TraverseByObjectSearchRequest()); }
@Test public void testTraverseGraphByObjectSearchWithoutSearchResult() throws Exception { TraverseByObjectSearchRequest request = new TraverseByObjectSearchRequest(); when(objectSearch.handle(request)).thenReturn(StreamingResultSet.<Object>builder().build()); ResultSet<?> result = delegate.handle(request); assertFalse(result.iterator().hasNext()); }