Search in sources :

Example 36 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO in project carbon-apimgt by wso2.

the class APIProviderImplTest method testGetSubscriberClaims.

@Test
public void testGetSubscriberClaims() throws APIManagementException, UserStoreException, XMLStreamException {
    String configuredClaims = "http://wso2.org/claim1,http://wso2.org/claim2";
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    // Mock retrieving the tenant domain
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.mockStatic(APIUtil.class);
    Mockito.when(MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    RealmService realmService = Mockito.mock(RealmService.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    PowerMockito.when(tenantManager.getTenantId(Matchers.anyString())).thenReturn(-1234);
    UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    PowerMockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    PowerMockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    PowerMockito.when(userStoreManager.isExistingUser("admin")).thenReturn(true);
    SortedMap<String, String> claimValues = new TreeMap<String, String>();
    claimValues.put("claim1", "http://wso2.org/claim1");
    claimValues.put("claim2", "http://wso2.org/claim2");
    claimValues.put("claim3", "http://wso2.org/claim3");
    PowerMockito.when(APIUtil.getClaims("admin", -1234, DEFAULT_DIALECT_URI)).thenReturn(claimValues);
    APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService configurationService = Mockito.mock(APIManagerConfigurationService.class);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(configurationService);
    PowerMockito.when(configurationService.getAPIManagerConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.getFirstProperty(APIConstants.API_PUBLISHER_SUBSCRIBER_CLAIMS)).thenReturn(configuredClaims);
    Map subscriberClaims = apiProvider.getSubscriberClaims("admin");
    assertNotNull(subscriberClaims);
    assertEquals(configuredClaims.split(",").length, subscriberClaims.size());
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) UserRealm(org.wso2.carbon.user.api.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) TreeMap(java.util.TreeMap) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO in project carbon-apimgt by wso2.

the class APIProviderImplTest method testUpdateAPIProductForStateChange.

@Test
public void testUpdateAPIProductForStateChange() throws Exception {
    String provider = "admin";
    PowerMockito.mockStatic(MultitenantUtils.class);
    Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(APIConstants.SUPER_TENANT_DOMAIN);
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
    APIProduct apiProduct = createMockAPIProduct(provider);
    prepareForLCStateChangeOfAPIProduct(apiProvider, apiProduct);
    PublisherAPIProduct publisherAPIProduct = APIProductMapper.INSTANCE.toPublisherApiProduct(apiProduct);
    Organization organization = new Organization(APIConstants.SUPER_TENANT_DOMAIN);
    Mockito.when(apiPersistenceInstance.updateAPIProduct(organization, publisherAPIProduct)).thenReturn(publisherAPIProduct);
    apiProvider.updateAPIProductForStateChange(apiProduct, APIConstants.CREATED, APIConstants.PUBLISHED);
}
Also used : PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO in project carbon-apimgt by wso2.

the class APIAdminImplTest method setup.

@Before
public void setup() {
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    apimConfigService = Mockito.mock(APIMConfigService.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIMConfigService(org.wso2.carbon.apimgt.impl.config.APIMConfigService) Before(org.junit.Before)

Example 39 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO in project carbon-apimgt by wso2.

the class APIProviderImplTest method testDeleteWorkflowTask.

@Test
public void testDeleteWorkflowTask() throws APIManagementException, WorkflowException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
    WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
    Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
    WorkflowExecutor apiStateChangeWFExecutor = Mockito.mock(WorkflowExecutor.class);
    Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(apiStateChangeWFExecutor);
    WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(workflowDTO);
    APIIdentifier identifier = new APIIdentifier("admin", "API1", "1.0.0", apiUUID);
    apiProvider.deleteWorkflowTask(identifier);
    Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO in project carbon-apimgt by wso2.

the class APIProviderImplTest method testGetAPIRevisions.

/**
 * This method tests adding a new API Revision and then retrieving API Revisions by API UUID
 *
 * @throws APIManagementException
 */
@Test
public void testGetAPIRevisions() throws APIManagementException, APIPersistenceException, ArtifactSynchronizerException {
    ImportExportAPI importExportAPI = Mockito.mock(ImportExportAPI.class);
    ArtifactSaver artifactSaver = Mockito.mock(ArtifactSaver.class);
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, importExportAPI, gatewayArtifactsMgtDAO, artifactSaver);
    APIIdentifier apiId = new APIIdentifier("admin", "PizzaShackAPI", "1.0.0", "63e1e37e-a5b8-4be6-86a5-d6ae0749f131");
    API api = new API(apiId);
    api.setContext("/test");
    api.setStatus(APIConstants.CREATED);
    String apiPath = "/apimgt/applicationdata/provider/admin/PizzaShackAPI/1.0.0/api";
    APIRevision apiRevision = new APIRevision();
    apiRevision.setApiUUID("63e1e37e-a5b8-4be6-86a5-d6ae0749f131");
    apiRevision.setDescription("test description revision 1");
    Mockito.when(apimgtDAO.getRevisionCountByAPI(Mockito.anyString())).thenReturn(0);
    Mockito.when(apimgtDAO.getMostRecentRevisionId(Mockito.anyString())).thenReturn(0);
    Mockito.when(APIUtil.getAPIIdentifierFromUUID(Mockito.anyString())).thenReturn(apiId);
    Mockito.when(APIUtil.getAPIPath(apiId)).thenReturn(apiPath);
    Mockito.when(APIUtil.getTenantConfig(Mockito.anyString())).thenReturn(new JSONObject());
    PowerMockito.when(apiPersistenceInstance.addAPIRevision(any(Organization.class), Mockito.anyString(), Mockito.anyInt())).thenReturn("b55e0fc3-9829-4432-b99e-02056dc91838");
    try {
        apiProvider.addAPIRevision(apiRevision, superTenantDomain);
        apiProvider.getAPIRevisions("63e1e37e-a5b8-4be6-86a5-d6ae0749f131");
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ArtifactSaver(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.ArtifactSaver) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) JSONObject(org.json.simple.JSONObject) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) XMLStreamException(javax.xml.stream.XMLStreamException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) BlockConditionNotFoundException(org.wso2.carbon.apimgt.api.BlockConditionNotFoundException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) DuplicateAPIException(org.wso2.carbon.apimgt.api.model.DuplicateAPIException) IOException(java.io.IOException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) OMException(org.apache.axiom.om.OMException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)197 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)197 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)106 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)82 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)80 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)53 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)52 API (org.wso2.carbon.apimgt.api.model.API)50 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)50 Application (org.wso2.carbon.apimgt.api.model.Application)39 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)37 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)36 Resource (org.wso2.carbon.registry.core.Resource)36 Matchers.anyString (org.mockito.Matchers.anyString)35 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)33 RealmService (org.wso2.carbon.user.core.service.RealmService)32 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)32 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)31 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)29 HashMap (java.util.HashMap)27