Java Code Examples for org.wso2.carbon.apimgt.api.model.APIIdentifier#setTier()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.APIIdentifier#setTier() .
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: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testAddSubscription() throws Exception { APIIdentifier apiIdentifier = new APIIdentifier("SUMEDHA", "API1", "V1.0.0"); apiIdentifier.setApplicationId("APPLICATION99"); apiIdentifier.setTier("T1"); API api = new API(apiIdentifier); ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api); apiMgtDAO.addSubscription(apiTypeWrapper, 100, "UNBLOCKED", "admin"); }
Example 2
Source File: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testValidateSubscriptionDetails() throws APIManagementException { Subscriber subscriber = new Subscriber("sub_user1"); subscriber.setEmail("[email protected]"); subscriber.setSubscribedDate(new Date()); subscriber.setTenantId(MultitenantConstants.SUPER_TENANT_ID); apiMgtDAO.addSubscriber(subscriber, null); Application application = new Application("APP-10", subscriber); int applicationId = apiMgtDAO.addApplication(application, subscriber.getName()); APIIdentifier apiId = new APIIdentifier("provider1", "WSO2-Utils", "V1.0.0"); apiId.setTier("T10"); API api = new API(apiId); api.setContext("/wso2utils"); api.setContextTemplate("/wso2utils/{version}"); apiMgtDAO.addAPI(api, MultitenantConstants.SUPER_TENANT_ID); ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api); int subsId = apiMgtDAO.addSubscription(apiTypeWrapper, applicationId, "UNBLOCKED", "sub_user1"); String[] apiDetail = apiMgtDAO.getAPIDetailsByContext("/wso2utils"); assertTrue(apiDetail.length == 2); assertEquals(apiDetail[0], "WSO2-Utils"); assertEquals(apiDetail[1], "provider1"); String policyName = "T10"; SubscriptionPolicy policy = (SubscriptionPolicy) getSubscriptionPolicy(policyName); policy.setRateLimitCount(20); policy.setTenantId(MultitenantConstants.SUPER_TENANT_ID); policy.setMonetizationPlan(APIConstants.Monetization.FIXED_RATE); apiMgtDAO.addSubscriptionPolicy(policy); APIKeyValidationInfoDTO infoDTO = new APIKeyValidationInfoDTO(); apiMgtDAO.createApplicationKeyTypeMappingForManualClients(APIConstants.API_KEY_TYPE_PRODUCTION, "APP-10", "sub_user1", "clientId1","Default"); Map<String, String> consumerkeyByApplicationIdAndKeyType = apiMgtDAO.getConsumerkeyByApplicationIdAndKeyType(applicationId, APIConstants.API_KEY_TYPE_PRODUCTION); assertEquals(consumerkeyByApplicationIdAndKeyType.get("Default"), "clientId1"); assertTrue(apiMgtDAO.isMappingExistsforConsumerKey("Default","clientId1")); boolean validation = apiMgtDAO.validateSubscriptionDetails("/wso2utils", "V1.0.0", "clientId1","Default", infoDTO); APIKeyValidationInfoDTO infoDTO1 = new APIKeyValidationInfoDTO(); apiMgtDAO.validateSubscriptionDetails(infoDTO1, "/wso2utils", "V1.0.0", "clientId1", "Default", false); if (validation) { assertEquals(20, infoDTO.getSpikeArrestLimit()); } else { assertTrue("Expected validation for subscription details - true, but found - " + validation, validation); } if (infoDTO1.isAuthorized()) { assertEquals(20, infoDTO1.getSpikeArrestLimit()); } else { assertTrue("Expected validation for subscription details - true, but found - " + infoDTO1.isAuthorized(), infoDTO1.isAuthorized()); } apiMgtDAO.updateSubscriptionStatus(subsId, APIConstants.SubscriptionStatus.BLOCKED); APIKeyValidationInfoDTO infoDtoForBlocked = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails("/wso2utils", "V1.0.0", "clientId1", "Default", infoDtoForBlocked)); assertEquals(infoDtoForBlocked.getValidationStatus(), APIConstants.KeyValidationStatus.API_BLOCKED); APIKeyValidationInfoDTO infoDtoForBlocked1 = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails(infoDtoForBlocked1, "/wso2utils", "V1.0.0", "clientId1" ,"Default",false).isAuthorized()); assertEquals(infoDtoForBlocked1.getValidationStatus(), APIConstants.KeyValidationStatus.API_BLOCKED); APIKeyValidationInfoDTO infoDtoForOnHold = new APIKeyValidationInfoDTO(); apiMgtDAO.updateSubscriptionStatus(subsId, APIConstants.SubscriptionStatus.ON_HOLD); assertFalse(apiMgtDAO.validateSubscriptionDetails("/wso2utils", "V1.0.0", "clientId1", "Default", infoDtoForOnHold)); assertEquals(infoDtoForOnHold.getValidationStatus(), APIConstants.KeyValidationStatus.SUBSCRIPTION_INACTIVE); APIKeyValidationInfoDTO infoDtoForOnHold1 = new APIKeyValidationInfoDTO(); apiMgtDAO.updateSubscriptionStatus(subsId, APIConstants.SubscriptionStatus.ON_HOLD); assertFalse(apiMgtDAO.validateSubscriptionDetails(infoDtoForOnHold1, "/wso2utils", "V1.0.0", "clientId1", "Default",false).isAuthorized()); assertEquals(infoDtoForOnHold1.getValidationStatus(), APIConstants.KeyValidationStatus.SUBSCRIPTION_INACTIVE); apiMgtDAO.updateSubscriptionStatus(subsId, APIConstants.SubscriptionStatus.REJECTED); APIKeyValidationInfoDTO infoDotForRejected = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails("/wso2utils", "V1.0.0", "clientId1","Default", infoDotForRejected)); assertEquals(infoDotForRejected.getValidationStatus(), APIConstants.KeyValidationStatus.SUBSCRIPTION_INACTIVE); APIKeyValidationInfoDTO infoDotForRejected1 = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails(infoDotForRejected1, "/wso2utils", "V1.0.0", "clientId1", "Default",false).isAuthorized()); assertEquals(infoDotForRejected1.getValidationStatus(), APIConstants.KeyValidationStatus.SUBSCRIPTION_INACTIVE); apiMgtDAO.updateSubscriptionStatus(subsId, APIConstants.SubscriptionStatus.PROD_ONLY_BLOCKED); APIKeyValidationInfoDTO infoDotForProdOnlyBlocked = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails("/wso2utils", "V1.0.0", "clientId1","Default", infoDotForProdOnlyBlocked)); assertEquals(infoDotForProdOnlyBlocked.getValidationStatus(), APIConstants.KeyValidationStatus.API_BLOCKED); APIKeyValidationInfoDTO infoDotForProdOnlyBlocked1 = new APIKeyValidationInfoDTO(); assertFalse(apiMgtDAO.validateSubscriptionDetails(infoDotForProdOnlyBlocked1, "/wso2utils", "V1.0.0", "clientId1", "Default",false).isAuthorized()); assertEquals(infoDotForProdOnlyBlocked1.getValidationStatus(), APIConstants.KeyValidationStatus.API_BLOCKED); }