package vn.azteam.tpf.web.rest;

import vn.azteam.tpf.TpfApp;

import vn.azteam.tpf.domain.TBProductBlockDetailsReport;
import vn.azteam.tpf.domain.TBProductBlockDetails;
import vn.azteam.tpf.domain.TBCrop;
import vn.azteam.tpf.repository.TBProductBlockDetailsReportRepository;
import vn.azteam.tpf.repository.search.TBProductBlockDetailsReportSearchRepository;
import vn.azteam.tpf.service.TBProductBlockDetailsReportService;
import vn.azteam.tpf.service.dto.TBProductBlockDetailsReportDTO;
import vn.azteam.tpf.service.mapper.TBProductBlockDetailsReportMapper;
import vn.azteam.tpf.web.rest.errors.ExceptionTranslator;
import vn.azteam.tpf.service.dto.TBProductBlockDetailsReportCriteria;
import vn.azteam.tpf.service.TBProductBlockDetailsReportQueryService;

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 TBProductBlockDetailsReportResource REST controller.
 *
 * @see TBProductBlockDetailsReportResource
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TpfApp.class)
public class TBProductBlockDetailsReportResourceIntTest {

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

    private static final Double DEFAULT_PRODUCT_LEVEL_1 = 1D;
    private static final Double UPDATED_PRODUCT_LEVEL_1 = 2D;

    private static final Double DEFAULT_PRODUCT_LEVEL_2 = 1D;
    private static final Double UPDATED_PRODUCT_LEVEL_2 = 2D;

    private static final Double DEFAULT_PRODUCT_LEVEL_3 = 1D;
    private static final Double UPDATED_PRODUCT_LEVEL_3 = 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 TBProductBlockDetailsReportRepository tBProductBlockDetailsReportRepository;

    @Autowired
    private TBProductBlockDetailsReportMapper tBProductBlockDetailsReportMapper;

    @Autowired
    private TBProductBlockDetailsReportService tBProductBlockDetailsReportService;

    /**
     * This repository is mocked in the vn.azteam.tpf.repository.search test package.
     *
     * @see vn.azteam.tpf.repository.search.TBProductBlockDetailsReportSearchRepositoryMockConfiguration
     */
    @Autowired
    private TBProductBlockDetailsReportSearchRepository mockTBProductBlockDetailsReportSearchRepository;

    @Autowired
    private TBProductBlockDetailsReportQueryService tBProductBlockDetailsReportQueryService;

    @Autowired
    private MappingJackson2HttpMessageConverter jacksonMessageConverter;

    @Autowired
    private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

    @Autowired
    private ExceptionTranslator exceptionTranslator;

    @Autowired
    private EntityManager em;

    @Autowired
    private Validator validator;

    private MockMvc restTBProductBlockDetailsReportMockMvc;

    private TBProductBlockDetailsReport tBProductBlockDetailsReport;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        final TBProductBlockDetailsReportResource tBProductBlockDetailsReportResource = new TBProductBlockDetailsReportResource(tBProductBlockDetailsReportService, tBProductBlockDetailsReportQueryService);
        this.restTBProductBlockDetailsReportMockMvc = MockMvcBuilders.standaloneSetup(tBProductBlockDetailsReportResource)
            .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 TBProductBlockDetailsReport createEntity(EntityManager em) {
        TBProductBlockDetailsReport tBProductBlockDetailsReport = new TBProductBlockDetailsReport()
            .code(DEFAULT_CODE)
            .productLevel1(DEFAULT_PRODUCT_LEVEL_1)
            .productLevel2(DEFAULT_PRODUCT_LEVEL_2)
            .productLevel3(DEFAULT_PRODUCT_LEVEL_3)
            .createDate(DEFAULT_CREATE_DATE);
        return tBProductBlockDetailsReport;
    }

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

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

        // Create the TBProductBlockDetailsReport
        TBProductBlockDetailsReportDTO tBProductBlockDetailsReportDTO = tBProductBlockDetailsReportMapper.toDto(tBProductBlockDetailsReport);
        restTBProductBlockDetailsReportMockMvc.perform(post("/api/tb-product-block-details-reports")
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
            .content(TestUtil.convertObjectToJsonBytes(tBProductBlockDetailsReportDTO)))
            .andExpect(status().isCreated());

