use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.
the class NotificationExecutorTest method testShouldNotThrowExceptionWhenNotificationTypeNotRegistered.
@Test
public void testShouldNotThrowExceptionWhenNotificationTypeNotRegistered() throws Exception {
NotificationDTO notificationDTO = new NotificationDTO(new Properties(), "new_subscription");
notificationDTO.setTenantDomain(TENANT_DOMAIN);
notificationDTO.setTenantID(TENANT_ID);
Notifier notifier = Mockito.mock(Notifier.class);
Mockito.doNothing().when(notifier).run();
JSONObject jsonObject = new JSONObject();
jsonObject.put(NotifierConstants.Notifications_KEY, new JSONArray());
PowerMockito.when(APIUtil.class, "getTenantConfig", TENANT_DOMAIN).thenReturn(jsonObject);
try {
notificationExecutor.sendAsyncNotifications(notificationDTO);
} catch (NotificationException e) {
Assert.fail("Should not throw an exception");
}
}
use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.
the class NotificationExecutorTest method testShouldThrowExceptionsWhenRegistryErrorOccurs.
@Test(expected = NotificationException.class)
public void testShouldThrowExceptionsWhenRegistryErrorOccurs() 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).thenThrow(APIManagementException.class);
notificationExecutor.sendAsyncNotifications(notificationDTO);
Assert.fail("Should throw an exception");
}
use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.
the class NotificationExecutor method sendAsyncNotifications.
/**
* Executes the notifer classes in separtate threads.
* @param notificationDTO
* @throws NotificationException
*/
public void sendAsyncNotifications(NotificationDTO notificationDTO) throws NotificationException {
JSONObject notificationConfig;
String notificationType = notificationDTO.getType();
try {
notificationConfig = APIUtil.getTenantConfig(notificationDTO.getTenantDomain());
JSONArray notificationArray = (JSONArray) notificationConfig.get(NotifierConstants.Notifications_KEY);
for (Object notification : notificationArray) {
JSONObject notificationJson = (JSONObject) notification;
String notifierType = (String) notificationJson.get(NotifierConstants.TYPE_KEY);
if (notificationType.equals(notifierType)) {
JSONArray notifierArray = (JSONArray) notificationJson.get("Notifiers");
for (Object notifier : notifierArray) {
JSONObject jsonNotifier = (JSONObject) notifier;
String notifierClass = (String) jsonNotifier.get("Class");
Map map = (Map) jsonNotifier;
Properties prop = notificationDTO.getProperties();
prop.putAll(map);
notificationDTO.setProperties(prop);
// starting Notifier threads
if (notifierClass != null && !notifierClass.isEmpty()) {
Notifier notfier = (Notifier) APIUtil.getClassInstance(notifierClass);
notfier.setNotificationDTO(notificationDTO);
notfier.setTenantDomain(notificationDTO.getTenantDomain());
Thread notificationThread = new Thread(notfier);
notificationThread.start();
}
}
}
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException | APIManagementException e) {
throw new NotificationException("Error while Initializing the notifier class", e);
}
}
use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method process.
/**
* Process API lifecycle notifier events related to APIs deployed in external gateway
*
* @param event related to deployments
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
APIEvent apiEvent;
apiEvent = (APIEvent) event;
if (APIConstants.EventType.API_LIFECYCLE_CHANGE.name().equals(event.getType())) {
// Handle API retiring life cycle change in external gateway
undeployApiWhenRetiring(apiEvent);
} else if (APIConstants.EventType.API_DELETE.name().equals(event.getType())) {
// Handle API deletion in external gateway
undeployWhenDeleting(apiEvent);
}
}
use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project carbon-apimgt by wso2.
the class SolaceKeyGenNotifier method process.
/**
* Process Application notifier event related to key generation related to Solace Applications
*
* @param event related to Key generation handling
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
ApplicationRegistrationEvent applicationRegistrationEvent;
applicationRegistrationEvent = (ApplicationRegistrationEvent) event;
if (APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name().equals(event.getType())) {
syncSolaceApplicationClientId(applicationRegistrationEvent);
}
}
Aggregations