package it.sw.pa.comune.artegna.web.rest;

import static it.sw.pa.comune.artegna.domain.ConfermaAsserts.*;
import static it.sw.pa.comune.artegna.web.rest.TestUtil.createUpdateProxyForBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import it.sw.pa.comune.artegna.IntegrationTest;
import it.sw.pa.comune.artegna.domain.Conferma;
import it.sw.pa.comune.artegna.domain.UtenteApp;
import it.sw.pa.comune.artegna.domain.enumeration.TipoConferma;
import it.sw.pa.comune.artegna.repository.ConfermaRepository;
import it.sw.pa.comune.artegna.service.ConfermaService;
import it.sw.pa.comune.artegna.service.dto.ConfermaDTO;
import it.sw.pa.comune.artegna.service.mapper.ConfermaMapper;
import jakarta.persistence.EntityManager;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link ConfermaResource} REST controller.
 */
@IntegrationTest
@ExtendWith(MockitoExtension.class)
@AutoConfigureMockMvc
@WithMockUser
class ConfermaResourceIT {

    private static final String DEFAULT_MOTIVO_CONFERMA = "AAAAAAAAAA";
    private static final String UPDATED_MOTIVO_CONFERMA = "BBBBBBBBBB";

    private static final TipoConferma DEFAULT_TIPO_CONFERMA = TipoConferma.CONFERMATA;
    private static final TipoConferma UPDATED_TIPO_CONFERMA = TipoConferma.RIFIUTATA;

