Java Code Examples for org.wso2.carbon.apimgt.impl.APIConstants#DEFAULT_SUB_POLICY_BRONZE

The following examples show how to use org.wso2.carbon.apimgt.impl.APIConstants#DEFAULT_SUB_POLICY_BRONZE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIUtilTierTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddDefaultSuperTenantAdvancedThrottlePoliciesSubLevel() throws Exception {
    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();

    String[] subPolicies = new String[]{APIConstants.DEFAULT_SUB_POLICY_GOLD, APIConstants.DEFAULT_SUB_POLICY_SILVER,
            APIConstants.DEFAULT_SUB_POLICY_BRONZE, APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED,
            APIConstants.DEFAULT_SUB_POLICY_UNLIMITED};

    for (String policy : subPolicies) {
        Mockito.when(
                apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(MultitenantConstants.SUPER_TENANT_ID),
                        eq(policy))).thenReturn(false);
    }

    try {
        APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies();
        Mockito.verify(apiMgtDAO, Mockito.times(subPolicies.length)).addSubscriptionPolicy(Mockito.any(SubscriptionPolicy.class));
    } catch (APIManagementException e) {
        Assert.assertTrue("Exception thrown", false);
    }
}
 
Example 2
Source File: APIUtilTierTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddDefaultSuperTenantAdvancedThrottlePoliciesSubLevelAlreadyAdded() throws Exception {
    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();

    String[] subPolicies = new String[]{APIConstants.DEFAULT_SUB_POLICY_GOLD, APIConstants.DEFAULT_SUB_POLICY_SILVER,
            APIConstants.DEFAULT_SUB_POLICY_BRONZE, APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED,
            APIConstants.DEFAULT_SUB_POLICY_UNLIMITED};

    for (String policy : subPolicies) {
        Mockito.when(
                apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(MultitenantConstants.SUPER_TENANT_ID),
                        eq(policy))).thenReturn(true);
    }

    try {
        APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies();
        Mockito.verify(apiMgtDAO, Mockito.never()).addSubscriptionPolicy(Mockito.any(SubscriptionPolicy.class));
    } catch (APIManagementException e) {
        Assert.assertTrue("Exception thrown", false);
    }
}
 
Example 3
Source File: APIUtilTierTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddDefaultTenantAdvancedThrottlePoliciesSubLevel() throws Exception {
    int tenantId = 1;
    String tenantDomain = "test.com";

    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();

    ThrottlePolicyTemplateBuilder templateBuilder = Mockito.mock(ThrottlePolicyTemplateBuilder.class);
    PowerMockito.whenNew(ThrottlePolicyTemplateBuilder.class).withNoArguments().thenReturn(templateBuilder);

    String[] policies = new String[]{APIConstants.DEFAULT_SUB_POLICY_GOLD, APIConstants.DEFAULT_SUB_POLICY_SILVER,
            APIConstants.DEFAULT_SUB_POLICY_BRONZE, APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED,
            APIConstants.DEFAULT_SUB_POLICY_UNLIMITED};

    for (String policy : policies) {
        Mockito.when(
                apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(tenantId),
                        eq(policy))).thenReturn(false);
        Mockito.when(
                apiMgtDAO.isPolicyDeployed(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(tenantId),
                        eq(policy))).thenReturn(false);
    }

    APIUtil.addDefaultTenantAdvancedThrottlePolicies(tenantDomain, tenantId);
    Mockito.verify(apiMgtDAO, Mockito.times(policies.length)).
            addSubscriptionPolicy(Mockito.any(SubscriptionPolicy.class));
    Mockito.verify(apiMgtDAO, Mockito.times(policies.length)).
            setPolicyDeploymentStatus(eq(PolicyConstants.POLICY_LEVEL_SUB), Mockito.anyString(), eq(tenantId), eq(true));
}
 
Example 4
Source File: APIUtilTierTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddDefaultTenantAdvancedThrottlePoliciesSubLevelAlreadyAdded() throws Exception {
    int tenantId = 1;
    String tenantDomain = "test.com";

    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();

    ThrottlePolicyTemplateBuilder templateBuilder = Mockito.mock(ThrottlePolicyTemplateBuilder.class);
    PowerMockito.whenNew(ThrottlePolicyTemplateBuilder.class).withNoArguments().thenReturn(templateBuilder);

    String[] policies = new String[]{APIConstants.DEFAULT_SUB_POLICY_GOLD, APIConstants.DEFAULT_SUB_POLICY_SILVER,
            APIConstants.DEFAULT_SUB_POLICY_BRONZE, APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED,
            APIConstants.DEFAULT_SUB_POLICY_UNLIMITED};

    for (String policy : policies) {
        Mockito.when(
                apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(tenantId),
                        eq(policy))).thenReturn(true);
        Mockito.when(
                apiMgtDAO.isPolicyDeployed(eq(PolicyConstants.POLICY_LEVEL_SUB), eq(tenantId),
                        eq(policy))).thenReturn(true);
    }

    APIUtil.addDefaultTenantAdvancedThrottlePolicies(tenantDomain, tenantId);
    Mockito.verify(apiMgtDAO, Mockito.never()).
            addSubscriptionPolicy(Mockito.any(SubscriptionPolicy.class));
    Mockito.verify(apiMgtDAO, Mockito.never()).
            setPolicyDeploymentStatus(eq(PolicyConstants.POLICY_LEVEL_SUB), Mockito.anyString(), eq(tenantId), eq(true));
}