Search in sources :

Example 76 with ScopesDAO

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

the class APIProviderImplTest method testGetAPIUsageByAPIId.

@Test
public void testGetAPIUsageByAPIId() throws APIManagementException, RegistryException, UserStoreException {
    String uuid = UUID.randomUUID().toString();
    SubscribedAPI subscribedAPI1 = new SubscribedAPI(new Subscriber("user1"), new APIIdentifier("admin", "API1", "1.0.0"));
    SubscribedAPI subscribedAPI2 = new SubscribedAPI(new Subscriber("user1"), new APIIdentifier("admin", "API2", "1.0.0"));
    UserApplicationAPIUsage apiResult1 = new UserApplicationAPIUsage();
    apiResult1.addApiSubscriptions(subscribedAPI1);
    apiResult1.addApiSubscriptions(subscribedAPI2);
    SubscribedAPI subscribedAPI3 = new SubscribedAPI(new Subscriber("user2"), new APIIdentifier("admin", "API1", "1.0.0"));
    SubscribedAPI subscribedAPI4 = new SubscribedAPI(new Subscriber("user2"), new APIIdentifier("admin", "API2", "1.0.0"));
    UserApplicationAPIUsage apiResult2 = new UserApplicationAPIUsage();
    apiResult2.addApiSubscriptions(subscribedAPI3);
    apiResult2.addApiSubscriptions(subscribedAPI4);
    UserApplicationAPIUsage[] apiResults = { apiResult1, apiResult2 };
    Mockito.when(apimgtDAO.getAllAPIUsageByProviderAndApiId(uuid, "org1")).thenReturn(apiResults);
    Mockito.when(apimgtDAO.getAPIIdentifierFromUUID(uuid)).thenReturn(new APIIdentifier("admin", "API1", "1.0.0"));
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    List<SubscribedAPI> subscribedAPIs = apiProvider.getAPIUsageByAPIId(uuid, "org1");
    Assert.assertEquals(2, subscribedAPIs.size());
    Assert.assertEquals("user1", subscribedAPIs.get(0).getSubscriber().getName());
    Assert.assertEquals("user2", subscribedAPIs.get(1).getSubscriber().getName());
}
Also used : UserApplicationAPIUsage(org.wso2.carbon.apimgt.api.dto.UserApplicationAPIUsage) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 77 with ScopesDAO

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

the class APIProviderImplTest method testAddBlockCondition.

@Test
public void testAddBlockCondition() throws APIManagementException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
    blockConditionsDTO.setUUID("12345");
    Mockito.when(apimgtDAO.addBlockConditions(Mockito.any(BlockConditionsDTO.class))).thenReturn(blockConditionsDTO);
    // condition type IP
    assertEquals("12345", apiProvider.addBlockCondition("IP", "testValue"));
    // condition type User
    assertEquals("12345", apiProvider.addBlockCondition("USER", "testValue"));
}
Also used : BlockConditionsDTO(org.wso2.carbon.apimgt.api.model.BlockConditionsDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 78 with ScopesDAO

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

the class ScopesApiServiceImpl method scopesGet.

public Response scopesGet(String xWSO2Tenant, String scopeKey, MessageContext messageContext) throws APIManagementException {
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    ScopesDAO scopesDAO = ScopesDAO.getInstance();
    if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        int tenantId = APIUtil.getTenantIdFromTenantDomain(xWSO2Tenant);
        if (StringUtils.isNotEmpty(scopeKey)) {
            List<Scope> model = new ArrayList<>();
            Scope scope = scopesDAO.getScope(scopeKey, tenantId);
            if (scope != null) {
                model.add(scope);
            }
            return Response.ok().entity(SubscriptionValidationDataUtil.fromScopeListToScopeDtoList(model)).build();
        } else {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromScopeListToScopeDtoList(scopesDAO.getScopes(tenantId))).build();
        }
    } else {
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
    }
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)76 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)76 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)51 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)31 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)31 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)29 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)29 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)25 API (org.wso2.carbon.apimgt.api.model.API)24 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)24 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)24 Resource (org.wso2.carbon.registry.core.Resource)20 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)18 RealmService (org.wso2.carbon.user.core.service.RealmService)17 QName (javax.xml.namespace.QName)16 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)15 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)15 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 OMException (org.apache.axiom.om.OMException)12