Search in sources :

Example 11 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.

the class ExternalGatewayNotifier method process.

/**
 * Process gateway notifier events related to External gateway deployments
 *
 * @param event related to deployments
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    DeployAPIInGatewayEvent deployAPIInGatewayEvent;
    deployAPIInGatewayEvent = (DeployAPIInGatewayEvent) event;
    if (isExternalGatewayAvailableToDeployment(deployAPIInGatewayEvent))
        if (APIConstants.EventType.DEPLOY_API_IN_GATEWAY.name().equals(event.getType())) {
            deployApi(deployAPIInGatewayEvent);
        } else if (APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name().equals(event.getType())) {
            unDeployApi(deployAPIInGatewayEvent);
        }
}
Also used : DeployAPIInGatewayEvent(org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)

Example 12 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.

the class NotificationExecutorTest method testShouldSendNotificationWhenConfigurationExists.

@Test
public void testShouldSendNotificationWhenConfigurationExists() throws Exception {
    NotificationDTO notificationDTO = new NotificationDTO(new Properties(), NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
    notificationDTO.setTenantDomain(TENANT_DOMAIN);
    notificationDTO.setTenantID(TENANT_ID);
    Notifier notifier = Mockito.mock(Notifier.class);
    Mockito.doNothing().when(notifier).run();
    PowerMockito.when(APIUtil.class, "getTenantConfig", TENANT_DOMAIN).thenReturn(new JSONParser().parse(validNotifierConf));
    PowerMockito.when(APIUtil.class, "getClassInstance", "org.wso2.carbon.apimgt.impl.notification" + ".NewAPIVersionEmailNotifier").thenReturn(notifier);
    try {
        notificationExecutor.sendAsyncNotifications(notificationDTO);
    } catch (NotificationException e) {
        Assert.fail("Should not throw an exception");
    }
}
Also used : NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) JSONParser(org.json.simple.parser.JSONParser) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.

the class NotificationExecutorTest method testShouldNotThrowExceptionWhenNotifierNotDefined.

@Test
public void testShouldNotThrowExceptionWhenNotifierNotDefined() throws Exception {
    NotificationDTO notificationDTO = new NotificationDTO(new Properties(), NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
    notificationDTO.setTenantDomain(TENANT_DOMAIN);
    notificationDTO.setTenantID(TENANT_ID);
    Notifier notifier = Mockito.mock(Notifier.class);
    Mockito.doNothing().when(notifier).run();
    PowerMockito.when(APIUtil.class, "getTenantConfig", TENANT_DOMAIN).thenReturn(new JSONParser().parse(invalidNotifierConf));
    try {
        notificationExecutor.sendAsyncNotifications(notificationDTO);
    } catch (NotificationException e) {
        Assert.fail("Should not throw an exception");
    }
}
Also used : NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) JSONParser(org.json.simple.parser.JSONParser) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.

the class SolaceApplicationNotifier method process.

/**
 * Process Application notifier event related to Solace applications
 *
 * @param event related to Application handling
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    ApplicationEvent applicationEvent;
    applicationEvent = (ApplicationEvent) event;
    if (APIConstants.EventType.APPLICATION_DELETE.name().equals(event.getType())) {
        removeSolaceApplication(applicationEvent);
    } else if (APIConstants.EventType.APPLICATION_UPDATE.name().equals(event.getType())) {
        renameSolaceApplication(applicationEvent);
    }
}
Also used : ApplicationEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationEvent)

Example 15 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.

the class SolaceSubscriptionsNotifier method process.

/**
 * Process gateway notifier events related to Solace API subscriptions
 *
 * @param event related to subscription handling
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    SubscriptionEvent subscriptionEvent;
    subscriptionEvent = (SubscriptionEvent) event;
    if (APIConstants.EventType.SUBSCRIPTIONS_CREATE.name().equals(event.getType())) {
        crateSubscription(subscriptionEvent);
    } else if (APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name().equals(event.getType())) {
        updateSubscription(subscriptionEvent);
    } else if (APIConstants.EventType.SUBSCRIPTIONS_DELETE.name().equals(event.getType())) {
        removeSubscription(subscriptionEvent);
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent)

Aggregations

Properties (java.util.Properties)6 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 NotificationException (org.wso2.carbon.apimgt.impl.notification.exception.NotificationException)4 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 Before (org.junit.Before)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)2 Notifier (org.wso2.carbon.apimgt.impl.notifier.Notifier)2 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1