package com.bares.web.rest;

import com.bares.BaresApp;

import com.bares.domain.Comanda;
import com.bares.domain.Mesa;
import com.bares.repository.ComandaRepository;
import com.bares.service.ComandaService;
import com.bares.service.dto.ComandaDTO;
import com.bares.service.mapper.ComandaMapper;
import com.bares.web.rest.errors.ExceptionTranslator;
import com.bares.service.dto.ComandaCriteria;
import com.bares.service.ComandaQueryService;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.ArrayList;

import static com.bares.web.rest.TestUtil.createFormattingConversionService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Test class for the ComandaResource REST controller.
 *
 * @see ComandaResource
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BaresApp.class)
public class ComandaResourceIntTest {

    private static final String DEFAULT_OBSERVACIONES = "AAAAAAAAAA";
    private static final String UPDATED_OBSERVACIONES = "BBBBBBBBBB";

    private static final String DEFAULT_NOMBRE = "AAAAAAAAAA";
    private static final String UPDATED_NOMBRE = "BBBBBBBBBB";

    private static final Double DEFAULT_PRECIO = 1D;
    private static final Double UPDATED_PRECIO = 2D;

    private static final Boolean DEFAULT_SERVIDO = false;
    private static final Boolean UPDATED_SERVIDO = true;

    private static final Instant DEFAULT_DATE_PEDIDO = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_DATE_PEDIDO = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final Instant DEFAULT_DATE_SERVIDO = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_DATE_SERVIDO = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    @Autowired
    private ComandaRepository comandaRepository;



    @Autowired
    private ComandaMapper comandaMapper;
    

    @Autowired
    private ComandaService comandaService;

    @Autowired
    private ComandaQueryService comandaQueryService;

    @Autowired
    private MappingJackson2HttpMessageConverter jacksonMessageConverter;

    @Autowired
    private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

    @Autowired
    private ExceptionTranslator exceptionTranslator;

    @Autowired
    private EntityManager em;

    private MockMvc restComandaMockMvc;

    private Comanda comanda;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        final ComandaResource comandaResource = new ComandaResource(comandaService, comandaQueryService);
        this.restComandaMockMvc = MockMvcBuilders.standaloneSetup(comandaResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setControllerAdvice(exceptionTranslator)
            .setConversionService(createFormattingConversionService())
            .setMessageConverters(jacksonMessageConverter).build();
    }

