Search in sources :

Example 1 with APIMConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations in project carbon-apimgt by wso2.

the class NotificationExecutor method sendAsyncNotifications.

/**
 * Executes the notifer classes in separtate threads.
 *
 * @param notificationDTO
 * @throws org.wso2.carbon.apimgt.core.exception.NotificationException
 */
public void sendAsyncNotifications(NotificationDTO notificationDTO) throws NotificationException {
    List<NotifierConfigurations> notifierConfigurations = new APIMConfigurations().getNotificationConfigurations().getNewVersionNotifierConfiguration().getNotifierConfigurations();
    if (notificationDTO.getType().equalsIgnoreCase(NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION)) {
        for (NotifierConfigurations listItem : notifierConfigurations) {
            String executorClass = listItem.getExecutorClass();
            Map property = listItem.getPropertyList();
            Properties prop = notificationDTO.getProperties();
            prop.putAll(property);
            notificationDTO.setProperties(prop);
            // starting Notifier threads
            if (executorClass != null && !executorClass.isEmpty()) {
                Notifier notifier;
                try {
                    notifier = (Notifier) APIUtils.getClassForName(executorClass).newInstance();
                } catch (InstantiationException e) {
                    throw new NotificationException("Instantiation Error while Initializing the notifier class", e);
                } catch (IllegalAccessException e) {
                    throw new NotificationException("IllegalAccess Error while Initializing the notifier class", e);
                } catch (ClassNotFoundException e) {
                    throw new NotificationException("ClassNotFound Error while Initializing the notifier class", e);
                }
                notifier.setNotificationDTO(notificationDTO);
                executor.execute(notifier);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Class " + executorClass + " Empty Or Null");
                }
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Notification Type Does Not match with " + NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
        }
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }
}
Also used : APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) NotificationException(org.wso2.carbon.apimgt.core.exception.NotificationException) NotifierConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations) Properties(java.util.Properties) Map(java.util.Map) Notifier(org.wso2.carbon.apimgt.core.impl.Notifier)

Example 2 with APIMConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getAPIMConfiguration.

/**
 * Gives the APIMConfigurations explicitly set in the deployment yaml or the default configurations
 *
 * @return APIMConfigurations
 */
