package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataSample1;
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataSample2;
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableRandomSampleGenerator;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.Test;

import com.oguerreiro.resilient.web.rest.TestUtil;

class InputDataTest {

  @Test
  void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(InputData.class);
    InputData inputData1 = getInputDataSample1();
    InputData inputData2 = new InputData();
    assertThat(inputData1).isNotEqualTo(inputData2);

    inputData2.setId(inputData1.getId());
    assertThat(inputData1).isEqualTo(inputData2);

    inputData2 = getInputDataSample2();
    assertThat(inputData1).isNotEqualTo(inputData2);
  }

  @Test
  void inputDataTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    InputData inputDataBack = getInputDataRandomSampleGenerator();

    inputData.addInputData(inputDataBack);
    assertThat(inputData.getInputData()).containsOnly(inputDataBack);
    assertThat(inputDataBack.getSourceInputData()).isEqualTo(inputData);

    inputData.removeInputData(inputDataBack);
    assertThat(inputData.getInputData()).doesNotContain(inputDataBack);
    assertThat(inputDataBack.getSourceInputData()).isNull();

    inputData.inputData(new HashSet<>(Set.of(inputDataBack)));
    assertThat(inputData.getInputData()).containsOnly(inputDataBack);
    assertThat(inputDataBack.getSourceInputData()).isEqualTo(inputData);

    inputData.setInputData(new HashSet<>());
    assertThat(inputData.getInputData()).doesNotContain(inputDataBack);
    assertThat(inputDataBack.getSourceInputData()).isNull();
  }

  @Test
  void variableTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    Variable variableBack = getVariableRandomSampleGenerator();

    inputData.setVariable(variableBack);
    assertThat(inputData.getVariable()).isEqualTo(variableBack);

    inputData.variable(null);
    assertThat(inputData.getVariable()).isNull();
  }

  @Test
  void periodTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    Period periodBack = getPeriodRandomSampleGenerator();

    inputData.setPeriod(periodBack);
    assertThat(inputData.getPeriod()).isEqualTo(periodBack);

    inputData.period(null);
    assertThat(inputData.getPeriod()).isNull();
  }

  @Test
  void sourceUnitTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    Unit unitBack = getUnitRandomSampleGenerator();

    inputData.setSourceUnit(unitBack);
    assertThat(inputData.getSourceUnit()).isEqualTo(unitBack);

    inputData.sourceUnit(null);
    assertThat(inputData.getSourceUnit()).isNull();
  }

  @Test
  void unitTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    Unit unitBack = getUnitRandomSampleGenerator();

    inputData.setUnit(unitBack);
    assertThat(inputData.getUnit()).isEqualTo(unitBack);

    inputData.unit(null);
    assertThat(inputData.getUnit()).isNull();
  }

  @Test
  void ownerTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    Organization organizationBack = getOrganizationRandomSampleGenerator();

    inputData.setOwner(organizationBack);
    assertThat(inputData.getOwner()).isEqualTo(organizationBack);

    inputData.owner(null);
    assertThat(inputData.getOwner()).isNull();
  }

  @Test
  void sourceInputDataTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    InputData inputDataBack = getInputDataRandomSampleGenerator();

    inputData.setSourceInputData(inputDataBack);
    assertThat(inputData.getSourceInputData()).isEqualTo(inputDataBack);

    inputData.sourceInputData(null);
    assertThat(inputData.getSourceInputData()).isNull();
  }

  @Test
  void sourceInputDataUploadTest() {
    InputData inputData = getInputDataRandomSampleGenerator();
    InputDataUpload inputDataUploadBack = getInputDataUploadRandomSampleGenerator();

    inputData.setSourceInputDataUpload(inputDataUploadBack);
    assertThat(inputData.getSourceInputDataUpload()).isEqualTo(inputDataUploadBack);

    inputData.sourceInputDataUpload(null);
    assertThat(inputData.getSourceInputDataUpload()).isNull();
  }
}
