@Test public void test001CreateCustomerWithAitMetaFields_DefaultDate() throws Exception { System.out.println("#test001CreateCustomerWithAitMetaFields_DefaultDate"); JbillingAPI api = JbillingAPIFactory.getAPI(); Integer userId = null; try { UserWS newUser = createUser(); System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE); MetaFieldValueWS metaField1 = new MetaFieldValueWS(); metaField1.setFieldName("partner.prompt.fee"); metaField1.setValue("serial-from-ws"); MetaFieldValueWS metaField2 = new MetaFieldValueWS(); metaField2.setFieldName("ccf.payment_processor"); metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor String email = newUser.getUserName() + "@shire.com"; String firstName = "Frodo"; String lastName = "Baggins"; MetaFieldValueWS metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue(email); metaField3.setGroupId(1); MetaFieldValueWS metaField4 = new MetaFieldValueWS(); metaField4.setFieldName("contact.first.name"); metaField4.setValue(firstName); metaField4.setGroupId(1); MetaFieldValueWS metaField5 = new MetaFieldValueWS(); metaField5.setFieldName("contact.last.name"); metaField5.setValue(lastName); metaField5.setGroupId(1); newUser.setMetaFields( new MetaFieldValueWS[] {metaField1, metaField2, metaField3, metaField4, metaField5}); System.out.println("Setting default date as the only date of timeline"); ArrayList<Date> timelineDates = new ArrayList<Date>(0); timelineDates.add(CommonConstants.EPOCH_DATE); newUser.getTimelineDatesMap().put(new Integer(1), timelineDates); System.out.println("Creating user ..."); userId = api.createUser(newUser); newUser.setUserId(userId); System.out.println("Getting created user"); UserWS ret = api.getUserWS(newUser.getUserId()); ArrayList<MetaFieldValueWS> aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE); // check that timeline contains default date if (!ret.getAccountInfoTypeFieldsMap() .get(new Integer(1)) .containsKey(CommonConstants.EPOCH_DATE)) { fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline"); } // Total no of ait meta fields returned should be 18, no of meta fields for ait = 1, only 3 // has values assertEquals(3, aitMetaFields.size()); // ait meta fields should be 11. Customer Specific: 8 (2 has value). Ait meta field for // effective date: 18 (3 has values) assertEquals(5, ret.getMetaFields().length); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", email, ws.getValue()); } else if (ws.getFieldName().equals("contact.first.name")) { assertEquals("First name should be same", firstName, ws.getValue()); } else if (ws.getFieldName().equals("contact.last.name")) { assertEquals("Last name should be same", lastName, ws.getValue()); } } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } finally { System.out.println("Deleting created user"); if (userId != null) api.deleteUser(userId); } }
@Test public void test003CreateCustomerWithAitMetaFields_UpdateTodaysFields() throws Exception { System.out.println("#test003CreateCustomerWithAitMetaFields_UpdateTodaysFields"); JbillingAPI api = JbillingAPIFactory.getAPI(); Integer userId = null; try { UserWS newUser = createUser(); System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE); MetaFieldValueWS metaField1 = new MetaFieldValueWS(); metaField1.setFieldName("partner.prompt.fee"); metaField1.setValue("serial-from-ws"); MetaFieldValueWS metaField2 = new MetaFieldValueWS(); metaField2.setFieldName("ccf.payment_processor"); metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor MetaFieldValueWS metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue("*****@*****.**"); metaField3.setGroupId(1); newUser.setMetaFields(new MetaFieldValueWS[] {metaField1, metaField2, metaField3}); Date today = new DateTime().toDateMidnight().toDate(); System.out.println("Setting default date and todays date on timeline"); ArrayList<Date> timelineDates = new ArrayList<Date>(0); timelineDates.add(CommonConstants.EPOCH_DATE); timelineDates.add(today); newUser.getTimelineDatesMap().put(new Integer(1), timelineDates); System.out.println("Creating user ..."); userId = api.createUser(newUser); newUser.setUserId(userId); System.out.println("Getting created user"); UserWS ret = api.getUserWS(newUser.getUserId()); // Update todays ait meta field value for the created users metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue("*****@*****.**"); metaField3.setGroupId(1); ret.setMetaFields(new MetaFieldValueWS[] {metaField1, metaField2, metaField3}); ret.getEffectiveDateMap().put(1, today); api.updateUser(ret); // get updated user ret = api.getUserWS(newUser.getUserId()); // check that timeline contains default date and today's date if (!ret.getAccountInfoTypeFieldsMap() .get(new Integer(1)) .containsKey(CommonConstants.EPOCH_DATE)) { fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline"); } if (!ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).containsKey(today)) { fail("Default date: " + today + " should be present in timeline"); } // verify meta fields for default date ArrayList<MetaFieldValueWS> aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE); // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but // only // one has a value assertEquals(1, aitMetaFields.size()); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", "*****@*****.**", ws.getValue()); } } // verify meta fields for todays date aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(today); // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but // only // one has a value assertEquals(1, aitMetaFields.size()); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", "*****@*****.**", ws.getValue()); } } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } finally { // Change System.out.println("Deleting created user"); if (userId != null) api.deleteUser(userId); } }