    /**
     * 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 Comanda createEntity(EntityManager em) {
        Comanda comanda = new Comanda()
            .observaciones(DEFAULT_OBSERVACIONES)
            .nombre(DEFAULT_NOMBRE)
            .precio(DEFAULT_PRECIO)
            .servido(DEFAULT_SERVIDO)
            .datePedido(DEFAULT_DATE_PEDIDO)
            .dateServido(DEFAULT_DATE_SERVIDO);
        return comanda;
    }

    @Before
    public void initTest() {
        comanda = createEntity(em);
    }

    @Test
    @Transactional
    public void createComanda() throws Exception {
        int databaseSizeBeforeCreate = comandaRepository.findAll().size();

        // Create the Comanda
        ComandaDTO comandaDTO = comandaMapper.toDto(comanda);
        restComandaMockMvc.perform(post("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isCreated());

        // Validate the Comanda in the database
        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeCreate + 1);
        Comanda testComanda = comandaList.get(comandaList.size() - 1);
        assertThat(testComanda.getObservaciones()).isEqualTo(DEFAULT_OBSERVACIONES);
        assertThat(testComanda.getNombre()).isEqualTo(DEFAULT_NOMBRE);
        assertThat(testComanda.getPrecio()).isEqualTo(DEFAULT_PRECIO);
        assertThat(testComanda.isServido()).isEqualTo(DEFAULT_SERVIDO);
        assertThat(testComanda.getDatePedido()).isEqualTo(DEFAULT_DATE_PEDIDO);
        assertThat(testComanda.getDateServido()).isEqualTo(DEFAULT_DATE_SERVIDO);
    }

    @Test
    @Transactional
    public void createComandaWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = comandaRepository.findAll().size();

        // Create the Comanda with an existing ID
        comanda.setId(1L);
        ComandaDTO comandaDTO = comandaMapper.toDto(comanda);

        // An entity with an existing ID cannot be created, so this API call must fail
        restComandaMockMvc.perform(post("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Comanda in the database
        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    public void checkNombreIsRequired() throws Exception {
        int databaseSizeBeforeTest = comandaRepository.findAll().size();
        // set the field null
        comanda.setNombre(null);

        // Create the Comanda, which fails.
        ComandaDTO comandaDTO = comandaMapper.toDto(comanda);

        restComandaMockMvc.perform(post("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isBadRequest());

        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkPrecioIsRequired() throws Exception {
        int databaseSizeBeforeTest = comandaRepository.findAll().size();
        // set the field null
        comanda.setPrecio(null);

        // Create the Comanda, which fails.
        ComandaDTO comandaDTO = comandaMapper.toDto(comanda);

        restComandaMockMvc.perform(post("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isBadRequest());

        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllComandas() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList
        restComandaMockMvc.perform(get("/api/comandas?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(comanda.getId().intValue())))
            .andExpect(jsonPath("$.[*].observaciones").value(hasItem(DEFAULT_OBSERVACIONES.toString())))
            .andExpect(jsonPath("$.[*].nombre").value(hasItem(DEFAULT_NOMBRE.toString())))
            .andExpect(jsonPath("$.[*].precio").value(hasItem(DEFAULT_PRECIO.doubleValue())))
            .andExpect(jsonPath("$.[*].servido").value(hasItem(DEFAULT_SERVIDO.booleanValue())))
            .andExpect(jsonPath("$.[*].datePedido").value(hasItem(DEFAULT_DATE_PEDIDO.toString())))
            .andExpect(jsonPath("$.[*].dateServido").value(hasItem(DEFAULT_DATE_SERVIDO.toString())));
    }
    

    @Test
    @Transactional
    public void getComanda() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get the comanda
        restComandaMockMvc.perform(get("/api/comandas/{id}", comanda.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.id").value(comanda.getId().intValue()))
            .andExpect(jsonPath("$.observaciones").value(DEFAULT_OBSERVACIONES.toString()))
            .andExpect(jsonPath("$.nombre").value(DEFAULT_NOMBRE.toString()))
            .andExpect(jsonPath("$.precio").value(DEFAULT_PRECIO.doubleValue()))
            .andExpect(jsonPath("$.servido").value(DEFAULT_SERVIDO.booleanValue()))
            .andExpect(jsonPath("$.datePedido").value(DEFAULT_DATE_PEDIDO.toString()))
            .andExpect(jsonPath("$.dateServido").value(DEFAULT_DATE_SERVIDO.toString()));
    }

    @Test
    @Transactional
    public void getAllComandasByObservacionesIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where observaciones equals to DEFAULT_OBSERVACIONES
        defaultComandaShouldBeFound("observaciones.equals=" + DEFAULT_OBSERVACIONES);

        // Get all the comandaList where observaciones equals to UPDATED_OBSERVACIONES
        defaultComandaShouldNotBeFound("observaciones.equals=" + UPDATED_OBSERVACIONES);
    }

    @Test
    @Transactional
    public void getAllComandasByObservacionesIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where observaciones in DEFAULT_OBSERVACIONES or UPDATED_OBSERVACIONES
        defaultComandaShouldBeFound("observaciones.in=" + DEFAULT_OBSERVACIONES + "," + UPDATED_OBSERVACIONES);

        // Get all the comandaList where observaciones equals to UPDATED_OBSERVACIONES
        defaultComandaShouldNotBeFound("observaciones.in=" + UPDATED_OBSERVACIONES);
    }

    @Test
    @Transactional
    public void getAllComandasByObservacionesIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where observaciones is not null
        defaultComandaShouldBeFound("observaciones.specified=true");

        // Get all the comandaList where observaciones is null
        defaultComandaShouldNotBeFound("observaciones.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByNombreIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where nombre equals to DEFAULT_NOMBRE
        defaultComandaShouldBeFound("nombre.equals=" + DEFAULT_NOMBRE);

        // Get all the comandaList where nombre equals to UPDATED_NOMBRE
        defaultComandaShouldNotBeFound("nombre.equals=" + UPDATED_NOMBRE);
    }

    @Test
    @Transactional
    public void getAllComandasByNombreIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where nombre in DEFAULT_NOMBRE or UPDATED_NOMBRE
        defaultComandaShouldBeFound("nombre.in=" + DEFAULT_NOMBRE + "," + UPDATED_NOMBRE);

        // Get all the comandaList where nombre equals to UPDATED_NOMBRE
        defaultComandaShouldNotBeFound("nombre.in=" + UPDATED_NOMBRE);
    }

    @Test
    @Transactional
    public void getAllComandasByNombreIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where nombre is not null
        defaultComandaShouldBeFound("nombre.specified=true");

        // Get all the comandaList where nombre is null
        defaultComandaShouldNotBeFound("nombre.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByPrecioIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where precio equals to DEFAULT_PRECIO
        defaultComandaShouldBeFound("precio.equals=" + DEFAULT_PRECIO);

        // Get all the comandaList where precio equals to UPDATED_PRECIO
        defaultComandaShouldNotBeFound("precio.equals=" + UPDATED_PRECIO);
    }

    @Test
    @Transactional
    public void getAllComandasByPrecioIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where precio in DEFAULT_PRECIO or UPDATED_PRECIO
        defaultComandaShouldBeFound("precio.in=" + DEFAULT_PRECIO + "," + UPDATED_PRECIO);

        // Get all the comandaList where precio equals to UPDATED_PRECIO
        defaultComandaShouldNotBeFound("precio.in=" + UPDATED_PRECIO);
    }

    @Test
    @Transactional
    public void getAllComandasByPrecioIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where precio is not null
        defaultComandaShouldBeFound("precio.specified=true");

        // Get all the comandaList where precio is null
        defaultComandaShouldNotBeFound("precio.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByServidoIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where servido equals to DEFAULT_SERVIDO
        defaultComandaShouldBeFound("servido.equals=" + DEFAULT_SERVIDO);

        // Get all the comandaList where servido equals to UPDATED_SERVIDO
        defaultComandaShouldNotBeFound("servido.equals=" + UPDATED_SERVIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByServidoIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where servido in DEFAULT_SERVIDO or UPDATED_SERVIDO
        defaultComandaShouldBeFound("servido.in=" + DEFAULT_SERVIDO + "," + UPDATED_SERVIDO);

        // Get all the comandaList where servido equals to UPDATED_SERVIDO
        defaultComandaShouldNotBeFound("servido.in=" + UPDATED_SERVIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByServidoIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where servido is not null
        defaultComandaShouldBeFound("servido.specified=true");

        // Get all the comandaList where servido is null
        defaultComandaShouldNotBeFound("servido.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByDatePedidoIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where datePedido equals to DEFAULT_DATE_PEDIDO
        defaultComandaShouldBeFound("datePedido.equals=" + DEFAULT_DATE_PEDIDO);

        // Get all the comandaList where datePedido equals to UPDATED_DATE_PEDIDO
        defaultComandaShouldNotBeFound("datePedido.equals=" + UPDATED_DATE_PEDIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByDatePedidoIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where datePedido in DEFAULT_DATE_PEDIDO or UPDATED_DATE_PEDIDO
        defaultComandaShouldBeFound("datePedido.in=" + DEFAULT_DATE_PEDIDO + "," + UPDATED_DATE_PEDIDO);

        // Get all the comandaList where datePedido equals to UPDATED_DATE_PEDIDO
        defaultComandaShouldNotBeFound("datePedido.in=" + UPDATED_DATE_PEDIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByDatePedidoIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where datePedido is not null
        defaultComandaShouldBeFound("datePedido.specified=true");

        // Get all the comandaList where datePedido is null
        defaultComandaShouldNotBeFound("datePedido.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByDateServidoIsEqualToSomething() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where dateServido equals to DEFAULT_DATE_SERVIDO
        defaultComandaShouldBeFound("dateServido.equals=" + DEFAULT_DATE_SERVIDO);

        // Get all the comandaList where dateServido equals to UPDATED_DATE_SERVIDO
        defaultComandaShouldNotBeFound("dateServido.equals=" + UPDATED_DATE_SERVIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByDateServidoIsInShouldWork() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where dateServido in DEFAULT_DATE_SERVIDO or UPDATED_DATE_SERVIDO
        defaultComandaShouldBeFound("dateServido.in=" + DEFAULT_DATE_SERVIDO + "," + UPDATED_DATE_SERVIDO);

        // Get all the comandaList where dateServido equals to UPDATED_DATE_SERVIDO
        defaultComandaShouldNotBeFound("dateServido.in=" + UPDATED_DATE_SERVIDO);
    }

    @Test
    @Transactional
    public void getAllComandasByDateServidoIsNullOrNotNull() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        // Get all the comandaList where dateServido is not null
        defaultComandaShouldBeFound("dateServido.specified=true");

        // Get all the comandaList where dateServido is null
        defaultComandaShouldNotBeFound("dateServido.specified=false");
    }

    @Test
    @Transactional
    public void getAllComandasByMesaIsEqualToSomething() throws Exception {
        // Initialize the database
        Mesa mesa = MesaResourceIntTest.createEntity(em);
        em.persist(mesa);
        em.flush();
        comanda.setMesa(mesa);
        comandaRepository.saveAndFlush(comanda);
        Long mesaId = mesa.getId();

        // Get all the comandaList where mesa equals to mesaId
        defaultComandaShouldBeFound("mesaId.equals=" + mesaId);

        // Get all the comandaList where mesa equals to mesaId + 1
        defaultComandaShouldNotBeFound("mesaId.equals=" + (mesaId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned
     */
    private void defaultComandaShouldBeFound(String filter) throws Exception {
        restComandaMockMvc.perform(get("/api/comandas?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(comanda.getId().intValue())))
            .andExpect(jsonPath("$.[*].observaciones").value(hasItem(DEFAULT_OBSERVACIONES.toString())))
            .andExpect(jsonPath("$.[*].nombre").value(hasItem(DEFAULT_NOMBRE.toString())))
            .andExpect(jsonPath("$.[*].precio").value(hasItem(DEFAULT_PRECIO.doubleValue())))
            .andExpect(jsonPath("$.[*].servido").value(hasItem(DEFAULT_SERVIDO.booleanValue())))
            .andExpect(jsonPath("$.[*].datePedido").value(hasItem(DEFAULT_DATE_PEDIDO.toString())))
            .andExpect(jsonPath("$.[*].dateServido").value(hasItem(DEFAULT_DATE_SERVIDO.toString())));
    }

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


    @Test
    @Transactional
    public void getNonExistingComanda() throws Exception {
        // Get the comanda
        restComandaMockMvc.perform(get("/api/comandas/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateComanda() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        int databaseSizeBeforeUpdate = comandaRepository.findAll().size();

        // Update the comanda
        Comanda updatedComanda = comandaRepository.findById(comanda.getId()).get();
        // Disconnect from session so that the updates on updatedComanda are not directly saved in db
        em.detach(updatedComanda);
        updatedComanda
            .observaciones(UPDATED_OBSERVACIONES)
            .nombre(UPDATED_NOMBRE)
            .precio(UPDATED_PRECIO)
            .servido(UPDATED_SERVIDO)
            .datePedido(UPDATED_DATE_PEDIDO)
            .dateServido(UPDATED_DATE_SERVIDO);
        ComandaDTO comandaDTO = comandaMapper.toDto(updatedComanda);

        restComandaMockMvc.perform(put("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isOk());

        // Validate the Comanda in the database
        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeUpdate);
        Comanda testComanda = comandaList.get(comandaList.size() - 1);
        assertThat(testComanda.getObservaciones()).isEqualTo(UPDATED_OBSERVACIONES);
        assertThat(testComanda.getNombre()).isEqualTo(UPDATED_NOMBRE);
        assertThat(testComanda.getPrecio()).isEqualTo(UPDATED_PRECIO);
        assertThat(testComanda.isServido()).isEqualTo(UPDATED_SERVIDO);
        assertThat(testComanda.getDatePedido()).isEqualTo(UPDATED_DATE_PEDIDO);
        assertThat(testComanda.getDateServido()).isEqualTo(UPDATED_DATE_SERVIDO);
    }

    @Test
    @Transactional
    public void updateNonExistingComanda() throws Exception {
        int databaseSizeBeforeUpdate = comandaRepository.findAll().size();

        // Create the Comanda
        ComandaDTO comandaDTO = comandaMapper.toDto(comanda);

        // If the entity doesn't have an ID, it will be created instead of just being updated
        restComandaMockMvc.perform(put("/api/comandas")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(comandaDTO)))
            .andExpect(status().isCreated());

        // Validate the Comanda in the database
        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeUpdate + 1);
    }

    @Test
    @Transactional
    public void deleteComanda() throws Exception {
        // Initialize the database
        comandaRepository.saveAndFlush(comanda);

        int databaseSizeBeforeDelete = comandaRepository.findAll().size();

        // Get the comanda
        restComandaMockMvc.perform(delete("/api/comandas/{id}", comanda.getId())
            .accept(TestUtil.APPLICATION_JSON_UTF8))
            .andExpect(status().isOk());

        // Validate the database is empty
        List<Comanda> comandaList = comandaRepository.findAll();
        assertThat(comandaList).hasSize(databaseSizeBeforeDelete - 1);
    }

    @Test
    @Transactional
    public void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(Comanda.class);
        Comanda comanda1 = new Comanda();
        comanda1.setId(1L);
        Comanda comanda2 = new Comanda();
        comanda2.setId(comanda1.getId());
        assertThat(comanda1).isEqualTo(comanda2);
        comanda2.setId(2L);
        assertThat(comanda1).isNotEqualTo(comanda2);
        comanda1.setId(null);
        assertThat(comanda1).isNotEqualTo(comanda2);
    }

    @Test
    @Transactional
    public void dtoEqualsVerifier() throws Exception {
        TestUtil.equalsVerifier(ComandaDTO.class);
        ComandaDTO comandaDTO1 = new ComandaDTO();
        comandaDTO1.setId(1L);
        ComandaDTO comandaDTO2 = new ComandaDTO();
        assertThat(comandaDTO1).isNotEqualTo(comandaDTO2);
        comandaDTO2.setId(comandaDTO1.getId());
        assertThat(comandaDTO1).isEqualTo(comandaDTO2);
        comandaDTO2.setId(2L);
        assertThat(comandaDTO1).isNotEqualTo(comandaDTO2);
        comandaDTO1.setId(null);
        assertThat(comandaDTO1).isNotEqualTo(comandaDTO2);
    }

    @Test
    @Transactional
    public void testEntityFromId() {
        assertThat(comandaMapper.fromId(42L).getId()).isEqualTo(42);
        assertThat(comandaMapper.fromId(null)).isNull();
    }
}