    private static final String ENTITY_API_URL = "/api/confermas";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2L * Integer.MAX_VALUE));

    @Autowired
    private ObjectMapper om;

    @Autowired
    private ConfermaRepository confermaRepository;

    @Mock
    private ConfermaRepository confermaRepositoryMock;

    @Autowired
    private ConfermaMapper confermaMapper;

    @Mock
    private ConfermaService confermaServiceMock;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restConfermaMockMvc;

    private Conferma conferma;

    private Conferma insertedConferma;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Conferma createEntity() {
        return new Conferma().motivoConferma(DEFAULT_MOTIVO_CONFERMA).tipoConferma(DEFAULT_TIPO_CONFERMA);
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Conferma createUpdatedEntity() {
        return new Conferma().motivoConferma(UPDATED_MOTIVO_CONFERMA).tipoConferma(UPDATED_TIPO_CONFERMA);
    }

    @BeforeEach
    void initTest() {
        conferma = createEntity();
    }

    @AfterEach
    void cleanup() {
        if (insertedConferma != null) {
            confermaRepository.delete(insertedConferma);
            insertedConferma = null;
        }
    }

    @Test
    @Transactional
    void createConferma() throws Exception {
        long databaseSizeBeforeCreate = getRepositoryCount();
        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);
        var returnedConfermaDTO = om.readValue(
            restConfermaMockMvc
                .perform(
                    post(ENTITY_API_URL).with(csrf()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(confermaDTO))
                )
                .andExpect(status().isCreated())
                .andReturn()
                .getResponse()
                .getContentAsString(),
            ConfermaDTO.class
        );

        // Validate the Conferma in the database
        assertIncrementedRepositoryCount(databaseSizeBeforeCreate);
        var returnedConferma = confermaMapper.toEntity(returnedConfermaDTO);
        assertConfermaUpdatableFieldsEquals(returnedConferma, getPersistedConferma(returnedConferma));

        insertedConferma = returnedConferma;
    }

    @Test
    @Transactional
    void createConfermaWithExistingId() throws Exception {
        // Create the Conferma with an existing ID
        conferma.setId(1L);
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        long databaseSizeBeforeCreate = getRepositoryCount();

        // An entity with an existing ID cannot be created, so this API call must fail
        restConfermaMockMvc
            .perform(post(ENTITY_API_URL).with(csrf()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(confermaDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllConfermas() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(conferma.getId().intValue())))
            .andExpect(jsonPath("$.[*].motivoConferma").value(hasItem(DEFAULT_MOTIVO_CONFERMA)))
            .andExpect(jsonPath("$.[*].tipoConferma").value(hasItem(DEFAULT_TIPO_CONFERMA.toString())));
    }

    @SuppressWarnings({ "unchecked" })
    void getAllConfermasWithEagerRelationshipsIsEnabled() throws Exception {
        when(confermaServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>()));

        restConfermaMockMvc.perform(get(ENTITY_API_URL + "?eagerload=true")).andExpect(status().isOk());

        verify(confermaServiceMock, times(1)).findAllWithEagerRelationships(any());
    }

    @SuppressWarnings({ "unchecked" })
    void getAllConfermasWithEagerRelationshipsIsNotEnabled() throws Exception {
        when(confermaServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>()));

        restConfermaMockMvc.perform(get(ENTITY_API_URL + "?eagerload=false")).andExpect(status().isOk());
        verify(confermaRepositoryMock, times(1)).findAll(any(Pageable.class));
    }

    @Test
    @Transactional
    void getConferma() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get the conferma
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL_ID, conferma.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(conferma.getId().intValue()))
            .andExpect(jsonPath("$.motivoConferma").value(DEFAULT_MOTIVO_CONFERMA))
            .andExpect(jsonPath("$.tipoConferma").value(DEFAULT_TIPO_CONFERMA.toString()));
    }

    @Test
    @Transactional
    void getConfermasByIdFiltering() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        Long id = conferma.getId();

        defaultConfermaFiltering("id.equals=" + id, "id.notEquals=" + id);

        defaultConfermaFiltering("id.greaterThanOrEqual=" + id, "id.greaterThan=" + id);

        defaultConfermaFiltering("id.lessThanOrEqual=" + id, "id.lessThan=" + id);
    }

    @Test
    @Transactional
    void getAllConfermasByMotivoConfermaIsEqualToSomething() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where motivoConferma equals to
        defaultConfermaFiltering("motivoConferma.equals=" + DEFAULT_MOTIVO_CONFERMA, "motivoConferma.equals=" + UPDATED_MOTIVO_CONFERMA);
    }

    @Test
    @Transactional
    void getAllConfermasByMotivoConfermaIsInShouldWork() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where motivoConferma in
        defaultConfermaFiltering(
            "motivoConferma.in=" + DEFAULT_MOTIVO_CONFERMA + "," + UPDATED_MOTIVO_CONFERMA,
            "motivoConferma.in=" + UPDATED_MOTIVO_CONFERMA
        );
    }

    @Test
    @Transactional
    void getAllConfermasByMotivoConfermaIsNullOrNotNull() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where motivoConferma is not null
        defaultConfermaFiltering("motivoConferma.specified=true", "motivoConferma.specified=false");
    }

    @Test
    @Transactional
    void getAllConfermasByMotivoConfermaContainsSomething() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where motivoConferma contains
        defaultConfermaFiltering(
            "motivoConferma.contains=" + DEFAULT_MOTIVO_CONFERMA,
            "motivoConferma.contains=" + UPDATED_MOTIVO_CONFERMA
        );
    }

    @Test
    @Transactional
    void getAllConfermasByMotivoConfermaNotContainsSomething() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where motivoConferma does not contain
        defaultConfermaFiltering(
            "motivoConferma.doesNotContain=" + UPDATED_MOTIVO_CONFERMA,
            "motivoConferma.doesNotContain=" + DEFAULT_MOTIVO_CONFERMA
        );
    }

    @Test
    @Transactional
    void getAllConfermasByTipoConfermaIsEqualToSomething() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where tipoConferma equals to
        defaultConfermaFiltering("tipoConferma.equals=" + DEFAULT_TIPO_CONFERMA, "tipoConferma.equals=" + UPDATED_TIPO_CONFERMA);
    }

    @Test
    @Transactional
    void getAllConfermasByTipoConfermaIsInShouldWork() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where tipoConferma in
        defaultConfermaFiltering(
            "tipoConferma.in=" + DEFAULT_TIPO_CONFERMA + "," + UPDATED_TIPO_CONFERMA,
            "tipoConferma.in=" + UPDATED_TIPO_CONFERMA
        );
    }

    @Test
    @Transactional
    void getAllConfermasByTipoConfermaIsNullOrNotNull() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        // Get all the confermaList where tipoConferma is not null
        defaultConfermaFiltering("tipoConferma.specified=true", "tipoConferma.specified=false");
    }

    @Test
    @Transactional
    void getAllConfermasByConfermataDaIsEqualToSomething() throws Exception {
        UtenteApp confermataDa;
        if (TestUtil.findAll(em, UtenteApp.class).isEmpty()) {
            confermaRepository.saveAndFlush(conferma);
            confermataDa = UtenteAppResourceIT.createEntity();
        } else {
            confermataDa = TestUtil.findAll(em, UtenteApp.class).get(0);
        }
        em.persist(confermataDa);
        em.flush();
        conferma.setConfermataDa(confermataDa);
        confermaRepository.saveAndFlush(conferma);
        Long confermataDaId = confermataDa.getId();
        // Get all the confermaList where confermataDa equals to confermataDaId
        defaultConfermaShouldBeFound("confermataDaId.equals=" + confermataDaId);

        // Get all the confermaList where confermataDa equals to (confermataDaId + 1)
        defaultConfermaShouldNotBeFound("confermataDaId.equals=" + (confermataDaId + 1));
    }

    private void defaultConfermaFiltering(String shouldBeFound, String shouldNotBeFound) throws Exception {
        defaultConfermaShouldBeFound(shouldBeFound);
        defaultConfermaShouldNotBeFound(shouldNotBeFound);
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultConfermaShouldBeFound(String filter) throws Exception {
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(conferma.getId().intValue())))
            .andExpect(jsonPath("$.[*].motivoConferma").value(hasItem(DEFAULT_MOTIVO_CONFERMA)))
            .andExpect(jsonPath("$.[*].tipoConferma").value(hasItem(DEFAULT_TIPO_CONFERMA.toString())));

        // Check, that the count call also returns 1
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL + "/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultConfermaShouldNotBeFound(String filter) throws Exception {
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restConfermaMockMvc
            .perform(get(ENTITY_API_URL + "/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    void getNonExistingConferma() throws Exception {
        // Get the conferma
        restConfermaMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putExistingConferma() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        long databaseSizeBeforeUpdate = getRepositoryCount();

        // Update the conferma
        Conferma updatedConferma = confermaRepository.findById(conferma.getId()).orElseThrow();
        // Disconnect from session so that the updates on updatedConferma are not directly saved in db
        em.detach(updatedConferma);
        updatedConferma.motivoConferma(UPDATED_MOTIVO_CONFERMA).tipoConferma(UPDATED_TIPO_CONFERMA);
        ConfermaDTO confermaDTO = confermaMapper.toDto(updatedConferma);

        restConfermaMockMvc
            .perform(
                put(ENTITY_API_URL_ID, confermaDTO.getId())
                    .with(csrf())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isOk());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
        assertPersistedConfermaToMatchAllProperties(updatedConferma);
    }

    @Test
    @Transactional
    void putNonExistingConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(
                put(ENTITY_API_URL_ID, confermaDTO.getId())
                    .with(csrf())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(
                put(ENTITY_API_URL_ID, longCount.incrementAndGet())
                    .with(csrf())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(put(ENTITY_API_URL).with(csrf()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(confermaDTO)))
            .andExpect(status().isMethodNotAllowed());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateConfermaWithPatch() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        long databaseSizeBeforeUpdate = getRepositoryCount();

        // Update the conferma using partial update
        Conferma partialUpdatedConferma = new Conferma();
        partialUpdatedConferma.setId(conferma.getId());

        partialUpdatedConferma.tipoConferma(UPDATED_TIPO_CONFERMA);

        restConfermaMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedConferma.getId())
                    .with(csrf())
                    .contentType("application/merge-patch+json")
                    .content(om.writeValueAsBytes(partialUpdatedConferma))
            )
            .andExpect(status().isOk());

        // Validate the Conferma in the database

        assertSameRepositoryCount(databaseSizeBeforeUpdate);
        assertConfermaUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedConferma, conferma), getPersistedConferma(conferma));
    }

    @Test
    @Transactional
    void fullUpdateConfermaWithPatch() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        long databaseSizeBeforeUpdate = getRepositoryCount();

        // Update the conferma using partial update
        Conferma partialUpdatedConferma = new Conferma();
        partialUpdatedConferma.setId(conferma.getId());

        partialUpdatedConferma.motivoConferma(UPDATED_MOTIVO_CONFERMA).tipoConferma(UPDATED_TIPO_CONFERMA);

        restConfermaMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedConferma.getId())
                    .with(csrf())
                    .contentType("application/merge-patch+json")
                    .content(om.writeValueAsBytes(partialUpdatedConferma))
            )
            .andExpect(status().isOk());

        // Validate the Conferma in the database

        assertSameRepositoryCount(databaseSizeBeforeUpdate);
        assertConfermaUpdatableFieldsEquals(partialUpdatedConferma, getPersistedConferma(partialUpdatedConferma));
    }

    @Test
    @Transactional
    void patchNonExistingConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, confermaDTO.getId())
                    .with(csrf())
                    .contentType("application/merge-patch+json")
                    .content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, longCount.incrementAndGet())
                    .with(csrf())
                    .contentType("application/merge-patch+json")
                    .content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamConferma() throws Exception {
        long databaseSizeBeforeUpdate = getRepositoryCount();
        conferma.setId(longCount.incrementAndGet());

        // Create the Conferma
        ConfermaDTO confermaDTO = confermaMapper.toDto(conferma);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restConfermaMockMvc
            .perform(
                patch(ENTITY_API_URL).with(csrf()).contentType("application/merge-patch+json").content(om.writeValueAsBytes(confermaDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the Conferma in the database
        assertSameRepositoryCount(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteConferma() throws Exception {
        // Initialize the database
        insertedConferma = confermaRepository.saveAndFlush(conferma);

        long databaseSizeBeforeDelete = getRepositoryCount();

        // Delete the conferma
        restConfermaMockMvc
            .perform(delete(ENTITY_API_URL_ID, conferma.getId()).with(csrf()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        assertDecrementedRepositoryCount(databaseSizeBeforeDelete);
    }

    protected long getRepositoryCount() {
        return confermaRepository.count();
    }

    protected void assertIncrementedRepositoryCount(long countBefore) {
        assertThat(countBefore + 1).isEqualTo(getRepositoryCount());
    }

    protected void assertDecrementedRepositoryCount(long countBefore) {
        assertThat(countBefore - 1).isEqualTo(getRepositoryCount());
    }

    protected void assertSameRepositoryCount(long countBefore) {
        assertThat(countBefore).isEqualTo(getRepositoryCount());
    }

    protected Conferma getPersistedConferma(Conferma conferma) {
        return confermaRepository.findById(conferma.getId()).orElseThrow();
    }

    protected void assertPersistedConfermaToMatchAllProperties(Conferma expectedConferma) {
        assertConfermaAllPropertiesEquals(expectedConferma, getPersistedConferma(expectedConferma));
    }

    protected void assertPersistedConfermaToMatchUpdatableProperties(Conferma expectedConferma) {
        assertConfermaAllUpdatablePropertiesEquals(expectedConferma, getPersistedConferma(expectedConferma));
    }
}