        // Validate the TBProductBlockDetailsReport in the database
        List<TBProductBlockDetailsReport> tBProductBlockDetailsReportList = tBProductBlockDetailsReportRepository.findAll();
        assertThat(tBProductBlockDetailsReportList).hasSize(databaseSizeBeforeCreate + 1);
        TBProductBlockDetailsReport testTBProductBlockDetailsReport = tBProductBlockDetailsReportList.get(tBProductBlockDetailsReportList.size() - 1);
        assertThat(testTBProductBlockDetailsReport.getCode()).isEqualTo(DEFAULT_CODE);
        assertThat(testTBProductBlockDetailsReport.getProductLevel1()).isEqualTo(DEFAULT_PRODUCT_LEVEL_1);
        assertThat(testTBProductBlockDetailsReport.getProductLevel2()).isEqualTo(DEFAULT_PRODUCT_LEVEL_2);
        assertThat(testTBProductBlockDetailsReport.getProductLevel3()).isEqualTo(DEFAULT_PRODUCT_LEVEL_3);
        assertThat(testTBProductBlockDetailsReport.getCreateDate()).isEqualTo(DEFAULT_CREATE_DATE);

        // Validate the TBProductBlockDetailsReport in Elasticsearch
        verify(mockTBProductBlockDetailsReportSearchRepository, times(1)).save(testTBProductBlockDetailsReport);
    }

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

        // Create the TBProductBlockDetailsReport with an existing ID
        tBProductBlockDetailsReport.setId(1L);
        TBProductBlockDetailsReportDTO tBProductBlockDetailsReportDTO = tBProductBlockDetailsReportMapper.toDto(tBProductBlockDetailsReport);

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

        // Validate the TBProductBlockDetailsReport in the database
        List<TBProductBlockDetailsReport> tBProductBlockDetailsReportList = tBProductBlockDetailsReportRepository.findAll();
        assertThat(tBProductBlockDetailsReportList).hasSize(databaseSizeBeforeCreate);

        // Validate the TBProductBlockDetailsReport in Elasticsearch
        verify(mockTBProductBlockDetailsReportSearchRepository, times(0)).save(tBProductBlockDetailsReport);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReports() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-block-details-reports?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(tBProductBlockDetailsReport.getId().intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE.toString())))
            .andExpect(jsonPath("$.[*].productLevel1").value(hasItem(DEFAULT_PRODUCT_LEVEL_1.doubleValue())))
            .andExpect(jsonPath("$.[*].productLevel2").value(hasItem(DEFAULT_PRODUCT_LEVEL_2.doubleValue())))
            .andExpect(jsonPath("$.[*].productLevel3").value(hasItem(DEFAULT_PRODUCT_LEVEL_3.doubleValue())))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())));
    }
    
    @Test
    @Transactional
    public void getTBProductBlockDetailsReport() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get the tBProductBlockDetailsReport
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-block-details-reports/{id}", tBProductBlockDetailsReport.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.id").value(tBProductBlockDetailsReport.getId().intValue()))
            .andExpect(jsonPath("$.code").value(DEFAULT_CODE.toString()))
            .andExpect(jsonPath("$.productLevel1").value(DEFAULT_PRODUCT_LEVEL_1.doubleValue()))
            .andExpect(jsonPath("$.productLevel2").value(DEFAULT_PRODUCT_LEVEL_2.doubleValue()))
            .andExpect(jsonPath("$.productLevel3").value(DEFAULT_PRODUCT_LEVEL_3.doubleValue()))
            .andExpect(jsonPath("$.createDate").value(DEFAULT_CREATE_DATE.toString()));
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCodeIsEqualToSomething() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCodeIsInShouldWork() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCodeIsNullOrNotNull() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel1IsEqualToSomething() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel1 equals to DEFAULT_PRODUCT_LEVEL_1
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel1.equals=" + DEFAULT_PRODUCT_LEVEL_1);

        // Get all the tBProductBlockDetailsReportList where productLevel1 equals to UPDATED_PRODUCT_LEVEL_1
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel1.equals=" + UPDATED_PRODUCT_LEVEL_1);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel1IsInShouldWork() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel1 in DEFAULT_PRODUCT_LEVEL_1 or UPDATED_PRODUCT_LEVEL_1
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel1.in=" + DEFAULT_PRODUCT_LEVEL_1 + "," + UPDATED_PRODUCT_LEVEL_1);

        // Get all the tBProductBlockDetailsReportList where productLevel1 equals to UPDATED_PRODUCT_LEVEL_1
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel1.in=" + UPDATED_PRODUCT_LEVEL_1);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel1IsNullOrNotNull() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel1 is not null
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel1.specified=true");

        // Get all the tBProductBlockDetailsReportList where productLevel1 is null
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel1.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel2IsEqualToSomething() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel2 equals to DEFAULT_PRODUCT_LEVEL_2
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel2.equals=" + DEFAULT_PRODUCT_LEVEL_2);

        // Get all the tBProductBlockDetailsReportList where productLevel2 equals to UPDATED_PRODUCT_LEVEL_2
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel2.equals=" + UPDATED_PRODUCT_LEVEL_2);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel2IsInShouldWork() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel2 in DEFAULT_PRODUCT_LEVEL_2 or UPDATED_PRODUCT_LEVEL_2
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel2.in=" + DEFAULT_PRODUCT_LEVEL_2 + "," + UPDATED_PRODUCT_LEVEL_2);

        // Get all the tBProductBlockDetailsReportList where productLevel2 equals to UPDATED_PRODUCT_LEVEL_2
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel2.in=" + UPDATED_PRODUCT_LEVEL_2);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel2IsNullOrNotNull() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel2 is not null
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel2.specified=true");

        // Get all the tBProductBlockDetailsReportList where productLevel2 is null
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel2.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel3IsEqualToSomething() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel3 equals to DEFAULT_PRODUCT_LEVEL_3
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel3.equals=" + DEFAULT_PRODUCT_LEVEL_3);

        // Get all the tBProductBlockDetailsReportList where productLevel3 equals to UPDATED_PRODUCT_LEVEL_3
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel3.equals=" + UPDATED_PRODUCT_LEVEL_3);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel3IsInShouldWork() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel3 in DEFAULT_PRODUCT_LEVEL_3 or UPDATED_PRODUCT_LEVEL_3
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel3.in=" + DEFAULT_PRODUCT_LEVEL_3 + "," + UPDATED_PRODUCT_LEVEL_3);

        // Get all the tBProductBlockDetailsReportList where productLevel3 equals to UPDATED_PRODUCT_LEVEL_3
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel3.in=" + UPDATED_PRODUCT_LEVEL_3);
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByProductLevel3IsNullOrNotNull() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

        // Get all the tBProductBlockDetailsReportList where productLevel3 is not null
        defaultTBProductBlockDetailsReportShouldBeFound("productLevel3.specified=true");

        // Get all the tBProductBlockDetailsReportList where productLevel3 is null
        defaultTBProductBlockDetailsReportShouldNotBeFound("productLevel3.specified=false");
    }

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCreateDateIsEqualToSomething() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCreateDateIsInShouldWork() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByCreateDateIsNullOrNotNull() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByTbProductBlockDetailsIsEqualToSomething() throws Exception {
        // Initialize the database
        TBProductBlockDetails tbProductBlockDetails = TBProductBlockDetailsResourceIntTest.createEntity(em);
        em.persist(tbProductBlockDetails);
        em.flush();
        tBProductBlockDetailsReport.setTbProductBlockDetails(tbProductBlockDetails);
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);
        Long tbProductBlockDetailsId = tbProductBlockDetails.getId();

        // Get all the tBProductBlockDetailsReportList where tbProductBlockDetails equals to tbProductBlockDetailsId
        defaultTBProductBlockDetailsReportShouldBeFound("tbProductBlockDetailsId.equals=" + tbProductBlockDetailsId);

        // Get all the tBProductBlockDetailsReportList where tbProductBlockDetails equals to tbProductBlockDetailsId + 1
        defaultTBProductBlockDetailsReportShouldNotBeFound("tbProductBlockDetailsId.equals=" + (tbProductBlockDetailsId + 1));
    }


    @Test
    @Transactional
    public void getAllTBProductBlockDetailsReportsByTbCropIsEqualToSomething() throws Exception {
        // Initialize the database
        TBCrop tbCrop = TBCropResourceIntTest.createEntity(em);
        em.persist(tbCrop);
        em.flush();
        tBProductBlockDetailsReport.setTbCrop(tbCrop);
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);
        Long tbCropId = tbCrop.getId();

        // Get all the tBProductBlockDetailsReportList where tbCrop equals to tbCropId
        defaultTBProductBlockDetailsReportShouldBeFound("tbCropId.equals=" + tbCropId);

        // Get all the tBProductBlockDetailsReportList where tbCrop equals to tbCropId + 1
        defaultTBProductBlockDetailsReportShouldNotBeFound("tbCropId.equals=" + (tbCropId + 1));
    }

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

        // Check, that the count call also returns 1
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-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 defaultTBProductBlockDetailsReportShouldNotBeFound(String filter) throws Exception {
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-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
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-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 getNonExistingTBProductBlockDetailsReport() throws Exception {
        // Get the tBProductBlockDetailsReport
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/tb-product-block-details-reports/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateTBProductBlockDetailsReport() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

        // Update the tBProductBlockDetailsReport
        TBProductBlockDetailsReport updatedTBProductBlockDetailsReport = tBProductBlockDetailsReportRepository.findById(tBProductBlockDetailsReport.getId()).get();
        // Disconnect from session so that the updates on updatedTBProductBlockDetailsReport are not directly saved in db
        em.detach(updatedTBProductBlockDetailsReport);
        updatedTBProductBlockDetailsReport
            .code(UPDATED_CODE)
            .productLevel1(UPDATED_PRODUCT_LEVEL_1)
            .productLevel2(UPDATED_PRODUCT_LEVEL_2)
            .productLevel3(UPDATED_PRODUCT_LEVEL_3)
            .createDate(UPDATED_CREATE_DATE);
        TBProductBlockDetailsReportDTO tBProductBlockDetailsReportDTO = tBProductBlockDetailsReportMapper.toDto(updatedTBProductBlockDetailsReport);

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

        // Validate the TBProductBlockDetailsReport in the database
        List<TBProductBlockDetailsReport> tBProductBlockDetailsReportList = tBProductBlockDetailsReportRepository.findAll();
        assertThat(tBProductBlockDetailsReportList).hasSize(databaseSizeBeforeUpdate);
        TBProductBlockDetailsReport testTBProductBlockDetailsReport = tBProductBlockDetailsReportList.get(tBProductBlockDetailsReportList.size() - 1);
        assertThat(testTBProductBlockDetailsReport.getCode()).isEqualTo(UPDATED_CODE);
        assertThat(testTBProductBlockDetailsReport.getProductLevel1()).isEqualTo(UPDATED_PRODUCT_LEVEL_1);
        assertThat(testTBProductBlockDetailsReport.getProductLevel2()).isEqualTo(UPDATED_PRODUCT_LEVEL_2);
        assertThat(testTBProductBlockDetailsReport.getProductLevel3()).isEqualTo(UPDATED_PRODUCT_LEVEL_3);
        assertThat(testTBProductBlockDetailsReport.getCreateDate()).isEqualTo(UPDATED_CREATE_DATE);

        // Validate the TBProductBlockDetailsReport in Elasticsearch
        verify(mockTBProductBlockDetailsReportSearchRepository, times(1)).save(testTBProductBlockDetailsReport);
    }

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

        // Create the TBProductBlockDetailsReport
        TBProductBlockDetailsReportDTO tBProductBlockDetailsReportDTO = tBProductBlockDetailsReportMapper.toDto(tBProductBlockDetailsReport);

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

        // Validate the TBProductBlockDetailsReport in the database
        List<TBProductBlockDetailsReport> tBProductBlockDetailsReportList = tBProductBlockDetailsReportRepository.findAll();
        assertThat(tBProductBlockDetailsReportList).hasSize(databaseSizeBeforeUpdate);

        // Validate the TBProductBlockDetailsReport in Elasticsearch
        verify(mockTBProductBlockDetailsReportSearchRepository, times(0)).save(tBProductBlockDetailsReport);
    }

    @Test
    @Transactional
    public void deleteTBProductBlockDetailsReport() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);

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

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

        // Validate the database is empty
        List<TBProductBlockDetailsReport> tBProductBlockDetailsReportList = tBProductBlockDetailsReportRepository.findAll();
        assertThat(tBProductBlockDetailsReportList).hasSize(databaseSizeBeforeDelete - 1);

        // Validate the TBProductBlockDetailsReport in Elasticsearch
        verify(mockTBProductBlockDetailsReportSearchRepository, times(1)).deleteById(tBProductBlockDetailsReport.getId());
    }

    @Test
    @Transactional
    public void searchTBProductBlockDetailsReport() throws Exception {
        // Initialize the database
        tBProductBlockDetailsReportRepository.saveAndFlush(tBProductBlockDetailsReport);
        when(mockTBProductBlockDetailsReportSearchRepository.search(queryStringQuery("id:" + tBProductBlockDetailsReport.getId()), PageRequest.of(0, 20)))
            .thenReturn(new PageImpl<>(Collections.singletonList(tBProductBlockDetailsReport), PageRequest.of(0, 1), 1));
        // Search the tBProductBlockDetailsReport
        restTBProductBlockDetailsReportMockMvc.perform(get("/api/_search/tb-product-block-details-reports?query=id:" + tBProductBlockDetailsReport.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(tBProductBlockDetailsReport.getId().intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].productLevel1").value(hasItem(DEFAULT_PRODUCT_LEVEL_1.doubleValue())))
            .andExpect(jsonPath("$.[*].productLevel2").value(hasItem(DEFAULT_PRODUCT_LEVEL_2.doubleValue())))
            .andExpect(jsonPath("$.[*].productLevel3").value(hasItem(DEFAULT_PRODUCT_LEVEL_3.doubleValue())))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())));
    }

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

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

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