package vn.azteam.tpf.web.rest;

import vn.azteam.tpf.TpfApp;

import vn.azteam.tpf.domain.TBBlockDetailsReport;
import vn.azteam.tpf.domain.TBBlockDetails;
import vn.azteam.tpf.domain.TBSuppliesType;
import vn.azteam.tpf.domain.TBSuppliesInWarehouse;
import vn.azteam.tpf.repository.TBBlockDetailsReportRepository;
import vn.azteam.tpf.repository.search.TBBlockDetailsReportSearchRepository;
import vn.azteam.tpf.service.TBBlockDetailsReportService;
import vn.azteam.tpf.service.dto.TBBlockDetailsReportDTO;
import vn.azteam.tpf.service.mapper.TBBlockDetailsReportMapper;
import vn.azteam.tpf.web.rest.errors.ExceptionTranslator;
import vn.azteam.tpf.service.dto.TBBlockDetailsReportCriteria;
import vn.azteam.tpf.service.TBBlockDetailsReportQueryService;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
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 org.springframework.validation.Validator;

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


import static vn.azteam.tpf.web.rest.TestUtil.createFormattingConversionService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Test class for the TBBlockDetailsReportResource REST controller.
 *
 * @see TBBlockDetailsReportResource
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TpfApp.class)
public class TBBlockDetailsReportResourceIntTest {

    private static final String DEFAULT_CODE = "AAAAAAAAAA";
    private static final String UPDATED_CODE = "BBBBBBBBBB";

    private static final Double DEFAULT_QUANTITY = 1D;
    private static final Double UPDATED_QUANTITY = 2D;

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

    @Autowired
    private TBBlockDetailsReportRepository tBBlockDetailsReportRepository;

    @Autowired
    private TBBlockDetailsReportMapper tBBlockDetailsReportMapper;

    @Autowired
    private TBBlockDetailsReportService tBBlockDetailsReportService;

    /**
     * This repository is mocked in the vn.azteam.tpf.repository.search test package.
     *
     * @see vn.azteam.tpf.repository.search.TBBlockDetailsReportSearchRepositoryMockConfiguration
     */
    @Autowired
    private TBBlockDetailsReportSearchRepository mockTBBlockDetailsReportSearchRepository;

    @Autowired
    private TBBlockDetailsReportQueryService tBBlockDetailsReportQueryService;

    @Autowired
    private MappingJackson2HttpMessageConverter jacksonMessageConverter;

    @Autowired
    private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

    @Autowired
    private ExceptionTranslator exceptionTranslator;

    @Autowired
    private EntityManager em;

    @Autowired
    private Validator validator;

    private MockMvc restTBBlockDetailsReportMockMvc;

    private TBBlockDetailsReport tBBlockDetailsReport;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        final TBBlockDetailsReportResource tBBlockDetailsReportResource = new TBBlockDetailsReportResource(tBBlockDetailsReportService, tBBlockDetailsReportQueryService);
        this.restTBBlockDetailsReportMockMvc = MockMvcBuilders.standaloneSetup(tBBlockDetailsReportResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setControllerAdvice(exceptionTranslator)
            .setConversionService(createFormattingConversionService())
            .setMessageConverters(jacksonMessageConverter)
            .setValidator(validator).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 TBBlockDetailsReport createEntity(EntityManager em) {
        TBBlockDetailsReport tBBlockDetailsReport = new TBBlockDetailsReport()
            .code(DEFAULT_CODE)
            .quantity(DEFAULT_QUANTITY)
            .createDate(DEFAULT_CREATE_DATE);
        return tBBlockDetailsReport;
    }

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

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

        // Create the TBBlockDetailsReport
        TBBlockDetailsReportDTO tBBlockDetailsReportDTO = tBBlockDetailsReportMapper.toDto(tBBlockDetailsReport);
        restTBBlockDetailsReportMockMvc.perform(post("/api/tb-block-details-reports")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(tBBlockDetailsReportDTO)))
            .andExpect(status().isCreated());

        // Validate the TBBlockDetailsReport in the database
        List<TBBlockDetailsReport> tBBlockDetailsReportList = tBBlockDetailsReportRepository.findAll();
        assertThat(tBBlockDetailsReportList).hasSize(databaseSizeBeforeCreate + 1);
        TBBlockDetailsReport testTBBlockDetailsReport = tBBlockDetailsReportList.get(tBBlockDetailsReportList.size() - 1);
        assertThat(testTBBlockDetailsReport.getCode()).isEqualTo(DEFAULT_CODE);
        assertThat(testTBBlockDetailsReport.getQuantity()).isEqualTo(DEFAULT_QUANTITY);
        assertThat(testTBBlockDetailsReport.getCreateDate()).isEqualTo(DEFAULT_CREATE_DATE);

