package ch.unisg.executorpool;

import java.net.URI;
import java.util.Optional;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;

import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.executorpool.domain.ExecutorPool;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;

public class ExecutorPoolTest {

	private static final URI URI = null;

	@Test
	void addNewExecutorToExecutorPoolSuccess() {
		ExecutorPool executorPool = ExecutorPool.getExecutorPool();
		executorPool.getListOfExecutors().getValue().clear();
		ExecutorClass newExecutor = executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) ,
		new ExecutorTaskType("test-type"));

		assertThat(newExecutor.getExecutorTaskType().getValue()).isEqualTo("test-type");
		assertThat(executorPool.getListOfExecutors().getValue()).hasSize(1);
		assertThat(executorPool.getListOfExecutors().getValue().get(0)).isEqualTo(newExecutor);
	}

	@Test
	void retrieveExecutorSuccess() {
		ExecutorPool executorPool = ExecutorPool.getExecutorPool();
        executorPool.getListOfExecutors().getValue().clear();
		ExecutorClass newExecutor = executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type"));

		var retrievedExecutors = executorPool.getAllExecutorsByType(newExecutor.getExecutorTaskType());

        assertThat(retrievedExecutors.size()).isEqualTo(1);
		assertThat(retrievedExecutors.get(0)).isEqualTo(newExecutor);
	}

	@Test
	void retrieveExecutorFailure() {
		ExecutorPool executorPool = ExecutorPool.getExecutorPool();
        executorPool.getListOfExecutors().getValue().clear();
		executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type"));

		var fakeType = new ExecutorTaskType("fake-type");

		var retrievedExecutor = executorPool.getAllExecutorsByType(fakeType);

		assertThat(retrievedExecutor.size()).isEqualTo(0);
	}




}
