Search in sources :

Example 1 with NotificationMgtConfigBuilder

use of org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder in project carbon-identity-framework by wso2.

the class NotificationManagementServiceComponent method activate.

@Activate
protected void activate(ComponentContext context) {
    // messages on a registered event
    try {
        // Pass the bundle context to read property file in a case it is not found in default location.
        try {
            configBuilder = new NotificationMgtConfigBuilder(context.getBundleContext());
        } catch (NotificationManagementException e) {
            log.error("Error while building Notification Mgt configuration", e);
        }
        // Read the thread pool size from configurations. If not present in configurations use default value.
        if (configBuilder != null && configBuilder.getThreadPoolSize() != null) {
            try {
                threadPoolSize = Integer.parseInt(configBuilder.getThreadPoolSize());
            } catch (NumberFormatException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Error while parsing thread pool size configuration, " + "setting default size :" + NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE);
                }
                threadPoolSize = NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE;
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("No configuration found for thread pool size, " + "setting default size :" + NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE);
            }
            threadPoolSize = NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE;
        }
        if (log.isDebugEnabled()) {
            log.debug("Notification mgt thread pool size " + threadPoolSize);
        }
        // Register Notification sender as the service class
        notificationSender = new NotificationSender(notificationSendingModules, threadPoolSize);
        context.getBundleContext().registerService(NotificationSender.class.getName(), notificationSender, null);
        if (log.isDebugEnabled()) {
            log.debug("Notification Management bundle is activated");
        }
    // Catch throwable since there may be run time exceptions.
    } catch (Throwable e) {
        log.error("Error while initiating Notification Management component", e);
    }
}
Also used : NotificationMgtConfigBuilder(org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder) NotificationSender(org.wso2.carbon.identity.notification.mgt.NotificationSender) NotificationManagementException(org.wso2.carbon.identity.notification.mgt.NotificationManagementException) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with NotificationMgtConfigBuilder

use of org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder in project carbon-identity-framework by wso2.

the class AbstractEventHandlerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    String home = IdentityEventConfigBuilder.class.getResource("/").getFile();
    String config = IdentityEventConfigBuilder.class.getResource("/").getFile();
    System.setProperty("carbon.home", home);
    System.setProperty("carbon.config.dir.path", config);
    subscriptionList = new ArrayList<>();
    moduleConfiguration = Mockito.mock(ModuleConfiguration.class);
    Mockito.doReturn(subscriptionList).when(moduleConfiguration).getSubscriptions();
    IdentityEventConfigBuilder identityEventConfigBuilder = Mockito.mock(IdentityEventConfigBuilder.class);
    Field field = IdentityEventConfigBuilder.class.getDeclaredField("notificationMgtConfigBuilder");
    field.setAccessible(true);
    field.set(null, identityEventConfigBuilder);
    Mockito.doReturn(moduleConfiguration).when(identityEventConfigBuilder).getModuleConfigurations(moduleName);
    moduleConfigurationMap = new HashMap<>();
    Mockito.doReturn(moduleConfigurationMap).when(identityEventConfigBuilder).getModuleConfiguration();
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return moduleConfigurationMap.get(invocationOnMock.getArguments()[0]);
        }
    }).when(identityEventConfigBuilder).getModuleConfigurations(Matchers.anyString());
    ModuleConfiguration moduleConfiguration2 = new ModuleConfiguration(new Properties(), subscriptionList);
    moduleConfigurationMap.put("TestEventHandler", moduleConfiguration2);
}
Also used : Field(java.lang.reflect.Field) Answer(org.mockito.stubbing.Answer) ModuleConfiguration(org.wso2.carbon.identity.event.bean.ModuleConfiguration) IdentityEventConfigBuilder(org.wso2.carbon.identity.event.IdentityEventConfigBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Properties(java.util.Properties) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Field (java.lang.reflect.Field)1 Properties (java.util.Properties)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 Activate (org.osgi.service.component.annotations.Activate)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 IdentityEventConfigBuilder (org.wso2.carbon.identity.event.IdentityEventConfigBuilder)1 ModuleConfiguration (org.wso2.carbon.identity.event.bean.ModuleConfiguration)1 NotificationManagementException (org.wso2.carbon.identity.notification.mgt.NotificationManagementException)1 NotificationMgtConfigBuilder (org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder)1 NotificationSender (org.wso2.carbon.identity.notification.mgt.NotificationSender)1