use of org.wso2.carbon.apimgt.impl.utils.APIUtil in project carbon-apimgt by wso2.
the class APIUtilTierTest method testBillingPlanAndCustomAttr.
/**
* Test whether the APIUtil properly converts the billing plan and the custom attributes in the SubscriptionPolicy
* when constructing the Tier object.
*/
@Test
public void testBillingPlanAndCustomAttr() throws Exception {
SubscriptionPolicy policy = new SubscriptionPolicy("JUnitTest");
JSONArray jsonArray = new JSONArray();
JSONObject json1 = new JSONObject();
json1.put("name", "key1");
json1.put("value", "value1");
jsonArray.add(json1);
JSONObject json2 = new JSONObject();
json2.put("name", "key2");
json2.put("value", "value2");
jsonArray.add(json2);
policy.setCustomAttributes(jsonArray.toJSONString().getBytes());
policy.setBillingPlan("FREE");
Tier tier = new Tier("JUnitTest");
APIUtil.setBillingPlanAndCustomAttributesToTier(policy, tier);
Assert.assertTrue("Expected FREE but received " + tier.getTierPlan(), "FREE".equals(tier.getTierPlan()));
if ("key1".equals(tier.getTierAttributes().get("name"))) {
Assert.assertTrue("Expected to have 'value1' as the value of 'key1' but found " + tier.getTierAttributes().get("value"), tier.getTierAttributes().get("value").equals("value1"));
}
if ("key2".equals(tier.getTierAttributes().get("name"))) {
Assert.assertTrue("Expected to have 'value2' as the value of 'key2' but found " + tier.getTierAttributes().get("value"), tier.getTierAttributes().get("value").equals("value2"));
}
}
Aggregations