@SuppressWarnings("serial")
  private String getTestProductRatePlan(final String productId) {
    SaveResult saveResult = null;

    try {
      saveResult =
          module
              .create(
                  ZObjectType.ProductRatePlan,
                  Collections.<Map<String, Object>>singletonList(
                      new HashMap<String, Object>() {
                        {
                          put("ProductId", productId);
                          put("Name", "TestProductRatePlan");
                          put("EffectiveStartDate", "2011-01-01T20:00:00");
                          put("EffectiveEndDate", "2013-01-01T20:00:00");
                          put("Description", "Test product used in unit test.");
                        }
                      }))
              .get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    return saveResult.getId();
  }
Exemplo n.º 2
0
  public void testZUpdate()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];
      assertTrue("Found JTest Product", p1.getDescription().equals("JTest Description"));

      p1.setDescription("JTest Description 2");
      SaveResult[] sr = zapi.zUpdate(new ZObject[] {p1});
      if (!sr[0].getSuccess()) {
        System.out.println(sr[0].getErrors()[0].getMessage());
      }
      assertTrue("Updated Product", sr[0].getSuccess());

      QueryResult qres2 =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods2 = qres2.getRecords();
      Product p2 = (Product) zprods2[0];
      assertTrue("Found Updated JTest Product", p2.getDescription().equals("JTest Description 2"));

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  @SuppressWarnings("serial")
  private String getTestProduct() {

    Map<String, Object> returnMap = new HashMap<String, Object>();

    SaveResult saveResult = null;

    try {
      saveResult =
          module
              .create(
                  ZObjectType.Product,
                  Collections.<Map<String, Object>>singletonList(
                      new HashMap<String, Object>() {
                        {
                          put("Name", "UnitTestProduct");
                          put("EffectiveStartDate", "2011-01-01T20:00:00");
                          put("EffectiveEndDate", "2013-01-01T20:00:00");
                        }
                      }))
              .get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    return saveResult.getId();
  }
Exemplo n.º 4
0
 public void testZLogin() {
   try {
     ZApi zapi = new ZApi();
     assertTrue("Logged in", zapi.isLoggedIn);
   } catch (Exception e) {
     e.printStackTrace();
     fail(e.getMessage());
   }
 }
Exemplo n.º 5
0
  public void testZQuery()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Name,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];

      assertTrue("Found JTest Product", p1.getDescription().equals("JTest Description"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Exemplo n.º 6
0
  public void testZDelete()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault, InvalidValueFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];

      DeleteResult[] delRes = zapi.zDelete(new String[] {p1.getId()}, "Product");
      assertTrue(delRes[0].getSuccess());
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  @SuppressWarnings("serial")
  private String getTestProductRatePlanCharge(final String productRatePlanId) {
    ProductRatePlanChargeTier tier = new ProductRatePlanChargeTier();
    tier.setCurrency("USD");
    tier.setPrice(new BigDecimal(12.2));
    tier.setTier(1);
    tier.setActive(true);
    final ProductRatePlanChargeTierData productRatePlanChargeTierData =
        new ProductRatePlanChargeTierData();
    productRatePlanChargeTierData.getProductRatePlanChargeTier().add(tier);

    SaveResult saveResult = null;

    try {
      saveResult =
          module
              .create(
                  ZObjectType.ProductRatePlanCharge,
                  Collections.<Map<String, Object>>singletonList(
                      new HashMap<String, Object>() {
                        {
                          put("BillingPeriod", "Month");
                          put("ChargeModel", "FlatFee");
                          put("ChargeType", "Recurring");
                          put("DefaultQuantity", "1	");
                          put("Model", "PerUnit");
                          put("Name", "TestProductRatePlanCharge");
                          put("ProductRatePlanId", productRatePlanId);
                          put("ProductRatePlanChargeTierData", productRatePlanChargeTierData);
                          put("TriggerEvent", "ContractEffective");
                          put("Type", "Recurring");
                        }
                      }))
              .get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    return saveResult.getId();
  }
Exemplo n.º 8
0
  public void testZCreate() throws RemoteException, UnexpectedErrorFault, InvalidTypeFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      Product testProd = new Product();
      testProd.setName("JTest Product");
      testProd.setDescription("JTest Description");
      Calendar sdate = Calendar.getInstance();
      Calendar edate = Calendar.getInstance();
      sdate.add(Calendar.YEAR, -50);
      edate.add(Calendar.YEAR, 50);
      testProd.setEffectiveStartDate(sdate);
      testProd.setEffectiveEndDate(edate);

      SaveResult[] sr = zapi.zCreate(new ZObject[] {testProd});
      assertTrue("Created Product", sr[0].getSuccess());

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  /** Test for fetching zobjects when there is an object that matches the query */
  @Test
  public void getInvoice() throws Exception {

    // Setup Product details
    String productId = getTestProduct();
    String productRatePlanId = getTestProductRatePlan(productId);
    String productRateplanChargeId = getTestProductRatePlanCharge(productRatePlanId);

    assertNotNull(productId);
    assertNotNull(productRatePlanId);
    assertNotNull(productRateplanChargeId);

    SubscribeRequest subscribeReq = new SubscribeRequest();

    // subscribeReq.setAccount(testAccount());
    String uniqueString = UUID.randomUUID().toString();

    Contact contact = new Contact();
    contact.setFirstName(uniqueString);
    contact.setLastName(uniqueString);

    Account account = new Account();
    account.setName(uniqueString);
    account.setBillCycleDay(1);
    account.setCurrency("USD");
    account.setAllowInvoiceEdit(false);
    account.setAutoPay(false);
    account.setStatus("Draft");
    account.setPaymentTerm("Due Upon Receipt");
    account.setBatch("Batch1");

    PaymentMethod paymentMethod = new PaymentMethod();
    paymentMethod.setType("CreditCard");
    paymentMethod.setCreditCardNumber("5105105105105100");
    paymentMethod.setCreditCardType("Visa");
    paymentMethod.setCreditCardExpirationYear(2026);
    paymentMethod.setCreditCardExpirationMonth(5);
    paymentMethod.setCreditCardHolderName("Unit Test");

    // Generate Start and stop days for subscription
    XMLGregorianCalendar effectiveStartDate = null;
    XMLGregorianCalendar effectiveEndDate = null;
    try {
      GregorianCalendar calStart = new GregorianCalendar();
      // calStart.setTime(now);
      calStart.add(Calendar.DATE, -1);

      GregorianCalendar calEnd = new GregorianCalendar();
      // calEnd.setTime(now);
      calEnd.add(Calendar.DATE, 1);

      effectiveStartDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);
      effectiveEndDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);

    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Subscription subscription = new Subscription();
    subscription.setContractAcceptanceDate(effectiveStartDate);
    subscription.setContractEffectiveDate(effectiveStartDate);
    subscription.setInitialTerm(12);
    subscription.setRenewalTerm(12);

    RatePlan ratePlan = new RatePlan();
    ratePlan.setProductRatePlanId(productRatePlanId);
    RatePlanData ratePlanData = new RatePlanData();
    ratePlanData.setRatePlan(ratePlan);

    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setSubscription(subscription);
    subscriptionData.getRatePlanData().add(ratePlanData);

    subscribeReq.setAccount(account);
    subscribeReq.setBillToContact(contact);
    subscribeReq.setSoldToContact(contact);
    subscribeReq.setPaymentMethod(paymentMethod);
    subscribeReq.setSubscriptionData(subscriptionData);

    SubscribeResult subscribeResult =
        module.subscribe(Collections.singletonList(subscribeReq)).get(0);
    assertTrue(subscribeResult.isSuccess());
    assertEquals(0, subscribeResult.getErrors().size());

    Map<String, Object> result = module.getInvoice(subscribeResult.getInvoiceId());

    System.out.println("Result = " + result);

    assertEquals("Posted", result.get("status"));
    // assertEquals("amount",result.get("amount"));
    assertNotSame(0, ((ArrayList) result.get("invoiceitems")).size());

    assertNotNull(result.get("billTo"));
    assertNotNull(result.get("soldTo"));

    DeleteResult deleteResultAccount = null;
    DeleteResult deleteResultProduct = null;
    try {
      deleteResultAccount =
          module
              .delete(
                  ZObjectType.Account, Collections.singletonList(subscribeResult.getAccountId()))
              .get(0);
      deleteResultProduct =
          module.delete(ZObjectType.Product, Collections.singletonList(productId)).get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    assertTrue(deleteResultAccount.isSuccess());
    assertTrue(deleteResultProduct.isSuccess());
  }