// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java
// public final class UpdateApplicationInstanceHealth {
// 
// 	private final String id;
// 	private final Status healthStatus;
// 
// 	public UpdateApplicationInstanceHealth(String id, Status healthStatus) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(healthStatus, "healthStatus must not be null!");
// 
// 		this.id = id;
// 		this.healthStatus = healthStatus;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Status getHealthStatus() {
// 		return this.healthStatus;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java
// public class ApplicationInstanceDeleted extends ApplicationEvent {
// 
// 	public ApplicationInstanceDeleted(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// 	public ApplicationInstance getApplicationInstance() {
// 		return (ApplicationInstance) this.source;
// 	}
// 
// }


import java.net.URI;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted;
import org.springframework.boot.actuate.health.Status;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.verify;
import static org.mockito.BDDMockito.when;
		assertThat(applicationInstances).isNotEmpty();
	}

	@Test
	public void shouldUpdateTheHealthOfAnApplicationInstance() {
		when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a"));
		when(this.repository.save(any(ApplicationInstance.class)))
				.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));

		UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP);
		this.service.updateApplicationInstanceHealth(command);

		verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture());
		ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue();
		assertThat(applicationInstance.getId()).isEqualTo("a-1");
	}

	@Test
	public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() {
		when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a"));
		when(this.repository.save(any(ApplicationInstance.class)))
				.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));

		Links links = new Links(new Link("http://localhost:8080/actuator/health", "health"));
		UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links);
		this.service.updateActuatorEndpoints(command);

		verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture());
		ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue();
		assertThat(applicationInstance.getId()).isEqualTo("a-1");
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java
// public final class UpdateApplicationInstanceHealth {
// 
// 	private final String id;
// 	private final Status healthStatus;
// 
// 	public UpdateApplicationInstanceHealth(String id, Status healthStatus) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(healthStatus, "healthStatus must not be null!");
// 
// 		this.id = id;
// 		this.healthStatus = healthStatus;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Status getHealthStatus() {
// 		return this.healthStatus;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java
// public class ApplicationInstanceDeleted extends ApplicationEvent {
// 
// 	public ApplicationInstanceDeleted(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// 	public ApplicationInstance getApplicationInstance() {
// 		return (ApplicationInstance) this.source;
// 	}
// 
// }


// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
import java.net.URI;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted;
import org.springframework.boot.actuate.health.Status;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.verify;
import static org.mockito.BDDMockito.when;

		assertThat(applicationInstances).isNotEmpty();
	}

	@Test
	public void shouldUpdateTheHealthOfAnApplicationInstance() {
		when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a"));
		when(this.repository.save(any(ApplicationInstance.class)))
				.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));

		UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP);
		this.service.updateApplicationInstanceHealth(command);

		verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture());
		ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue();
		assertThat(applicationInstance.getId()).isEqualTo("a-1");
	}

	@Test
	public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() {
		when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a"));
		when(this.repository.save(any(ApplicationInstance.class)))
				.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));

		Links links = new Links(new Link("http://localhost:8080/actuator/health", "health"));
		UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links);
		this.service.updateActuatorEndpoints(command);

		verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture());
		ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue();
		assertThat(applicationInstance.getId()).isEqualTo("a-1");
		assertThat(applicationInstance.getActuatorEndpoints()).hasSize(1);