// 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;
/*
 * Copyright 2015-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
 *
 *      http://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 be.ordina.msdashboard.applicationinstance;






/**
 * @author Tim Ysewyn
 */
public class ApplicationInstanceTests {

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

		assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.CREATED);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
	}

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

		assertThat(applicationInstance.getUncommittedChanges()).isEmpty();
	}

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

		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN);
	}

	@Test
	public void instanceShouldNotUpdateItsHealthStatusAgainIfNotChanged() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
		applicationInstance.markChangesAsCommitted();
		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN);

		applicationInstance.updateHealthStatus(Status.UP);
		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UP);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
		assertThat(applicationInstance.getUncommittedChanges().get(0))
// 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;

/*
 * Copyright 2015-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
 *
 *      http://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 be.ordina.msdashboard.applicationinstance;






/**
 * @author Tim Ysewyn
 */
public class ApplicationInstanceTests {

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

		assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.CREATED);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
	}

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

		assertThat(applicationInstance.getUncommittedChanges()).isEmpty();
	}

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

		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN);
	}

	@Test
	public void instanceShouldNotUpdateItsHealthStatusAgainIfNotChanged() {
		ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
		applicationInstance.markChangesAsCommitted();
		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN);

		applicationInstance.updateHealthStatus(Status.UP);
		assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UP);
		assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
		assertThat(applicationInstance.getUncommittedChanges().get(0))
				.isInstanceOf(ApplicationInstanceHealthUpdated.class);