Search in sources :

Example 1 with APIUtil

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"));
    }
}
Also used : JSONObject(org.json.simple.JSONObject) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) Tier(org.wso2.carbon.apimgt.api.model.Tier) JSONArray(org.json.simple.JSONArray) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Tier (org.wso2.carbon.apimgt.api.model.Tier)1 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)1