package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.MetadataPropertyTestSamples.*;
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.*;
import static com.oguerreiro.resilient.domain.OrganizationTypeTestSamples.*;
import static org.assertj.core.api.Assertions.assertThat;

import com.oguerreiro.resilient.web.rest.TestUtil;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;

class OrganizationTypeTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(OrganizationType.class);
        OrganizationType organizationType1 = getOrganizationTypeSample1();
        OrganizationType organizationType2 = new OrganizationType();
        assertThat(organizationType1).isNotEqualTo(organizationType2);

        organizationType2.setId(organizationType1.getId());
        assertThat(organizationType1).isEqualTo(organizationType2);

        organizationType2 = getOrganizationTypeSample2();
        assertThat(organizationType1).isNotEqualTo(organizationType2);
    }

    @Test
    void organizationTest() {
        OrganizationType organizationType = getOrganizationTypeRandomSampleGenerator();
        Organization organizationBack = getOrganizationRandomSampleGenerator();

        organizationType.addOrganization(organizationBack);
        assertThat(organizationType.getOrganizations()).containsOnly(organizationBack);
        assertThat(organizationBack.getOrganizationType()).isEqualTo(organizationType);

        organizationType.removeOrganization(organizationBack);
        assertThat(organizationType.getOrganizations()).doesNotContain(organizationBack);
        assertThat(organizationBack.getOrganizationType()).isNull();

        organizationType.organizations(new HashSet<>(Set.of(organizationBack)));
        assertThat(organizationType.getOrganizations()).containsOnly(organizationBack);
        assertThat(organizationBack.getOrganizationType()).isEqualTo(organizationType);

        organizationType.setOrganizations(new HashSet<>());
        assertThat(organizationType.getOrganizations()).doesNotContain(organizationBack);
        assertThat(organizationBack.getOrganizationType()).isNull();
    }

    @Test
    void metadataPropertiesTest() {
        OrganizationType organizationType = getOrganizationTypeRandomSampleGenerator();
        MetadataProperty metadataPropertyBack = getMetadataPropertyRandomSampleGenerator();

        organizationType.addMetadataProperties(metadataPropertyBack);
        assertThat(organizationType.getMetadataProperties()).containsOnly(metadataPropertyBack);

        organizationType.removeMetadataProperties(metadataPropertyBack);
        assertThat(organizationType.getMetadataProperties()).doesNotContain(metadataPropertyBack);

        organizationType.metadataProperties(new HashSet<>(Set.of(metadataPropertyBack)));
        assertThat(organizationType.getMetadataProperties()).containsOnly(metadataPropertyBack);

        organizationType.setMetadataProperties(new HashSet<>());
        assertThat(organizationType.getMetadataProperties()).doesNotContain(metadataPropertyBack);
    }
}
