Search in sources :

Example 1 with NotificationExecutor

use of org.wso2.carbon.apimgt.core.executors.NotificationExecutor 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 2 with NotificationExecutor

use of org.wso2.carbon.apimgt.core.executors.NotificationExecutor in project carbon-apimgt by wso2.

the class APIPublisherImpl method sendNotification.

private void sendNotification(String apiId, String apiName, String newVersion) throws APIManagementException {
    Set<String> subscriberList;
    NotificationConfigurations notificationConfigurations = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getNotificationConfigurations();
    // check notification Enabled
    if (notificationConfigurations.getNotificationEnable()) {
        subscriberList = getSubscribersByAPIId(apiId);
        // Notifications are sent only if there are subscribers
        if (subscriberList.size() > 0) {
            try {
                Properties prop = new Properties();
                prop.put(NotifierConstants.NEW_API_VERSION, newVersion);
                prop.put(NotifierConstants.API_NAME, apiName);
                prop.put(NotifierConstants.SUBSCRIBERS_PER_API, subscriberList);
                NotificationDTO notificationDTO = new NotificationDTO(prop, NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
                new NotificationExecutor().sendAsyncNotifications(notificationDTO);
            } catch (NotificationException e) {
                String msg = "Error occurred while sending Async Notifications";
                log.error(msg, e);
            }
        }
    }
}
Also used : NotificationDTO(org.wso2.carbon.apimgt.core.template.dto.NotificationDTO) NotificationConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotificationConfigurations) NotificationExecutor(org.wso2.carbon.apimgt.core.executors.NotificationExecutor) NotificationException(org.wso2.carbon.apimgt.core.exception.NotificationException) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)2 NotificationConfigurations (org.wso2.carbon.apimgt.core.configuration.models.NotificationConfigurations)2 NotificationExecutor (org.wso2.carbon.apimgt.core.executors.NotificationExecutor)2 NotificationDTO (org.wso2.carbon.apimgt.core.template.dto.NotificationDTO)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)1 APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)1 NotificationException (org.wso2.carbon.apimgt.core.exception.NotificationException)1 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)1