public APIMConfigurations getAPIMConfiguration() {
    try {
        if (configProvider != null) {
            apimConfigurations = configProvider.getConfigurationObject(APIMConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("error getting config : org.wso2.carbon.apimgt.core.internal.APIMConfiguration", e);
    }
    if (apimConfigurations == null) {
        apimConfigurations = new APIMConfigurations();
        log.info("APIMConfiguration: Setting default configurations...");
    }
    return apimConfigurations;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)

Example 3 with APIMConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations in project carbon-apimgt by wso2.

the class ScopeRegistrationServiceStubFactoryTest method testGetScopeRegistrationForWso2Is.

@Test
public void testGetScopeRegistrationForWso2Is() throws Exception {
    KeyMgtConfigurations keyManagerConfiguration = new KeyMgtConfigurations();
    keyManagerConfiguration.setKeyManagerImplClass(WSO2ISKeyManagerImpl.class.getCanonicalName());
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    APIMConfigurations apimConfigurations = new APIMConfigurations();
    apimConfigurations.setKeyManagerConfigs(keyManagerConfiguration);
    Mockito.when(configProvider.getConfigurationObject(APIMConfigurations.class)).thenReturn(apimConfigurations);
    ServiceReferenceHolder.getInstance().setConfigProvider(configProvider);
    ScopeRegistration scopeRegistration = ScopeRegistrationServiceStubFactory.getScopeRegistration();
    Assert.assertTrue(scopeRegistration instanceof WSO2ISScopeRegistrationImpl);
}
Also used : KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) WSO2ISKeyManagerImpl(org.wso2.carbon.apimgt.core.impl.WSO2ISKeyManagerImpl) Test(org.testng.annotations.Test)

Example 4 with APIMConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations in project carbon-apimgt by wso2.

the class NotificationTestCase method testNotificationExecutor.

@Test
public void testNotificationExecutor() throws Exception {
    Properties properties = Mockito.mock(Properties.class);
    NotificationDTO notificationDTO = Mockito.mock(NotificationDTO.class);
    Mockito.when(notificationDTO.getTitle()).thenReturn("Title");
    Mockito.when(notificationDTO.getType()).thenReturn("ApiNewVersion");
    Mockito.when(notificationDTO.getMessage()).thenReturn("Message");
    Mockito.when(notificationDTO.getProperties()).thenReturn(properties);
    APIMConfigurations apimConfigurations = Mockito.mock(APIMConfigurations.class);
    NotificationConfigurations notificationConfigurations = Mockito.mock(NotificationConfigurations.class);
    PowerMockito.mockStatic(APIMConfigurations.class);
    PowerMockito.when(apimConfigurations.getNotificationConfigurations()).thenReturn(notificationConfigurations);
    APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    Set subscriber = new HashSet();
    subscriber.add("User");
    Mockito.when((Set<String>) notificationDTO.getProperty(NotifierConstants.SUBSCRIBERS_PER_API)).thenReturn(subscriber);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
    PowerMockito.when(apiManagerFactory.getIdentityProvider()).thenReturn(identityProvider);
    PowerMockito.when(identityProvider.getIdOfUser("User")).thenReturn("1111");
    PowerMockito.when(identityProvider.getEmailOfUser("1111")).thenReturn("admin@gmail.com");
    new NotificationExecutor().sendAsyncNotifications(notificationDTO);
}
Also used : APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) NotificationDTO(org.wso2.carbon.apimgt.core.template.dto.NotificationDTO) Set(java.util.Set) HashSet(java.util.HashSet) NotificationConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotificationConfigurations) NotificationExecutor(org.wso2.carbon.apimgt.core.executors.NotificationExecutor) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) Properties(java.util.Properties) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with APIMConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations in project carbon-apimgt by wso2.

the class RestApiUtilTestCase method testGetContext.

@Test(description = "Test get Context")
public void testGetContext() throws Exception {
    APIMConfigurations apimConfigurations = new APIMConfigurations();
    String actualPubContext = RestApiUtil.getContext("publisher");
    String expectedPubContext = apimConfigurations.getPublisherContext();
    Assert.assertEquals(actualPubContext, expectedPubContext);
    String actualStoreContext = RestApiUtil.getContext("store");
    String expectedStoreStoreContext = apimConfigurations.getStoreContext();
    Assert.assertEquals(actualStoreContext, expectedStoreStoreContext);
    String actualAdminContext = RestApiUtil.getContext("admin");
    String expectedAdminContext = apimConfigurations.getAdminContext();
    Assert.assertEquals(actualAdminContext, expectedAdminContext);
    String actualContext = RestApiUtil.getContext("test");
    Assert.assertEquals(actualContext, null);
}
Also used : APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)5 Properties (java.util.Properties)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.junit.Test)1 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)1 KeyMgtConfigurations (org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations)1 NotificationConfigurations (org.wso2.carbon.apimgt.core.configuration.models.NotificationConfigurations)1 NotifierConfigurations (org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations)1 NotificationException (org.wso2.carbon.apimgt.core.exception.NotificationException)1 NotificationExecutor (org.wso2.carbon.apimgt.core.executors.NotificationExecutor)1 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)1 Notifier (org.wso2.carbon.apimgt.core.impl.Notifier)1 WSO2ISKeyManagerImpl (org.wso2.carbon.apimgt.core.impl.WSO2ISKeyManagerImpl)1 NotificationDTO (org.wso2.carbon.apimgt.core.template.dto.NotificationDTO)1 ConfigurationException (org.wso2.carbon.config.ConfigurationException)1 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)1