org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO Java Examples
The following examples show how to use
org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.
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: SubscriptionDeletionSimpleWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); SubscriptionWorkflowDTO subWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO; String errorMsg = null; try { APIIdentifier identifier = new APIIdentifier(subWorkflowDTO.getApiProvider(), subWorkflowDTO.getApiName(), subWorkflowDTO.getApiVersion()); apiMgtDAO.removeSubscription(identifier, ((SubscriptionWorkflowDTO) workflowDTO).getApplicationId()); } catch (APIManagementException e) { errorMsg = "Could not complete subscription deletion workflow for api: " + subWorkflowDTO.getApiName(); throw new WorkflowException(errorMsg, e); } return new GeneralWorkflowResponse(); }
Example #2
Source File: AbstractApplicationRegistrationWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public WorkflowResponse execute(WorkflowDTO workFlowDTO) throws WorkflowException { if (log.isDebugEnabled()) { log.debug("Executing AbstractApplicationRegistrationWorkflowExecutor..."); } ApiMgtDAO dao = ApiMgtDAO.getInstance(); try { //dao.createApplicationRegistrationEntry((ApplicationRegistrationWorkflowDTO) workFlowDTO, false); ApplicationRegistrationWorkflowDTO appRegDTO; if (workFlowDTO instanceof ApplicationRegistrationWorkflowDTO) { appRegDTO = (ApplicationRegistrationWorkflowDTO)workFlowDTO; }else{ String message = "Invalid workflow type found"; log.error(message); throw new WorkflowException(message); } dao.createApplicationRegistrationEntry(appRegDTO,false); // appRegDTO.getAppInfoDTO().saveDTO(); super.execute(workFlowDTO); } catch (APIManagementException e) { log.error("Error while creating Application Registration entry.", e); throw new WorkflowException("Error while creating Application Registration entry.", e); } return new GeneralWorkflowResponse(); }
Example #3
Source File: APIMOAuthEventInterceptor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
private void persistRevokedJWTSignature(String token, Long expiryTime) { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); try { String tokenSignature = APIUtil.getSignatureIfJWT(token); String tenantDomain = APIUtil.getTenantDomainIfJWT(token); int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain); apiMgtDAO.addRevokedJWTSignature(tokenSignature, APIConstants.DEFAULT, expiryTime, tenantId); // Cleanup expired revoked tokens from db. Runnable expiredJWTCleaner = new ExpiredJWTCleaner(); Thread cleanupThread = new Thread(expiredJWTCleaner); cleanupThread.start(); } catch (APIManagementException e) { log.error("Unable to add revoked JWT signature to the database"); } }
Example #4
Source File: SubscriptionCreationApprovalWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Handle cleanup task for subscription creation Approval workflow executor. * Use workflow external reference to delete the pending workflow request * * @param workflowExtRef Workflow external reference of pending workflow request */ @Override public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException { String errorMsg = null; super.cleanUpPendingTask(workflowExtRef); if (log.isDebugEnabled()) { log.debug("Starting cleanup task for SubscriptionCreationApprovalWorkflowExecutor for :" + workflowExtRef); } try { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); apiMgtDAO.deleteWorkflowRequest(workflowExtRef); } catch (APIManagementException axisFault) { errorMsg = "Error sending out cancel pending subscription approval process message. cause: " + axisFault .getMessage(); throw new WorkflowException(errorMsg, axisFault); } }
Example #5
Source File: ApplicationCreationApprovalWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Handle cleanup task for application creation Approval workflow executor. * Use workflow external reference to delete the pending workflow request * * @param workflowExtRef Workflow external reference of pending workflow request */ @Override public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException { String errorMsg; if (log.isDebugEnabled()) { log.debug("Starting cleanup task for ApplicationCreationApprovalWorkflowExecutor for :" + workflowExtRef); } super.cleanUpPendingTask(workflowExtRef); try { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); apiMgtDAO.deleteWorkflowRequest(workflowExtRef); } catch (APIManagementException axisFault) { errorMsg = "Error sending out cancel pending application approval process message. cause: " + axisFault .getMessage(); throw new WorkflowException(errorMsg, axisFault); } }
Example #6
Source File: AMDefaultKeyManagerImpl.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public Map<String, Set<Scope>> getScopesForAPIS(String apiIdsString) throws APIManagementException { Map<String, Set<Scope>> apiToScopeMapping = new HashMap<>(); ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); Map<String, Set<String>> apiToScopeKeyMapping = apiMgtDAO.getScopesForAPIS(apiIdsString); for (String apiId : apiToScopeKeyMapping.keySet()) { Set<Scope> apiScopes = new LinkedHashSet<>(); Set<String> scopeKeys = apiToScopeKeyMapping.get(apiId); for (String scopeKey : scopeKeys) { Scope scope = getScopeByName(scopeKey); apiScopes.add(scope); } apiToScopeMapping.put(apiId, apiScopes); } return apiToScopeMapping; }
Example #7
Source File: ApplicationDeletionSimpleWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); ApplicationWorkflowDTO applicationWorkflowDTO = (ApplicationWorkflowDTO) workflowDTO; Application application = applicationWorkflowDTO.getApplication(); String errorMsg = null; try { apiMgtDAO.deleteApplication(application); } catch (APIManagementException e) { if (e.getMessage() == null) { errorMsg = "Couldn't complete simple application deletion workflow for application: " + application .getName(); } else { errorMsg = e.getMessage(); } throw new WorkflowException(errorMsg, e); } return new GeneralWorkflowResponse(); }
Example #8
Source File: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath"); APIManagerConfiguration config = new APIManagerConfiguration(); initializeDatabase(dbConfigPath); config.load(dbConfigPath); ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl (config)); List<Notifier> notifierList = new ArrayList<>(); SubscriptionsNotifier subscriptionsNotifier = new SubscriptionsNotifier(); notifierList.add(subscriptionsNotifier); ServiceReferenceHolder.getInstance().getNotifiersMap().put(subscriptionsNotifier.getType(), notifierList); PowerMockito.mockStatic(KeyManagerHolder.class); keyManager = Mockito.mock(KeyManager.class); APIMgtDBUtil.initialize(); apiMgtDAO = ApiMgtDAO.getInstance(); IdentityTenantUtil.setRealmService(new TestRealmService()); String identityConfigPath = System.getProperty("IdentityConfigurationPath"); IdentityConfigParser.getInstance(identityConfigPath); OAuthServerConfiguration oAuthServerConfiguration = OAuthServerConfiguration.getInstance(); ServiceReferenceHolder.getInstance().setOauthServerConfiguration(oAuthServerConfiguration); }
Example #9
Source File: LabelApiServiceImplTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * This method tests the functionality of labelsPost, for a successful add label * * @throws APIManagementException APIManagementException. */ @Test public void testLabelsPost() throws APIManagementException { LabelDTO labelDTO = Mockito.mock(LabelDTO.class); List<String> urls = new ArrayList<>(); urls.add("url1"); urls.add("url2"); Label label1 = new Label(); label1.setLabelId("1111"); label1.setName("TestLabel"); label1.setAccessUrls(urls); PowerMockito.when(LabelMappingUtil.labelDTOToLabel(labelDTO)).thenReturn(label1); PowerMockito.mockStatic(ApiMgtDAO.class); apiMgtDAO = PowerMockito.mock(ApiMgtDAO.class); PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.addLabel(TENANT_DOMAIN, label1)).thenReturn(label1); PowerMockito.when(LabelMappingUtil.fromLabelToLabelDTO(label1)).thenReturn(labelDTO); Response response = labelsApiService.labelsPost(labelDTO); Assert.assertEquals(response.getStatus(), 201); }
Example #10
Source File: ApplicationCreationSimpleWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Complete the external process status * Based on the workflow status we will update the status column of the * Application table * * @param workFlowDTO - WorkflowDTO */ public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException { if (log.isDebugEnabled()) { log.info("Complete Application creation Workflow.."); } String status = null; if ("CREATED".equals(workFlowDTO.getStatus().toString())) { status = APIConstants.ApplicationStatus.APPLICATION_CREATED; } else if ("REJECTED".equals(workFlowDTO.getStatus().toString())) { status = APIConstants.ApplicationStatus.APPLICATION_REJECTED; } else if ("APPROVED".equals(workFlowDTO.getStatus().toString())) { status = APIConstants.ApplicationStatus.APPLICATION_APPROVED; } ApiMgtDAO dao = ApiMgtDAO.getInstance(); try { dao.updateApplicationStatus(Integer.parseInt(workFlowDTO.getWorkflowReference()),status); } catch (APIManagementException e) { String msg = "Error occured when updating the status of the Application creation process"; log.error(msg, e); throw new WorkflowException(msg, e); } return new GeneralWorkflowResponse(); }
Example #11
Source File: AlertTypesPublisherTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test(expected = APIManagementException.class) public void saveAlertWhileDatabaseConnectionFailed() throws Exception { String checkedAlertList = "health-availability"; String emailList = "[email protected]"; String userName = "[email protected]"; String agent = "publisher"; String checkedAlertListValues = "true"; ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Mockito.doThrow(APIManagementException.class).when(apiMgtDAO).addAlertTypesConfigInfo(userName, emailList, checkedAlertList, agent); APIMgtUsageDataPublisher apiMgtUsageDataPublisher = Mockito.mock(APIMgtUsageDataPublisher.class); AlertTypesPublisher alertTypesPublisher = new AlertTypePublisherWrapper(apiMgtDAO, apiMgtUsageDataPublisher); alertTypesPublisher.enabled = true; alertTypesPublisher.skipEventReceiverConnection = false; alertTypesPublisher.saveAndPublishAlertTypesEvent(checkedAlertList, emailList, userName, agent, checkedAlertListValues); }
Example #12
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testAddDefaultSuperTenantAdvancedThrottlePoliciesAppLevel() throws Exception { ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); String[] appPolicies = new String[]{APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_UNLIMITED}; for (String policy : appPolicies) { Mockito.when( apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_APP), eq(MultitenantConstants.SUPER_TENANT_ID), eq(policy))).thenReturn(false); } try { APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies(); Mockito.verify(apiMgtDAO, Mockito.times(appPolicies.length)).addApplicationPolicy(Mockito.any(ApplicationPolicy.class)); } catch (APIManagementException e) { Assert.assertTrue("Exception thrown", false); } }
Example #13
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@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 #14
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testAddDefaultSuperTenantAdvancedThrottlePoliciesAppLevelAlreadyAdded() throws Exception { ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); String[] appPolicies = new String[]{APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_UNLIMITED}; // If policy added already for (String policy : appPolicies) { Mockito.when( apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_APP), eq(MultitenantConstants.SUPER_TENANT_ID), eq(policy))).thenReturn(true); } try { APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies(); Mockito.verify(apiMgtDAO, Mockito.never()).addApplicationPolicy(Mockito.any(ApplicationPolicy.class)); } catch (APIManagementException e) { Assert.assertTrue("Exception thrown", false); } }
Example #15
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@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 #16
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testAddDefaultSuperTenantAdvancedThrottlePoliciesApiLevel() throws Exception { ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); String[] apiPolicies = new String[]{APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_UNLIMITED}; for (String policy : apiPolicies) { Mockito.when( apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_API), eq(MultitenantConstants.SUPER_TENANT_ID), eq(policy))).thenReturn(false); } try { APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies(); Mockito.verify(apiMgtDAO, Mockito.times(apiPolicies.length)).addAPIPolicy(Mockito.any(APIPolicy.class)); } catch (APIManagementException e) { Assert.assertTrue("Exception thrown", false); } }
Example #17
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testAddDefaultSuperTenantAdvancedThrottlePoliciesApiLevelAlreadyAdded() throws Exception { ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); String[] apiPolicies = new String[]{APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN, APIConstants.DEFAULT_API_POLICY_UNLIMITED}; for (String policy : apiPolicies) { Mockito.when( apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_API), eq(MultitenantConstants.SUPER_TENANT_ID), eq(policy))).thenReturn(true); } try { APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies(); Mockito.verify(apiMgtDAO, Mockito.never()).addAPIPolicy(Mockito.any(APIPolicy.class)); } catch (APIManagementException e) { Assert.assertTrue("Exception thrown", false); } }
Example #18
Source File: ApplicationRegistrationSimpleWorkflowExecutorTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() throws APIManagementException { PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(KeyManagerHolder.class); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); keyManager = Mockito.mock(KeyManager.class); application = new Application("test", new Subscriber("testUser")); oAuthAppRequest = new OAuthAppRequest(); oAuthApplicationInfo = new OAuthApplicationInfo(); oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo); workflowDTO = new ApplicationRegistrationWorkflowDTO(); workflowDTO.setWorkflowReference("1"); workflowDTO.setApplication(application); workflowDTO.setAppInfoDTO(oAuthAppRequest); workflowDTO.setKeyManager("default"); PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager); KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration(); Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration); applicationRegistrationSimpleWorkflowExecutor = new ApplicationRegistrationSimpleWorkflowExecutor(); }
Example #19
Source File: APIStateChangeApprovalWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Handle cleanup task for api state change workflow Approval executor. * Use workflow external reference to delete the pending workflow request * * @param workflowExtRef External Workflow Reference of pending workflow process */ @Override public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException { if (log.isDebugEnabled()) { log.debug("Starting cleanup task for APIStateChangeWSWorkflowExecutor for :" + workflowExtRef); } String errorMsg; super.cleanUpPendingTask(workflowExtRef); try { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); apiMgtDAO.deleteWorkflowRequest(workflowExtRef); } catch (APIManagementException axisFault) { errorMsg = "Error sending out cancel pending application approval process message. cause: " + axisFault .getMessage(); throw new WorkflowException(errorMsg, axisFault); } }
Example #20
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetTiersFromAppPolicies() throws Exception { String policyLevel = PolicyConstants.POLICY_LEVEL_APP; int tenantId = 1; ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); ServiceReferenceHolderMockCreator serviceReferenceHolderMockCreator = daoMockHolder.getServiceReferenceHolderMockCreator(); serviceReferenceHolderMockCreator.initRegistryServiceMockCreator(true, tenantConf); ApplicationPolicy[] policies = generateAppPolicies(tiersReturned); Mockito.when(apiMgtDAO.getApplicationPolicies(tenantId)).thenReturn(policies); Map<String, Tier> tiersFromPolicies = APIUtil.getTiersFromPolicies(policyLevel, tenantId); Mockito.verify(apiMgtDAO, Mockito.only()).getApplicationPolicies(tenantId); for (ApplicationPolicy policy : policies) { Tier tier = tiersFromPolicies.get(policy.getPolicyName()); Assert.assertNotNull(tier); Assert.assertEquals(policy.getPolicyName(), tier.getName()); Assert.assertEquals(policy.getDescription(), tier.getDescription()); } }
Example #21
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@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 #22
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testAddDefaultTenantAdvancedThrottlePoliciesAppLevel() 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[] appPolicies = new String[]{APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_UNLIMITED}; for (String policy : appPolicies) { Mockito.when( apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_APP), eq(tenantId), eq(policy))).thenReturn(false); Mockito.when( apiMgtDAO.isPolicyDeployed(eq(PolicyConstants.POLICY_LEVEL_APP), eq(tenantId), eq(policy))).thenReturn(false); } APIUtil.addDefaultTenantAdvancedThrottlePolicies(tenantDomain, tenantId); Mockito.verify(apiMgtDAO, Mockito.times(appPolicies.length)). addApplicationPolicy(Mockito.any(ApplicationPolicy.class)); Mockito.verify(apiMgtDAO, Mockito.times(appPolicies.length)). setPolicyDeploymentStatus(eq(PolicyConstants.POLICY_LEVEL_APP), Mockito.anyString(), eq(tenantId), eq(true)); }
Example #23
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetTiersFromApiPoliciesBandwidth() throws Exception { String policyLevel = PolicyConstants.POLICY_LEVEL_API; int tenantId = 1; ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId); ApiMgtDAO apiMgtDAO = daoMockHolder.getMock(); ServiceReferenceHolderMockCreator serviceReferenceHolderMockCreator = daoMockHolder.getServiceReferenceHolderMockCreator(); serviceReferenceHolderMockCreator.initRegistryServiceMockCreator(true, tenantConf); APIPolicy[] policies = generateApiPoliciesBandwidth(tiersReturned); Mockito.when(apiMgtDAO.getAPIPolicies(tenantId)).thenReturn(policies); Map<String, Tier> tiersFromPolicies = APIUtil.getTiersFromPolicies(policyLevel, tenantId); Mockito.verify(apiMgtDAO, Mockito.only()).getAPIPolicies(tenantId); for (APIPolicy policy : policies) { Tier tier = tiersFromPolicies.get(policy.getPolicyName()); Assert.assertNotNull(tier); Assert.assertEquals(policy.getPolicyName(), tier.getName()); Assert.assertEquals(policy.getDescription(), tier.getDescription()); } }
Example #24
Source File: APIUtilTierTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@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)); }
Example #25
Source File: APIProviderImplWrapper.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public APIProviderImplWrapper(ApiMgtDAO apiMgtDAO, List<Documentation> documentationList, Map<String, Map<String,String>> failedGateways) throws APIManagementException { super(null); this.apiMgtDAO = apiMgtDAO; if (documentationList != null) { this.documentationList = documentationList; } this.failedGateways = failedGateways; }
Example #26
Source File: SubscriptionCreationSimpleWorkflowExecutorTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void init() { subscriptionCreationSimpleWorkflowExecutor = new SubscriptionCreationSimpleWorkflowExecutor(); PowerMockito.mockStatic(ApiMgtDAO.class); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); }
Example #27
Source File: WorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Implements the workflow execution logic. * * @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow. * @throws WorkflowException - Thrown when the workflow execution was not fully performed. */ public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); try { apiMgtDAO.addWorkflowEntry(workflowDTO); publishEvents(workflowDTO); } catch (APIManagementException e) { throw new WorkflowException("Error while persisting workflow", e); } return new GeneralWorkflowResponse(); }
Example #28
Source File: SubscriptionCreationWSWorkflowExecutorTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void init() { subscriptionCreationWSWorkflowExecutor = new SubscriptionCreationWSWorkflowExecutor(); subscriptionCreationWSWorkflowExecutor.setPassword("admin".toCharArray()); subscriptionCreationWSWorkflowExecutor.setUsername("admin"); subscriptionCreationWSWorkflowExecutor.setServiceEndpoint("http://localhost:9445/service"); subscriptionCreationWSWorkflowExecutor.setCallbackURL("http://localhost:8243/workflow-callback"); PowerMockito.mockStatic(ApiMgtDAO.class); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); serviceClient = Mockito.mock(ServiceClient.class); PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); }
Example #29
Source File: WorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Implements the workflow completion logic. * * @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow. * @throws WorkflowException - Thrown when the workflow completion was not fully performed. */ public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); try { apiMgtDAO.updateWorkflowStatus(workflowDTO); publishEvents(workflowDTO); } catch (APIManagementException e) { throw new WorkflowException("Error while updating workflow", e); } return new GeneralWorkflowResponse(); }
Example #30
Source File: WorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Method for persisting Workflow DTO * * @param workflowDTO * @throws WorkflowException */ public void persistWorkflow(WorkflowDTO workflowDTO) throws WorkflowException { ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); try { apiMgtDAO.addWorkflowEntry(workflowDTO); } catch (APIManagementException e) { throw new WorkflowException("Error while persisting workflow", e); } }