/**
* This code was auto-generated by a tool.
*
* Changes to this file may cause incorrect behavior and will be lost if
* the code is regenerated.
*/
package com.mozu.test.framework.datafactory;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import org.apache.http.HttpStatus;
import org.joda.time.DateTime;
import com.mozu.api.ApiException;
import com.mozu.api.ApiContext;
import com.mozu.test.framework.core.TestFailException;
import com.mozu.api.resources.commerce.catalog.admin.couponsets.CouponResource;
/** <summary>
* Use the Coupons subresource to manage coupons within manual coupon sets.
* </summary>
*/
public class CouponFactory
{
public static com.mozu.api.contracts.productadmin.Coupon getCoupon(ApiContext apiContext, String couponSetCode, String couponCode, int expectedCode) throws Exception
{
return getCoupon(apiContext, couponSetCode, couponCode, null, null, expectedCode);
}
public static com.mozu.api.contracts.productadmin.Coupon getCoupon(ApiContext apiContext, String couponSetCode, String couponCode, Boolean includeCounts, String responseFields, int expectedCode) throws Exception
{
com.mozu.api.contracts.productadmin.Coupon returnObj = new com.mozu.api.contracts.productadmin.Coupon();
CouponResource resource = new CouponResource(apiContext);
try
{
returnObj = resource.getCoupon( couponSetCode, couponCode, includeCounts, responseFields);
}
catch (ApiException e)
{
if(e.getHttpStatusCode() != expectedCode)
throw new TestFailException("" + e.getHttpStatusCode(), Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
else
return null;
}
if(expectedCode != 304 && !(expectedCode >= 200 && expectedCode <= 300) && !(expectedCode == HttpStatus.SC_NOT_FOUND && returnObj == null))
throw new TestFailException("304 or between 200 and 300", Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
return returnObj;
}
public static com.mozu.api.contracts.productadmin.CouponCollection getCoupons(ApiContext apiContext, String couponSetCode, int expectedCode) throws Exception
{
return getCoupons(apiContext, couponSetCode, null, null, null, null, null, null, expectedCode);
}
public static com.mozu.api.contracts.productadmin.CouponCollection getCoupons(ApiContext apiContext, String couponSetCode, Integer startIndex, Integer pageSize, String sortBy, String filter, Boolean includeCounts, String responseFields, int expectedCode) throws Exception
{
com.mozu.api.contracts.productadmin.CouponCollection returnObj = new com.mozu.api.contracts.productadmin.CouponCollection();
CouponResource resource = new CouponResource(apiContext);
try
{
returnObj = resource.getCoupons( couponSetCode, startIndex, pageSize, sortBy, filter, includeCounts, responseFields);
}
catch (ApiException e)
{
if(e.getHttpStatusCode() != expectedCode)
throw new TestFailException("" + e.getHttpStatusCode(), Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
else
return null;
}
if(expectedCode != 304 && !(expectedCode >= 200 && expectedCode <= 300) && !(expectedCode == HttpStatus.SC_NOT_FOUND && returnObj == null))
throw new TestFailException("304 or between 200 and 300", Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
return returnObj;
}
public static void addCoupons(ApiContext apiContext, List<com.mozu.api.contracts.productadmin.Coupon> coupons, String couponSetCode, int expectedCode) throws Exception
{
CouponResource resource = new CouponResource(apiContext);
try
{
resource.addCoupons( coupons, couponSetCode);
}
catch (ApiException e)
{
if(e.getHttpStatusCode() != expectedCode)
throw new TestFailException("" + e.getHttpStatusCode(), Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
else
return;
}
if(expectedCode != 304 && !(expectedCode >= 200 && expectedCode <= 300))
throw new TestFailException("304 or between 200 and 300", Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
}
public static void deleteCoupons(ApiContext apiContext, List<String> couponCodes, String couponSetCode, int expectedCode) throws Exception
{
CouponResource resource = new CouponResource(apiContext);
try
{
resource.deleteCoupons( couponCodes, couponSetCode);
}
catch (ApiException e)
{
if(e.getHttpStatusCode() != expectedCode)
throw new TestFailException("" + e.getHttpStatusCode(), Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
else
return;
}
if(expectedCode != 304 && !(expectedCode >= 200 && expectedCode <= 300))
throw new TestFailException("304 or between 200 and 300", Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
}
public static void deleteCoupon(ApiContext apiContext, String couponSetCode, String couponCode, int expectedCode) throws Exception
{
CouponResource resource = new CouponResource(apiContext);
try
{
resource.deleteCoupon( couponSetCode, couponCode);
}
catch (ApiException e)
{
if(e.getHttpStatusCode() != expectedCode)
throw new TestFailException("" + e.getHttpStatusCode(), Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
else
return;
}
if(expectedCode != 304 && !(expectedCode >= 200 && expectedCode <= 300))
throw new TestFailException("304 or between 200 and 300", Thread.currentThread().getStackTrace()[2].getMethodName(), "" + expectedCode, "");
}
}