// 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/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java
// public class ApplicationInstanceHealthUpdated extends ApplicationEvent {
// 
// 	public ApplicationInstanceHealthUpdated(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// }


import java.net.URI;
import org.junit.Test;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated;
import org.springframework.boot.actuate.health.Status;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import static org.assertj.core.api.Assertions.assertThat;
	public void undefinedActuatorEndpointWillReturnEmptyOptional() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a",
				URI.create("http://localhost:8080"),
				new Links(new Link("http://localhost:8080/actuator/health", "health")));

		assertThat(applicationInstance.hasActuatorEndpointFor("not-defined-endpoint")).isFalse();
		assertThat(applicationInstance.getActuatorEndpoint("not-defined-endpoint")).isEmpty();
	}

	@Test
	public void definedActuatorEndpointWillReturnLink() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a",
				URI.create("http://localhost:8080"),
				new Links(new Link("http://localhost:8080/actuator/health", "health")));

		assertThat(applicationInstance.hasActuatorEndpointFor("health")).isTrue();
		assertThat(applicationInstance.getActuatorEndpoint("health")).isNotEmpty();
		assertThat(applicationInstance.getActuatorEndpoint("health"))
				.get().extracting(Link::getHref).isEqualTo("http://localhost:8080/actuator/health");
	}

	@Test
	public void canNotBeDeletedMoreThanOnce() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
		applicationInstance.markChangesAsCommitted();
		applicationInstance.delete();
		applicationInstance.delete();

		assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.DELETED);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
// 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/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java
// public class ApplicationInstanceHealthUpdated extends ApplicationEvent {
// 
// 	public ApplicationInstanceHealthUpdated(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// }


// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceTests.java
import java.net.URI;
import org.junit.Test;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated;
import org.springframework.boot.actuate.health.Status;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import static org.assertj.core.api.Assertions.assertThat;

	public void undefinedActuatorEndpointWillReturnEmptyOptional() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a",
				URI.create("http://localhost:8080"),
				new Links(new Link("http://localhost:8080/actuator/health", "health")));

		assertThat(applicationInstance.hasActuatorEndpointFor("not-defined-endpoint")).isFalse();
		assertThat(applicationInstance.getActuatorEndpoint("not-defined-endpoint")).isEmpty();
	}

	@Test
	public void definedActuatorEndpointWillReturnLink() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a",
				URI.create("http://localhost:8080"),
				new Links(new Link("http://localhost:8080/actuator/health", "health")));

		assertThat(applicationInstance.hasActuatorEndpointFor("health")).isTrue();
		assertThat(applicationInstance.getActuatorEndpoint("health")).isNotEmpty();
		assertThat(applicationInstance.getActuatorEndpoint("health"))
				.get().extracting(Link::getHref).isEqualTo("http://localhost:8080/actuator/health");
	}

	@Test
	public void canNotBeDeletedMoreThanOnce() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
		applicationInstance.markChangesAsCommitted();
		applicationInstance.delete();
		applicationInstance.delete();

		assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.DELETED);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
		assertThat(applicationInstance.getUncommittedChanges().get(0)).isInstanceOf(ApplicationInstanceDeleted.class);