package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.MetadataPropertyTestSamples.*;
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 MetadataPropertyTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(MetadataProperty.class);
        MetadataProperty metadataProperty1 = getMetadataPropertySample1();
        MetadataProperty metadataProperty2 = new MetadataProperty();
        assertThat(metadataProperty1).isNotEqualTo(metadataProperty2);

        metadataProperty2.setId(metadataProperty1.getId());
        assertThat(metadataProperty1).isEqualTo(metadataProperty2);

        metadataProperty2 = getMetadataPropertySample2();
        assertThat(metadataProperty1).isNotEqualTo(metadataProperty2);
    }

    @Test
    void organizationTypeTest() {
        MetadataProperty metadataProperty = getMetadataPropertyRandomSampleGenerator();
        OrganizationType organizationTypeBack = getOrganizationTypeRandomSampleGenerator();

        metadataProperty.addOrganizationType(organizationTypeBack);
        assertThat(metadataProperty.getOrganizationTypes()).containsOnly(organizationTypeBack);
        assertThat(organizationTypeBack.getMetadataProperties()).containsOnly(metadataProperty);

        metadataProperty.removeOrganizationType(organizationTypeBack);
        assertThat(metadataProperty.getOrganizationTypes()).doesNotContain(organizationTypeBack);
        assertThat(organizationTypeBack.getMetadataProperties()).doesNotContain(metadataProperty);

        metadataProperty.organizationTypes(new HashSet<>(Set.of(organizationTypeBack)));
        assertThat(metadataProperty.getOrganizationTypes()).containsOnly(organizationTypeBack);
        assertThat(organizationTypeBack.getMetadataProperties()).containsOnly(metadataProperty);

        metadataProperty.setOrganizationTypes(new HashSet<>());
        assertThat(metadataProperty.getOrganizationTypes()).doesNotContain(organizationTypeBack);
        assertThat(organizationTypeBack.getMetadataProperties()).doesNotContain(metadataProperty);
    }
}
