// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }


import org.cloudfoundry.operations.CloudFoundryOperations;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;

	@Test
	public void testUseContainerIpFalse() {
		this.contextRunner.withUserConfiguration(CloudFoundryConfig.class)
				.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
						"spring.cloud.cloudfoundry.discovery.use-container-ip=false")
				.run((context) -> {
					DiscoveryClient discoveryClient = context.getBean(DiscoveryClient.class);
					assertThat(discoveryClient.getClass()).isEqualTo(CloudFoundryAppServiceDiscoveryClient.class);
				});
	}

	@Test
	public void testUseContainerIpTrue() {
		this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
				"spring.cloud.cloudfoundry.discovery.use-container-ip=true").run((context) -> {
					DiscoveryClient discoveryClient = context.getBean(DiscoveryClient.class);
					assertThat(discoveryClient.getClass()).isEqualTo(SimpleDnsBasedDiscoveryClient.class);
				});
	}

	@Configuration(proxyBeanMethods = false)
	public static class CloudFoundryConfig {

		@Bean
		public CloudFoundryOperations cloudFoundryOperations() {
			return Mockito.mock(CloudFoundryOperations.class);
		}

		@Bean
// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }


// Path: spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfigurationTest.java
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;


	@Test
	public void testUseContainerIpFalse() {
		this.contextRunner.withUserConfiguration(CloudFoundryConfig.class)
				.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
						"spring.cloud.cloudfoundry.discovery.use-container-ip=false")
				.run((context) -> {
					DiscoveryClient discoveryClient = context.getBean(DiscoveryClient.class);
					assertThat(discoveryClient.getClass()).isEqualTo(CloudFoundryAppServiceDiscoveryClient.class);
				});
	}

	@Test
	public void testUseContainerIpTrue() {
		this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
				"spring.cloud.cloudfoundry.discovery.use-container-ip=true").run((context) -> {
					DiscoveryClient discoveryClient = context.getBean(DiscoveryClient.class);
					assertThat(discoveryClient.getClass()).isEqualTo(SimpleDnsBasedDiscoveryClient.class);
				});
	}

	@Configuration(proxyBeanMethods = false)
	public static class CloudFoundryConfig {

		@Bean
		public CloudFoundryOperations cloudFoundryOperations() {
			return Mockito.mock(CloudFoundryOperations.class);
		}

		@Bean
		public CloudFoundryService cloudFoundryService() {