Search in sources :

Example 16 with Response

use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.

the class PurchaseManagerTest method testIsPurchaseValidForExpiredExistentPurchase.

/**
 * tests isPurchaseValid for expired existent purchase
 */
@Test
public void testIsPurchaseValidForExpiredExistentPurchase() throws Exception {
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    Receipt receipt = TestUtils.createReceipt("subSku", "subSku", new Date(), new Date());
    mPurchaseManager.mReceiptMap.put("subSku", receipt);
    mPurchaseManager.isPurchaseValid("subSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.SUCCESSFUL, response.getStatus());
            assertFalse(validity);
            verify(purchaseSystem).notifyFulfillment(any(String.class), any(UserData.class), any(Receipt.class), any(Receipt.FulfillmentStatus.class));
            assertFalse(mPurchaseManager.mReceiptMap.containsKey("subSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Response

use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.

the class PurchaseManagerTest method testIsPurchaseValidForReceiptValidSystemFailure.

/**
 * tests isPurchaseValid for receipt validation system failure
 */
@Test
public void testIsPurchaseValidForReceiptValidSystemFailure() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.FAILED, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(false).when(mockPurchaseSystem).receiptValidResponse();
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    Receipt receipt = TestUtils.createReceipt("rentSku", "rentSku", DateAndTimeHelper.addSeconds(new Date(), 25), null);
    mPurchaseManager.mReceiptMap.put("rentSku", receipt);
    mPurchaseManager.isPurchaseValid("rentSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.FAILED, response.getStatus());
            assertFalse(validity);
            assertTrue(mPurchaseManager.mReceiptMap.containsKey("rentSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Response

use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.

the class PurchaseManagerTest method testPurchaseFailure.

/**
 * Tests purchase failure
 */
@Test
public void testPurchaseFailure() throws Exception {
    Response purchaseResponse = new Response("purchaseRequest", Response.Status.FAILED, null);
    doReturn(purchaseResponse).when(mockPurchaseSystem).purchaseListenerResponse();
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    mPurchaseManager.purchaseSku("subSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.FAILED, response.getStatus());
            assertFalse(validity);
            assertFalse(mPurchaseManager.mReceiptMap.containsKey("subSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Test(org.junit.Test)

Example 19 with Response

use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.

the class PurchaseManagerTest method testIsPurchaseValidForValidPurchase.

/**
 * tests isPurchaseValid for valid purchase
 */
@Test
public void testIsPurchaseValidForValidPurchase() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.SUCCESSFUL, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(true).when(mockPurchaseSystem).receiptValidResponse();
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    Receipt receipt = TestUtils.createReceipt("rentSku", "rentSku", DateAndTimeHelper.addSeconds(new Date(), 25), null);
    mPurchaseManager.mReceiptMap.put("rentSku", receipt);
    mPurchaseManager.isPurchaseValid("rentSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.SUCCESSFUL, response.getStatus());
            assertTrue(validity);
            assertTrue(mPurchaseManager.mReceiptMap.containsKey("rentSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Response

use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.

the class PurchaseManagerTest method testIsPurchaseValidForNonValidPurchase.

/**
 * tests isPurchaseValid for non valid purchase
 */
@Test
public void testIsPurchaseValidForNonValidPurchase() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.SUCCESSFUL, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(false).when(mockPurchaseSystem).receiptValidResponse();
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    Receipt receipt = TestUtils.createReceipt("rentSku", "rentSku", DateAndTimeHelper.addSeconds(new Date(), 25), null);
    mPurchaseManager.mReceiptMap.put("rentSku", receipt);
    mPurchaseManager.isPurchaseValid("rentSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.SUCCESSFUL, response.getStatus());
            assertFalse(validity);
            assertFalse(mPurchaseManager.mReceiptMap.containsKey("rentSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Response (com.amazon.purchase.model.Response)21 Receipt (com.amazon.purchase.model.Receipt)11 Test (org.junit.Test)10 Date (java.util.Date)6 Product (com.amazon.purchase.model.Product)3 UserData (com.amazon.purchase.model.UserData)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Bundle (android.os.Bundle)1 PurchasingListener (com.amazon.device.iap.PurchasingListener)1 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)1 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)1 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)1 UserDataResponse (com.amazon.device.iap.model.UserDataResponse)1 IPurchase (com.amazon.purchase.IPurchase)1 PurchaseManagerListener (com.amazon.purchase.PurchaseManagerListener)1 Gson (com.google.gson.Gson)1 MarketplaceConnectBody (com.zype.fire.api.Model.MarketplaceConnectBody)1 MarketplaceConnectBodyData (com.zype.fire.api.Model.MarketplaceConnectBodyData)1 HashMap (java.util.HashMap)1