// 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/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java
// @ConfigurationProperties(prefix = "spring.cloud.cloudfoundry.discovery")
// public class CloudFoundryDiscoveryProperties {
// 
// 	/**
// 	 * Flag to indicate that discovery is enabled.
// 	 */
// 	private boolean enabled = true;
// 
// 	/**
// 	 * Frequency in milliseconds of poll for heart beat. The client will poll on this
// 	 * frequency and broadcast a list of service ids.
// 	 */
// 	private long heartbeatFrequency = 5000;
// 
// 	/**
// 	 * Port to use when no port is defined by service discovery.
// 	 */
// 	private int defaultServerPort = 80;
// 
// 	/**
// 	 * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
// 	 * available clients.
// 	 */
// 	private int order = 0;
// 
// 	/**
// 	 * Default internal domain when configured to use Native DNS service discovery.
// 	 */
// 	private String internalDomain = "apps.internal";
// 
// 	public boolean isEnabled() {
// 		return this.enabled;
// 	}
// 
// 	public void setEnabled(boolean enabled) {
// 		this.enabled = enabled;
// 	}
// 
// 	public long getHeartbeatFrequency() {
// 		return this.heartbeatFrequency;
// 	}
// 
// 	public void setHeartbeatFrequency(long heartbeatFrequency) {
// 		this.heartbeatFrequency = heartbeatFrequency;
// 	}
// 
// 	public int getDefaultServerPort() {
// 		return this.defaultServerPort;
// 	}
// 
// 	public void setDefaultServerPort(int defaultServerPort) {
// 		this.defaultServerPort = defaultServerPort;
// 	}
// 
// 	public int getOrder() {
// 		return this.order;
// 	}
// 
// 	public void setOrder(int order) {
// 		this.order = order;
// 	}
// 
// 	public String getInternalDomain() {
// 		return this.internalDomain;
// 	}
// 
// 	public void setInternalDomain(String internalDomain) {
// 		this.internalDomain = internalDomain;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		// @formatter:off
// 		return new ToStringCreator(this)
// 			.append("enabled", enabled)
// 			.append("heartbeatFrequency", heartbeatFrequency)
// 			.append("defaultServerPort", defaultServerPort)
// 			.append("order", order)
// 			.append("internalDomain", internalDomain)
// 			.toString();
// 		// @formatter:on
// 	}
// 
// }


import java.util.UUID;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.applications.ApplicationDetail;
import org.cloudfoundry.operations.applications.ApplicationSummary;
import org.cloudfoundry.operations.applications.Applications;
import org.cloudfoundry.operations.applications.InstanceDetail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/*
 * Copyright 2019-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.cloudfoundry.discovery.reactive;





/**
 * @author Tim Ysewyn
 */
@ExtendWith(MockitoExtension.class)
class CloudFoundryNativeReactiveDiscoveryClientTests {

	@Mock
	private CloudFoundryOperations operations;

	@Mock
	private CloudFoundryService svc;

	@Mock
	private CloudFoundryDiscoveryProperties properties;

	@InjectMocks
	private CloudFoundryNativeReactiveDiscoveryClient client;

	@Test
	public void verifyDefaults() {
		when(properties.getOrder()).thenReturn(0);
		assertThat(client.description()).isEqualTo("CF Reactive Service Discovery Client");
		assertThat(client.getOrder()).isEqualTo(0);
	}

	@Test
	public void shouldReturnFluxOfServices() {
		Applications apps = mock(Applications.class);
// 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/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java
// @ConfigurationProperties(prefix = "spring.cloud.cloudfoundry.discovery")
// public class CloudFoundryDiscoveryProperties {
// 
// 	/**
// 	 * Flag to indicate that discovery is enabled.
// 	 */
// 	private boolean enabled = true;
// 
// 	/**
// 	 * Frequency in milliseconds of poll for heart beat. The client will poll on this
// 	 * frequency and broadcast a list of service ids.
// 	 */
// 	private long heartbeatFrequency = 5000;
// 
// 	/**
// 	 * Port to use when no port is defined by service discovery.
// 	 */
// 	private int defaultServerPort = 80;
// 
// 	/**
// 	 * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
// 	 * available clients.
// 	 */
// 	private int order = 0;
// 
// 	/**
// 	 * Default internal domain when configured to use Native DNS service discovery.
// 	 */
// 	private String internalDomain = "apps.internal";
// 
// 	public boolean isEnabled() {
// 		return this.enabled;
// 	}
// 
// 	public void setEnabled(boolean enabled) {
// 		this.enabled = enabled;
// 	}
// 
// 	public long getHeartbeatFrequency() {
// 		return this.heartbeatFrequency;
// 	}
// 
// 	public void setHeartbeatFrequency(long heartbeatFrequency) {
// 		this.heartbeatFrequency = heartbeatFrequency;
// 	}
// 
// 	public int getDefaultServerPort() {
// 		return this.defaultServerPort;
// 	}
// 
// 	public void setDefaultServerPort(int defaultServerPort) {
// 		this.defaultServerPort = defaultServerPort;
// 	}
// 
// 	public int getOrder() {
// 		return this.order;
// 	}
// 
// 	public void setOrder(int order) {
// 		this.order = order;
// 	}
// 
// 	public String getInternalDomain() {
// 		return this.internalDomain;
// 	}
// 
// 	public void setInternalDomain(String internalDomain) {
// 		this.internalDomain = internalDomain;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		// @formatter:off
// 		return new ToStringCreator(this)
// 			.append("enabled", enabled)
// 			.append("heartbeatFrequency", heartbeatFrequency)
// 			.append("defaultServerPort", defaultServerPort)
// 			.append("order", order)
// 			.append("internalDomain", internalDomain)
// 			.toString();
// 		// @formatter:on
// 	}
// 
// }


// Path: spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/reactive/CloudFoundryNativeReactiveDiscoveryClientTests.java
import java.util.UUID;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.applications.ApplicationDetail;
import org.cloudfoundry.operations.applications.ApplicationSummary;
import org.cloudfoundry.operations.applications.Applications;
import org.cloudfoundry.operations.applications.InstanceDetail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/*
 * Copyright 2019-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.cloudfoundry.discovery.reactive;





/**
 * @author Tim Ysewyn
 */
@ExtendWith(MockitoExtension.class)
class CloudFoundryNativeReactiveDiscoveryClientTests {

	@Mock
	private CloudFoundryOperations operations;

	@Mock
	private CloudFoundryService svc;

	@Mock
	private CloudFoundryDiscoveryProperties properties;

	@InjectMocks
	private CloudFoundryNativeReactiveDiscoveryClient client;

	@Test
	public void verifyDefaults() {
		when(properties.getOrder()).thenReturn(0);
		assertThat(client.description()).isEqualTo("CF Reactive Service Discovery Client");
		assertThat(client.getOrder()).isEqualTo(0);
	}

	@Test
	public void shouldReturnFluxOfServices() {
		Applications apps = mock(Applications.class);
		when(operations.applications()).thenReturn(apps);