        // Validate the TBBlockDetailsReport in Elasticsearch
        verify(mockTBBlockDetailsReportSearchRepository, times(1)).save(testTBBlockDetailsReport);
    }

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

        // Create the TBBlockDetailsReport with an existing ID
        tBBlockDetailsReport.setId(1L);
        TBBlockDetailsReportDTO tBBlockDetailsReportDTO = tBBlockDetailsReportMapper.toDto(tBBlockDetailsReport);

        // An entity with an existing ID cannot be created, so this API call must fail
        restTBBlockDetailsReportMockMvc.perform(post("/api/tb-block-details-reports")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(tBBlockDetailsReportDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TBBlockDetailsReport in the database
        List<TBBlockDetailsReport> tBBlockDetailsReportList = tBBlockDetailsReportRepository.findAll();
        assertThat(tBBlockDetailsReportList).hasSize(databaseSizeBeforeCreate);

        // Validate the TBBlockDetailsReport in Elasticsearch
        verify(mockTBBlockDetailsReportSearchRepository, times(0)).save(tBBlockDetailsReport);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReports() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(tBBlockDetailsReport.getId().intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE.toString())))
            .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY.doubleValue())))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())));
    }
    
    @Test
    @Transactional
    public void getTBBlockDetailsReport() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get the tBBlockDetailsReport
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports/{id}", tBBlockDetailsReport.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.id").value(tBBlockDetailsReport.getId().intValue()))
            .andExpect(jsonPath("$.code").value(DEFAULT_CODE.toString()))
            .andExpect(jsonPath("$.quantity").value(DEFAULT_QUANTITY.doubleValue()))
            .andExpect(jsonPath("$.createDate").value(DEFAULT_CREATE_DATE.toString()));
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCodeIsEqualToSomething() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where code equals to DEFAULT_CODE
        defaultTBBlockDetailsReportShouldBeFound("code.equals=" + DEFAULT_CODE);

        // Get all the tBBlockDetailsReportList where code equals to UPDATED_CODE
        defaultTBBlockDetailsReportShouldNotBeFound("code.equals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCodeIsInShouldWork() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where code in DEFAULT_CODE or UPDATED_CODE
        defaultTBBlockDetailsReportShouldBeFound("code.in=" + DEFAULT_CODE + "," + UPDATED_CODE);

        // Get all the tBBlockDetailsReportList where code equals to UPDATED_CODE
        defaultTBBlockDetailsReportShouldNotBeFound("code.in=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCodeIsNullOrNotNull() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where code is not null
        defaultTBBlockDetailsReportShouldBeFound("code.specified=true");

        // Get all the tBBlockDetailsReportList where code is null
        defaultTBBlockDetailsReportShouldNotBeFound("code.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByQuantityIsEqualToSomething() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where quantity equals to DEFAULT_QUANTITY
        defaultTBBlockDetailsReportShouldBeFound("quantity.equals=" + DEFAULT_QUANTITY);

        // Get all the tBBlockDetailsReportList where quantity equals to UPDATED_QUANTITY
        defaultTBBlockDetailsReportShouldNotBeFound("quantity.equals=" + UPDATED_QUANTITY);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByQuantityIsInShouldWork() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where quantity in DEFAULT_QUANTITY or UPDATED_QUANTITY
        defaultTBBlockDetailsReportShouldBeFound("quantity.in=" + DEFAULT_QUANTITY + "," + UPDATED_QUANTITY);

        // Get all the tBBlockDetailsReportList where quantity equals to UPDATED_QUANTITY
        defaultTBBlockDetailsReportShouldNotBeFound("quantity.in=" + UPDATED_QUANTITY);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByQuantityIsNullOrNotNull() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where quantity is not null
        defaultTBBlockDetailsReportShouldBeFound("quantity.specified=true");

        // Get all the tBBlockDetailsReportList where quantity is null
        defaultTBBlockDetailsReportShouldNotBeFound("quantity.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCreateDateIsEqualToSomething() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where createDate equals to DEFAULT_CREATE_DATE
        defaultTBBlockDetailsReportShouldBeFound("createDate.equals=" + DEFAULT_CREATE_DATE);

        // Get all the tBBlockDetailsReportList where createDate equals to UPDATED_CREATE_DATE
        defaultTBBlockDetailsReportShouldNotBeFound("createDate.equals=" + UPDATED_CREATE_DATE);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCreateDateIsInShouldWork() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where createDate in DEFAULT_CREATE_DATE or UPDATED_CREATE_DATE
        defaultTBBlockDetailsReportShouldBeFound("createDate.in=" + DEFAULT_CREATE_DATE + "," + UPDATED_CREATE_DATE);

        // Get all the tBBlockDetailsReportList where createDate equals to UPDATED_CREATE_DATE
        defaultTBBlockDetailsReportShouldNotBeFound("createDate.in=" + UPDATED_CREATE_DATE);
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByCreateDateIsNullOrNotNull() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

        // Get all the tBBlockDetailsReportList where createDate is not null
        defaultTBBlockDetailsReportShouldBeFound("createDate.specified=true");

        // Get all the tBBlockDetailsReportList where createDate is null
        defaultTBBlockDetailsReportShouldNotBeFound("createDate.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByTbBlockDetailsIsEqualToSomething() throws Exception {
        // Initialize the database
        TBBlockDetails tbBlockDetails = TBBlockDetailsResourceIntTest.createEntity(em);
        em.persist(tbBlockDetails);
        em.flush();
        tBBlockDetailsReport.setTbBlockDetails(tbBlockDetails);
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);
        Long tbBlockDetailsId = tbBlockDetails.getId();

        // Get all the tBBlockDetailsReportList where tbBlockDetails equals to tbBlockDetailsId
        defaultTBBlockDetailsReportShouldBeFound("tbBlockDetailsId.equals=" + tbBlockDetailsId);

        // Get all the tBBlockDetailsReportList where tbBlockDetails equals to tbBlockDetailsId + 1
        defaultTBBlockDetailsReportShouldNotBeFound("tbBlockDetailsId.equals=" + (tbBlockDetailsId + 1));
    }


    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByTbSuppliesTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        TBSuppliesType tbSuppliesType = TBSuppliesTypeResourceIntTest.createEntity(em);
        em.persist(tbSuppliesType);
        em.flush();
        tBBlockDetailsReport.setTbSuppliesType(tbSuppliesType);
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);
        Long tbSuppliesTypeId = tbSuppliesType.getId();

        // Get all the tBBlockDetailsReportList where tbSuppliesType equals to tbSuppliesTypeId
        defaultTBBlockDetailsReportShouldBeFound("tbSuppliesTypeId.equals=" + tbSuppliesTypeId);

        // Get all the tBBlockDetailsReportList where tbSuppliesType equals to tbSuppliesTypeId + 1
        defaultTBBlockDetailsReportShouldNotBeFound("tbSuppliesTypeId.equals=" + (tbSuppliesTypeId + 1));
    }


    @Test
    @Transactional
    public void getAllTBBlockDetailsReportsByTbSuppliesInWarehouseIsEqualToSomething() throws Exception {
        // Initialize the database
        TBSuppliesInWarehouse tbSuppliesInWarehouse = TBSuppliesInWarehouseResourceIntTest.createEntity(em);
        em.persist(tbSuppliesInWarehouse);
        em.flush();
        tBBlockDetailsReport.setTbSuppliesInWarehouse(tbSuppliesInWarehouse);
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);
        Long tbSuppliesInWarehouseId = tbSuppliesInWarehouse.getId();

        // Get all the tBBlockDetailsReportList where tbSuppliesInWarehouse equals to tbSuppliesInWarehouseId
        defaultTBBlockDetailsReportShouldBeFound("tbSuppliesInWarehouseId.equals=" + tbSuppliesInWarehouseId);

        // Get all the tBBlockDetailsReportList where tbSuppliesInWarehouse equals to tbSuppliesInWarehouseId + 1
        defaultTBBlockDetailsReportShouldNotBeFound("tbSuppliesInWarehouseId.equals=" + (tbSuppliesInWarehouseId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned
     */
    private void defaultTBBlockDetailsReportShouldBeFound(String filter) throws Exception {
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(tBBlockDetailsReport.getId().intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE.toString())))
            .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY.doubleValue())))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())));

        // Check, that the count call also returns 1
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(content().string("1"));
    }

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

        // Check, that the count call also returns 0
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(content().string("0"));
    }


    @Test
    @Transactional
    public void getNonExistingTBBlockDetailsReport() throws Exception {
        // Get the tBBlockDetailsReport
        restTBBlockDetailsReportMockMvc.perform(get("/api/tb-block-details-reports/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateTBBlockDetailsReport() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

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

        // Update the tBBlockDetailsReport
        TBBlockDetailsReport updatedTBBlockDetailsReport = tBBlockDetailsReportRepository.findById(tBBlockDetailsReport.getId()).get();
        // Disconnect from session so that the updates on updatedTBBlockDetailsReport are not directly saved in db
        em.detach(updatedTBBlockDetailsReport);
        updatedTBBlockDetailsReport
            .code(UPDATED_CODE)
            .quantity(UPDATED_QUANTITY)
            .createDate(UPDATED_CREATE_DATE);
        TBBlockDetailsReportDTO tBBlockDetailsReportDTO = tBBlockDetailsReportMapper.toDto(updatedTBBlockDetailsReport);

        restTBBlockDetailsReportMockMvc.perform(put("/api/tb-block-details-reports")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(tBBlockDetailsReportDTO)))
            .andExpect(status().isOk());

        // Validate the TBBlockDetailsReport in the database
        List<TBBlockDetailsReport> tBBlockDetailsReportList = tBBlockDetailsReportRepository.findAll();
        assertThat(tBBlockDetailsReportList).hasSize(databaseSizeBeforeUpdate);
        TBBlockDetailsReport testTBBlockDetailsReport = tBBlockDetailsReportList.get(tBBlockDetailsReportList.size() - 1);
        assertThat(testTBBlockDetailsReport.getCode()).isEqualTo(UPDATED_CODE);
        assertThat(testTBBlockDetailsReport.getQuantity()).isEqualTo(UPDATED_QUANTITY);
        assertThat(testTBBlockDetailsReport.getCreateDate()).isEqualTo(UPDATED_CREATE_DATE);

        // Validate the TBBlockDetailsReport in Elasticsearch
        verify(mockTBBlockDetailsReportSearchRepository, times(1)).save(testTBBlockDetailsReport);
    }

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

        // Create the TBBlockDetailsReport
        TBBlockDetailsReportDTO tBBlockDetailsReportDTO = tBBlockDetailsReportMapper.toDto(tBBlockDetailsReport);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restTBBlockDetailsReportMockMvc.perform(put("/api/tb-block-details-reports")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(tBBlockDetailsReportDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TBBlockDetailsReport in the database
        List<TBBlockDetailsReport> tBBlockDetailsReportList = tBBlockDetailsReportRepository.findAll();
        assertThat(tBBlockDetailsReportList).hasSize(databaseSizeBeforeUpdate);

        // Validate the TBBlockDetailsReport in Elasticsearch
        verify(mockTBBlockDetailsReportSearchRepository, times(0)).save(tBBlockDetailsReport);
    }

    @Test
    @Transactional
    public void deleteTBBlockDetailsReport() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);

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

        // Get the tBBlockDetailsReport
        restTBBlockDetailsReportMockMvc.perform(delete("/api/tb-block-details-reports/{id}", tBBlockDetailsReport.getId())
            .accept(TestUtil.APPLICATION_JSON_UTF8))
            .andExpect(status().isOk());

        // Validate the database is empty
        List<TBBlockDetailsReport> tBBlockDetailsReportList = tBBlockDetailsReportRepository.findAll();
        assertThat(tBBlockDetailsReportList).hasSize(databaseSizeBeforeDelete - 1);

        // Validate the TBBlockDetailsReport in Elasticsearch
        verify(mockTBBlockDetailsReportSearchRepository, times(1)).deleteById(tBBlockDetailsReport.getId());
    }

    @Test
    @Transactional
    public void searchTBBlockDetailsReport() throws Exception {
        // Initialize the database
        tBBlockDetailsReportRepository.saveAndFlush(tBBlockDetailsReport);
        when(mockTBBlockDetailsReportSearchRepository.search(queryStringQuery("id:" + tBBlockDetailsReport.getId()), PageRequest.of(0, 20)))
            .thenReturn(new PageImpl<>(Collections.singletonList(tBBlockDetailsReport), PageRequest.of(0, 1), 1));
        // Search the tBBlockDetailsReport
        restTBBlockDetailsReportMockMvc.perform(get("/api/_search/tb-block-details-reports?query=id:" + tBBlockDetailsReport.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(tBBlockDetailsReport.getId().intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY.doubleValue())))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())));
    }

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

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

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