/** Test for creating zobjects with relationships */ @Test @SuppressWarnings("serial") public void createAndDeleteRelated() throws Exception { SaveResult saveResult = module.create(ZObjectType.Account, Collections.singletonList(testAccount())).get(0); assertTrue(saveResult.isSuccess()); final String accountId = saveResult.getId(); try { SaveResult result = module .create( ZObjectType.Contact, Collections.<Map<String, Object>>singletonList( new HashMap<String, Object>() { { put("Country", "US"); put("FirstName", "John"); put("LastName", "Doe"); put("AccountId", accountId); } })) .get(0); assertTrue(result.isSuccess()); DeleteResult deleteResult = module.delete(ZObjectType.Contact, Arrays.asList(result.getId())).get(0); assertTrue(deleteResult.isSuccess()); } finally { module.delete(ZObjectType.Account, Arrays.asList(accountId)).get(0); } }
@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(); }
@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(); }
/** Test for creating dynamic zobjects */ @Test public void createAndDelete() throws Exception { SaveResult result = module.create(ZObjectType.Account, Collections.singletonList(testAccount())).get(0); assertTrue(result.isSuccess()); DeleteResult deleteResult = module.delete(ZObjectType.Account, Arrays.asList(result.getId())).get(0); assertTrue(deleteResult.isSuccess()); }
@Test @SuppressWarnings("serial") public void createRetrieveAnAccountProfileAndDeleteRelatedAccount() throws Exception { SaveResult accountResult = module.create(ZObjectType.Account, Collections.singletonList(testAccount())).get(0); assertTrue(accountResult.isSuccess()); final String accountId = accountResult.getId(); try { SaveResult contactResult = module .create( ZObjectType.Contact, Collections.<Map<String, Object>>singletonList( new HashMap<String, Object>() { { put("Country", "US"); put("FirstName", "John"); put("LastName", "Doe"); put("AccountId", accountId); } })) .get(0); assertTrue(contactResult.isSuccess()); Map<String, Object> accountMap = testAccount(); accountMap.put("Id", accountId); accountMap.put("BillToId", contactResult.getId()); SaveResult accountUpdateResult = module.update(ZObjectType.Account, Collections.singletonList(accountMap)).get(0); assertTrue(accountUpdateResult.isSuccess()); Map<String, Object> accountProfile = module.accountProfile(accountId); assertEquals("Doe", ((Map<String, Object>) accountProfile.get("billTo")).get("lastName")); } finally { module.delete(ZObjectType.Account, Arrays.asList(accountId)).get(0); } }
/** Test for fetching zobjects when there is an object that matches the query */ @Test public void findOneResult() throws Exception { String id = module.create(ZObjectType.Account, Collections.singletonList(testAccount())).get(0).getId(); try { Iterator<ZObject> result = module .find("SELECT Id, Name, AccountNumber FROM Account WHERE AccountNumber = '7891'") .iterator(); assertTrue(result.hasNext()); ZObject next = result.next(); assertNotNull(next.getId()); assertEquals(testAccount().get("Name"), next.getAt("Name")); assertFalse(result.hasNext()); } finally { module.delete(ZObjectType.Account, Arrays.asList(id)); } }
@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(); }