@Test public void testListEnvironments() throws Exception { when(environmentRepository.listEnvironments(cluster, null)) .thenReturn(Collections.singletonList(environment)); final ListEnvironmentsResponse response = api.listEnvironments(request); verify(apiModelMapper).toModelCluster(clusterWrapper); verify(environmentRepository).listEnvironments(cluster, null); assertThat(response.getEnvironmentIds().size()).isEqualTo(1); assertThat(response.getEnvironmentIds().get(0)).isEqualTo(environmentIdWrapper); }
@Test public void testListEnvironmentsEmptyResult() throws Exception { when(environmentRepository.listEnvironments(cluster, null)).thenReturn(Collections.emptyList()); final ListEnvironmentsResponse response = api.listEnvironments(request); verify(apiModelMapper).toModelCluster(clusterWrapper); verify(environmentRepository).listEnvironments(cluster, null); verify(apiModelMapper, never()).toWrapperEnvironmentId(any()); assertThat(response.getEnvironmentIds().size()).isEqualTo(0); }
@Override @SneakyThrows // TODO add checked exception handling public ManagerOutput handleRequest(ManagerInput input, Context context) { log.debug("Manager request: {}", input); ListEnvironmentsResponse r = data.listEnvironments( ListEnvironmentsRequest.builder().cluster(input.getCluster()).build()); List<EnvironmentId> environments = r.getEnvironmentIds(); ClusterSnapshot state = ecs.snapshotState(input.getCluster().getClusterName()); Stream<CompletableFuture<SchedulerOutput>> pendingRequests = environments .stream() .map(environmentId -> scheduler.callAsync(new SchedulerInput(state, environmentId))); List<SchedulerOutput> outputs = pendingRequests.collect(CompletableFutures.joinList()).join(); return new ManagerOutput(input.getCluster(), outputs); } }
@Test public void testListEnvironments() throws Exception { dataService.createEnvironment( models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build()); dataService.createEnvironment( models.createEnvironmentRequest().environmentId(createdEnvironmentId3).build()); final ListEnvironmentsResponse listEnvironmentsResponse = dataService.listEnvironments( models .listEnvironmentsRequest() .cluster(models.cluster().build()) .environmentNamePrefix(null) .build()); assertThat(listEnvironmentsResponse.getEnvironmentIds()) .isEqualTo(Arrays.asList(createdEnvironmentId1, createdEnvironmentId3)); } }