### Question:
BaseClientExecutionValidator implements ClientValidator<AbstractClientExecution> { @Override public List<Exception> validate(AbstractClientExecution value) { List<Exception> exceptions = new ArrayList<Exception>(); if (value.getDataSource() != null && value.getDataSource() instanceof ClientReference) { validate(value.getDataSource().getUri(), exceptions); } return exceptions; }  @Override List<Exception> validate(AbstractClientExecution value);  }### Answer:
@Test public void validate_uriIsNull_notValid() { when(dataSourceReference.getUri()).thenReturn(null); List<Exception> exceptions = validator.validate(execution); assertListContainsMandatoryParameterNotFoundException(exceptions); }
@Test public void validate_dataSourceUriPointsToFolder_notValid() { mockErrorDescriptorBuilder(QUERY_DATASOURCE_TYPE_NOT_SUPPORTED); when(repositoryService.folderExists(any(ExecutionContext.class), eq(DATA_SOURCE_URI))).thenReturn(true); List<Exception> exceptions = validator.validate(execution); assertExceptionsContainErrorCode(exceptions, QUERY_DATASOURCE_TYPE_NOT_SUPPORTED.toString()); }
@Test public void validate_dataSourceNotFound_notValid() { mockErrorDescriptorBuilder(QUERY_DATASOURCE_NOT_FOUND); when(repositoryService.getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))).thenReturn(null); List<Exception> exceptions = validator.validate(execution); assertExceptionsContainErrorCode(exceptions, QUERY_DATASOURCE_NOT_FOUND.toString()); }
@Test public void validate_repositoryServiceThrowsAccessDeniedException_notValid() { mockErrorDescriptorBuilder(QUERY_DATASOURCE_ACCESS_DENIED); when(repositoryService.getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))) .thenThrow(mock(AccessDeniedException.class)); List<Exception> exceptions = validator.validate(execution); assertExceptionsContainErrorCode(exceptions, QUERY_DATASOURCE_ACCESS_DENIED.toString()); }
@Test public void validate_resourceConverterNotFound_invalid() { mockErrorDescriptorBuilder(QUERY_DATASOURCE_TYPE_NOT_SUPPORTED); when(repositoryService .getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))) .thenReturn(mock(DataSource.class)); when(resourceConverterProvider.getToClientConverter(any(Resource.class))).thenReturn(null); List<Exception> exceptions = validator.validate(execution); assertExceptionsContainErrorCode(exceptions, QUERY_DATASOURCE_TYPE_NOT_SUPPORTED.toString()); }
@Test public void validate_notClientReferenceableType_invalid() { mockErrorDescriptorBuilder(QUERY_DATASOURCE_TYPE_NOT_SUPPORTED); when(repositoryService .getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))) .thenReturn(mock(DataSource.class)); doReturn(ClientDashboard.class).when(resourceConverterProvider).getClientTypeClass(CLIENT_RESOURCE_TYPE); List<Exception> exceptions = validator.validate(execution); assertExceptionsContainErrorCode(exceptions, QUERY_DATASOURCE_TYPE_NOT_SUPPORTED.toString()); }
@Test public void validate_dataSourceFound_valid() { when(repositoryService .getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))) .thenReturn(mock(DataSource.class)); doReturn(ClientDomain.class).when(resourceConverterProvider).getClientTypeClass(CLIENT_RESOURCE_TYPE); List<Exception> exceptions = validator.validate(execution); assertTrue(exceptions.isEmpty()); }
@Test(expected = Exception.class) public void validate_repositoryThrowsUnhandledException_exceptionExpected() { when(repositoryService .getResource(any(ExecutionContext.class), eq(DATA_SOURCE_URI))) .thenThrow(new Exception("Some Unexpected Exception")); validator.validate(execution); }