### Question:
AWSLambdaStreamEntry implements RequestStreamHandler { protected void processAllResourcePools(SchedulerRequest request) { String endpointURL = getEnvironmentVar(ENV_ENDPOINT_URL); String rawLaunchLambdaList = getEnvironmentVar(ENV_RESOURCEPOOL_LAMBDA_LAUNCH_LIST); String resourcePoolEndpointPath = getEnvironmentVar(ENV_RESOURCEPOOL_ENDPOINT_PATH); HttpObjectClient<ResourcePool> resourcePoolClient = objectClientFactory.createClient( environmentLookupUtils.getAPIEndpointURL(endpointURL, request.getStageId(), resourcePoolEndpointPath), ResourcePool.class); List<String> lambdasToLaunch = Arrays.stream(StringUtils.split(rawLaunchLambdaList, ",")) .map(String::trim).collect(Collectors.toList()); try { DataObjectResponse<ResourcePool> response = resourcePoolClient.getObjects(new ArrayList<>()); if(response.isError()) { logger.error("Failed to get all ResourcePools: {}", response.getErrorResponse().getServerStackTrace()); return; } response.getAll().forEach( resourcePool -> launchResourcePoolLambda(lambdasToLaunch, resourcePool, request) ); } catch (Throwable t) { throw new RuntimeException("Error processing resource pools.", t); } } AWSLambdaStreamEntry(AWSLambdaFactory awsLambdaFactory, HttpObjectClientFactory objectClientFactory);  AWSLambdaStreamEntry(); void handleRequest(InputStream inputStream, OutputStream outputStream, Context context); AWSLambdaStreamEntry setAwsLambdaFactory(AWSLambdaFactory awsLambdaFactory); AWSLambdaStreamEntry setEnvironmentFacade(EnvironmentFacade environmentFacade); AWSLambdaStreamEntry setEnvironmentLookupUtils(EnvironmentLookupUtils environmentLookupUtils); static final String ENV_IDM_ENCRYPTED_PASS; static final String ENV_IDM_USER; static final String ENV_IDENTITY_URL; static final String ENV_ENDPOINT_URL; static final String ENV_RESOURCEPOOL_ENDPOINT_PATH; static final String ENV_RESOURCEPOOL_LAMBDA_LAUNCH_LIST; }### Answer:
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = ".*Missing environment var.*", dataProvider = "missingEnvVarProvider" ) public void testProcessAllResourcePoolsMissingEnvVar(String missingVar) { setupValidEnvironment(); environmentMap.remove(missingVar); streamEntry.processAllResourcePools(new SchedulerRequest()); }
@Test(dataProvider = "resourcePoolCountProvider") public void testProcessAllResourcePools(int count) { setupValidEnvironment(); doReturn(mockResourcePoolClient).when(mockObjectClientFactory).createClient(anyString(), eq(ResourcePool.class)); doReturn(createResponse(count, false)).when(mockResourcePoolClient).getObjects(anyList()); streamEntry.processAllResourcePools(new SchedulerRequest()); verify(mockAWSLambdaFactory, times(count)).create(); }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Error processing resource pools.*") public void testProcessAllResourcePoolsLambdaError() { setupValidEnvironment(); AWSLambda mockAwsLambda = mock(AWSLambda.class); doReturn(mockAwsLambda).when(mockAWSLambdaFactory).create(); doReturn(mockResourcePoolClient).when(mockObjectClientFactory).createClient(anyString(), eq(ResourcePool.class)); doReturn(createResponse(1, false)).when(mockResourcePoolClient).getObjects(anyList()); doThrow(new RuntimeException()).when(mockAwsLambda).invoke(any()); streamEntry.processAllResourcePools(new SchedulerRequest()); verify(mockAWSLambdaFactory, times(1)).create(); }
@Test public void testProcessAllResourcePoolsResponseError() { setupValidEnvironment(); doReturn(mockResourcePoolClient).when(mockObjectClientFactory).createClient(anyString(), eq(ResourcePool.class)); doReturn(createResponse(0, true)).when(mockResourcePoolClient).getObjects(anyList()); streamEntry.processAllResourcePools(new SchedulerRequest()); verify(mockAWSLambdaFactory, times(0)).create(); }