use of org.wso2.carbon.apimgt.core.exception.NotificationException in project carbon-apimgt by wso2.
the class NotificationExecutorTest method testShouldNotThrowExceptionWhenConfigurationNotFound.
@Test
public void testShouldNotThrowExceptionWhenConfigurationNotFound() throws Exception {
NotificationDTO notificationDTO = new NotificationDTO(new Properties(), NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
notificationDTO.setTenantID(TENANT_ID);
notificationDTO.setTenantDomain(TENANT_DOMAIN);
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.core.exception.NotificationException 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");
}
}
use of org.wso2.carbon.apimgt.core.exception.NotificationException in project carbon-apimgt by wso2.
the class NewAPIVersionEmailNotifierTest method testShouldNotLoadMessageWhenErrorOccurs.
@Test
public void testShouldNotLoadMessageWhenErrorOccurs() throws RegistryException {
Resource resource = Mockito.mock(Resource.class);
NewAPIVersionEmailNotifier emailNotifier = new NewAPIVersionEmailNotifier() {
@Override
protected Registry getConfigSystemRegistry(int tenantId) throws RegistryException {
return registry;
}
};
Mockito.when(registry.resourceExists(Mockito.anyString())).thenReturn(true).thenThrow(RegistryException.class);
Mockito.when(registry.get(Mockito.anyString())).thenReturn(resource);
Mockito.when(resource.getContent()).thenReturn("".getBytes());
try {
NotificationDTO notification = emailNotifier.loadMessageTemplate(notificationDTO);
Assert.assertFalse(!notification.getMessage().equals(""));
emailNotifier.loadMessageTemplate(notificationDTO);
Assert.fail("Should fail with an exception");
} catch (NotificationException e) {
// exception is expection
return;
}
}
use of org.wso2.carbon.apimgt.core.exception.NotificationException in project carbon-apimgt by wso2.
the class NewAPIVersionEmailNotifierTest method testShouldReturnNotifiersWhenPropertiesValid.
@Test
public void testShouldReturnNotifiersWhenPropertiesValid() throws APIManagementException {
final ClaimsRetriever claimsRetriever = Mockito.mock(ClaimsRetriever.class);
final SortedMap<String, String> claims = new TreeMap<String, String>();
claims.put(NotifierConstants.EMAIL_CLAIM, "admin@wso2.com");
NewAPIVersionEmailNotifier emailNotifier = new NewAPIVersionEmailNotifier() {
@Override
protected ClaimsRetriever getClaimsRetriever(String claimsRetrieverImplClass) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
return claimsRetriever;
}
};
Mockito.doNothing().when(claimsRetriever).init();
Mockito.when(claimsRetriever.getClaims(Mockito.anyString())).thenReturn(claims);
try {
Assert.assertTrue(emailNotifier.getNotifierSet(notificationDTO).size() > 0);
} catch (NotificationException e) {
Assert.fail("Should not throw any exceptions");
}
}
use of org.wso2.carbon.apimgt.core.exception.NotificationException in project carbon-apimgt by wso2.
the class APIProviderImpl method sendEmailNotification.
/**
* This method used to send notifications to the previous subscribers of older versions of a given API
*
* @param api
* @throws APIManagementException
*/
private void sendEmailNotification(API api) throws APIManagementException {
try {
JSONObject tenantConfig = APIUtil.getTenantConfig(tenantDomain);
String isNotificationEnabled = "false";
if (tenantConfig.containsKey(NotifierConstants.NOTIFICATIONS_ENABLED)) {
isNotificationEnabled = (String) tenantConfig.get(NotifierConstants.NOTIFICATIONS_ENABLED);
}
if (JavaUtils.isTrueExplicitly(isNotificationEnabled)) {
List<APIIdentifier> apiIdentifiers = getOldPublishedAPIList(api);
for (APIIdentifier oldAPI : apiIdentifiers) {
Properties prop = new Properties();
prop.put(NotifierConstants.API_KEY, oldAPI);
prop.put(NotifierConstants.NEW_API_KEY, api.getId());
Set<Subscriber> subscribersOfAPI = apiMgtDAO.getSubscribersOfAPI(oldAPI);
prop.put(NotifierConstants.SUBSCRIBERS_PER_API, subscribersOfAPI);
NotificationDTO notificationDTO = new NotificationDTO(prop, NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
notificationDTO.setTenantID(tenantId);
notificationDTO.setTenantDomain(tenantDomain);
new NotificationExecutor().sendAsyncNotifications(notificationDTO);
}
}
} catch (NotificationException e) {
log.error(e.getMessage(), e);
}
}
Aggregations