コード例 #1
0
  @Test
  public void testDeleteCouponServletWithEmptyCoupon() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn("");
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("Coupon code is empty or not valid"));
  }
コード例 #2
0
  @Test
  public void testDeleteCouponServletWithNullCoupon() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(null);
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("Coupon not found in the DB"));
  }
コード例 #3
0
  @Test
  public void testDeleteCouponServletOK() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    CouponsRecord couponRecord = buildSuccessfulCouponRecord();

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(couponRecord);
    when(couponPluginApi.getActiveCouponsAppliedByCouponCode(anyString()))
        .thenReturn(new ArrayList());
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("has been successfully deleted"));
  }
コード例 #4
0
  @Test
  public void testDeleteCouponServletWithCouponApplicationActive() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    List<CouponsAppliedRecord> mockListOfActiveCouponsApplied = buildListOfActiveCouponsApplied();
    CouponsRecord couponRecord = buildSuccessfulCouponRecord();

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(couponRecord);
    when(couponPluginApi.getActiveCouponsAppliedByCouponCode(anyString()))
        .thenReturn(mockListOfActiveCouponsApplied);
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(
        stringWriter
            .toString()
            .contains("has currently active applications and cannot be deleted"));
  }