@Before
 public void initTest() {
   promotion = new Promotion();
   promotion.setName(DEFAULT_NAME);
   promotion.setPercent(DEFAULT_PERCENT);
   promotion.setReduction(DEFAULT_REDUCTION);
 }
  @Test
  @Transactional
  public void getPromotion() throws Exception {
    // Initialize the database
    promotionRepository.saveAndFlush(promotion);

    // Get the promotion
    restPromotionMockMvc
        .perform(get("/api/promotions/{id}", promotion.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(promotion.getId().intValue()))
        .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString()))
        .andExpect(jsonPath("$.percent").value(DEFAULT_PERCENT))
        .andExpect(jsonPath("$.reduction").value(DEFAULT_REDUCTION.doubleValue()));
  }
  @Test
  @Transactional
  public void updatePromotion() throws Exception {
    // Initialize the database
    promotionRepository.saveAndFlush(promotion);

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

    // Update the promotion
    promotion.setName(UPDATED_NAME);
    promotion.setPercent(UPDATED_PERCENT);
    promotion.setReduction(UPDATED_REDUCTION);

    restPromotionMockMvc
        .perform(
            put("/api/promotions")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(promotion)))
        .andExpect(status().isOk());

    // Validate the Promotion in the database
    List<Promotion> promotions = promotionRepository.findAll();
    assertThat(promotions).hasSize(databaseSizeBeforeUpdate);
    Promotion testPromotion = promotions.get(promotions.size() - 1);
    assertThat(testPromotion.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testPromotion.getPercent()).isEqualTo(UPDATED_PERCENT);
    assertThat(testPromotion.getReduction()).isEqualTo(UPDATED_REDUCTION);
  }
  @Test
  @Transactional
  public void createPromotion() throws Exception {
    int databaseSizeBeforeCreate = promotionRepository.findAll().size();

    // Create the Promotion

    restPromotionMockMvc
        .perform(
            post("/api/promotions")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(promotion)))
        .andExpect(status().isCreated());

    // Validate the Promotion in the database
    List<Promotion> promotions = promotionRepository.findAll();
    assertThat(promotions).hasSize(databaseSizeBeforeCreate + 1);
    Promotion testPromotion = promotions.get(promotions.size() - 1);
    assertThat(testPromotion.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testPromotion.getPercent()).isEqualTo(DEFAULT_PERCENT);
    assertThat(testPromotion.getReduction()).isEqualTo(DEFAULT_REDUCTION);
  }
  @Test
  @Transactional
  public void deletePromotion() throws Exception {
    // Initialize the database
    promotionRepository.saveAndFlush(promotion);

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

    // Get the promotion
    restPromotionMockMvc
        .perform(
            delete("/api/promotions/{id}", promotion.getId())
                .accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<Promotion> promotions = promotionRepository.findAll();
    assertThat(promotions).hasSize(databaseSizeBeforeDelete - 1);
  }
  @Test
  @Transactional
  public void checkReductionIsRequired() throws Exception {
    int databaseSizeBeforeTest = promotionRepository.findAll().size();
    // set the field null
    promotion.setReduction(null);

    // Create the Promotion, which fails.

    restPromotionMockMvc
        .perform(
            post("/api/promotions")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(promotion)))
        .andExpect(status().isBadRequest());

    List<Promotion> promotions = promotionRepository.findAll();
    assertThat(promotions).hasSize(databaseSizeBeforeTest);
  }