CompletableFuture<String> instanceIdFuture = getAwsInstanceId(asyncHttpClientHelper);
private Pair<CompletableFuture<String>, AsyncResponseHandler<String>> executeGetAwsInstanceIdAndExtractHandler() { CompletableFuture<String> cf = AwsUtil.getAwsInstanceId(asyncClientMock); verify(asyncClientMock).getRequestBuilder(AMAZON_METADATA_INSTANCE_ID_URL, HttpMethod.GET); ArgumentCaptor<AsyncResponseHandler> handlerArgCaptor = ArgumentCaptor.forClass(AsyncResponseHandler.class); verify(asyncClientMock).executeAsyncHttpRequest(eq(awsInstanceIdRequestBuilderWrapperMock), handlerArgCaptor.capture()); AsyncResponseHandler<String> handler = handlerArgCaptor.getValue(); return Pair.of(cf, handler); }
@Test public void getAppInfoFutureWithAwsInfo_with_all_args_uses_data_from_getAwsRegion_and_getAwsInstanceId_to_build_result() { // given String appId = "appid-" + UUID.randomUUID().toString(); String environment = "environment-" + UUID.randomUUID().toString(); String expectedDataCenter = AwsUtil.getAwsRegion(asyncClientMock).join(); String expectedInstanceId = AwsUtil.getAwsInstanceId(asyncClientMock).join(); // when AppInfo result = AwsUtil.getAppInfoFutureWithAwsInfo(appId, environment, asyncClientMock).join(); // then assertThat(result.appId()).isEqualTo(appId); assertThat(result.environment()).isEqualTo(environment); assertThat(result.dataCenter()).isEqualTo(expectedDataCenter); assertThat(result.instanceId()).isEqualTo(expectedInstanceId); }
@Test public void getAppInfoFutureWithAwsInfo_with_minimal_args_delegates_to_kitchen_sink_overload_method() { // given String appId = "appid-" + UUID.randomUUID().toString(); String environment = "environment-" + UUID.randomUUID().toString(); String expectedDataCenter = AwsUtil.getAwsRegion(asyncClientMock).join(); String expectedInstanceId = AwsUtil.getAwsInstanceId(asyncClientMock).join(); setAppIdAndEnvironemntSystemProperties(appId, environment); // when AppInfo result = AwsUtil.getAppInfoFutureWithAwsInfo(asyncClientMock).join(); // then assertThat(result.appId()).isEqualTo(appId); assertThat(result.environment()).isEqualTo(environment); assertThat(result.dataCenter()).isEqualTo(expectedDataCenter); assertThat(result.instanceId()).isEqualTo(expectedInstanceId); }