package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.InputDataUploadLogTestSamples.getInputDataUploadLogRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadSample1;
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadSample2;
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
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 InputDataUploadTest {

  @Test
  void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(InputDataUpload.class);
    InputDataUpload inputDataUpload1 = getInputDataUploadSample1();
    InputDataUpload inputDataUpload2 = new InputDataUpload();
    assertThat(inputDataUpload1).isNotEqualTo(inputDataUpload2);

    inputDataUpload2.setId(inputDataUpload1.getId());
    assertThat(inputDataUpload1).isEqualTo(inputDataUpload2);

    inputDataUpload2 = getInputDataUploadSample2();
    assertThat(inputDataUpload1).isNotEqualTo(inputDataUpload2);
  }

  @Test
  void inputDataTest() {
    InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
    InputData inputDataBack = getInputDataRandomSampleGenerator();

    inputDataUpload.addInputData(inputDataBack);
    assertThat(inputDataUpload.getInputData()).containsOnly(inputDataBack);
    assertThat(inputDataBack.getSourceInputDataUpload()).isEqualTo(inputDataUpload);

    inputDataUpload.removeInputData(inputDataBack);
    assertThat(inputDataUpload.getInputData()).doesNotContain(inputDataBack);
    assertThat(inputDataBack.getSourceInputDataUpload()).isNull();

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

    inputDataUpload.setInputData(new HashSet<>());
    assertThat(inputDataUpload.getInputData()).doesNotContain(inputDataBack);
    assertThat(inputDataBack.getSourceInputDataUpload()).isNull();
  }

  @Test
  void inputDataUploadLogTest() {
    InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
    InputDataUploadLog inputDataUploadLogBack = getInputDataUploadLogRandomSampleGenerator();

    inputDataUpload.addInputDataUploadLog(inputDataUploadLogBack);
    assertThat(inputDataUpload.getInputDataUploadLogs()).containsOnly(inputDataUploadLogBack);
    assertThat(inputDataUploadLogBack.getInputDataUpload()).isEqualTo(inputDataUpload);

    inputDataUpload.removeInputDataUploadLog(inputDataUploadLogBack);
    assertThat(inputDataUpload.getInputDataUploadLogs()).doesNotContain(inputDataUploadLogBack);
    assertThat(inputDataUploadLogBack.getInputDataUpload()).isNull();

    inputDataUpload.inputDataUploadLogs(new HashSet<>(Set.of(inputDataUploadLogBack)));
    assertThat(inputDataUpload.getInputDataUploadLogs()).containsOnly(inputDataUploadLogBack);
    assertThat(inputDataUploadLogBack.getInputDataUpload()).isEqualTo(inputDataUpload);

    inputDataUpload.setInputDataUploadLogs(new HashSet<>());
    assertThat(inputDataUpload.getInputDataUploadLogs()).doesNotContain(inputDataUploadLogBack);
    assertThat(inputDataUploadLogBack.getInputDataUpload()).isNull();
  }

  @Test
  void periodTest() {
    InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
    Period periodBack = getPeriodRandomSampleGenerator();

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

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

  @Test
  void ownerTest() {
    InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
    Organization organizationBack = getOrganizationRandomSampleGenerator();

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

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