Search in sources :

Example 46 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class KeyManagerDataServiceImpl method addScope.

@Override
public void addScope(ScopeEvent event) {
    Scope scope = new Scope();
    scope.setName(event.getName());
    scope.setRoles(event.getRoles());
    scope.setDisplayName(event.getDisplayName());
    scope.setDescription(event.getDescription());
    scope.setTimeStamp(event.getTimeStamp());
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the event as the tenant " + event.getTenantDomain() + " is not loaded");
        }
        return;
    }
    store.addOrUpdateScope(scope);
}
Also used : Scope(org.wso2.carbon.apimgt.keymgt.model.entity.Scope) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 47 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class GatewayUtilsTestCase method testGetAPI.

@Test
public void testGetAPI() {
    API api = new API();
    api.setApiName("api1");
    api.setApiVersion("1.0.0");
    api.setApiProvider("admin");
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
    Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
    SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
    Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
    Mockito.when(subscriptionDataStore.getApiByContextAndVersion("/abc", "1.0.0")).thenReturn(api);
    Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
    Assert.assertEquals(GatewayUtils.getAPI(messageContext), api);
    Assert.assertEquals(GatewayUtils.getAPINameFromContextAndVersion(messageContext), "api1");
    Assert.assertEquals(GatewayUtils.getApiProviderFromContextAndVersion(messageContext), "admin");
    Mockito.verify(messageContext, Mockito.times(6)).getProperty(APIMgtGatewayConstants.API_OBJECT);
    Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.REST_API_CONTEXT);
    Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
    Mockito.verify(subscriptionDataStore, Mockito.times(3)).getApiByContextAndVersion("/abc", "1.0.0");
}
Also used : API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) SubscriptionDataHolder(org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class GatewayUtilsTestCase method testGetAPIasNullWhenTenantSubscriptionStoreNull.

@Test
public void testGetAPIasNullWhenTenantSubscriptionStoreNull() {
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
    Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
    SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
    Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(null);
    Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc1");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
    Assert.assertNull(GatewayUtils.getAPI(messageContext));
    Assert.assertNull(GatewayUtils.getStatus(messageContext));
    Mockito.verify(messageContext, Mockito.times(0)).setProperty(Mockito.anyString(), Mockito.any());
    Mockito.verify(messageContext, Mockito.times(4)).getProperty(APIMgtGatewayConstants.API_OBJECT);
    Mockito.verify(messageContext, Mockito.times(2)).getProperty(RESTConstants.REST_API_CONTEXT);
    Mockito.verify(messageContext, Mockito.times(2)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
    Mockito.verify(subscriptionDataStore, Mockito.times(0)).getApiByContextAndVersion("/abc1", "1.0.0");
}
Also used : MessageContext(org.apache.synapse.MessageContext) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) SubscriptionDataHolder(org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class GatewayUtilsTestCase method testGetAPIFromProperty.

@Test
public void testGetAPIFromProperty() {
    API api = Mockito.mock(API.class);
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
    Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
    SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
    Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
    Mockito.when(subscriptionDataStore.getApiByContextAndVersion("/abc", "1.0.0")).thenReturn(api);
    Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
    Assert.assertEquals(GatewayUtils.getAPI(messageContext), api);
    Mockito.verify(messageContext, Mockito.times(1)).getProperty(APIMgtGatewayConstants.API_OBJECT);
    Mockito.verify(messageContext, Mockito.times(0)).getProperty(RESTConstants.REST_API_CONTEXT);
    Mockito.verify(messageContext, Mockito.times(0)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
    Mockito.verify(subscriptionDataStore, Mockito.times(0)).getApiByContextAndVersion("/abc", "1.0.0");
}
Also used : API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) SubscriptionDataHolder(org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)43 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)14 SubscriptionDataHolder (org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ArrayList (java.util.ArrayList)7 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)6 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)5 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)5 MessageContext (org.apache.synapse.MessageContext)4 DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO)4 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 URLMapping (org.wso2.carbon.apimgt.api.model.subscription.URLMapping)2 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)2 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)2 Scope (org.wso2.carbon.apimgt.keymgt.model.entity.Scope)2 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)2