use of io.gravitee.repository.management.model.PortalNotificationConfig in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_FindByIdTest method shouldFindExistingConfig.
@Test
public void shouldFindExistingConfig() throws TechnicalException {
PortalNotificationConfig cfg = mock(PortalNotificationConfig.class);
when(cfg.getReferenceType()).thenReturn(NotificationReferenceType.API);
when(cfg.getReferenceId()).thenReturn("123");
when(cfg.getUser()).thenReturn("user");
when(cfg.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
when(portalNotificationConfigRepository.findById("user", NotificationReferenceType.API, "123")).thenReturn(of(cfg));
final PortalNotificationConfigEntity entity = portalNotificationConfigService.findById("user", NotificationReferenceType.API, "123");
assertNotNull(entity);
assertEquals("referenceId", cfg.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfg.getReferenceType().name(), entity.getReferenceType());
assertEquals("user", cfg.getUser(), entity.getUser());
assertEquals("hooks", cfg.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, times(1)).findById("user", NotificationReferenceType.API, "123");
}
use of io.gravitee.repository.management.model.PortalNotificationConfig in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_SaveTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
PortalNotificationConfig cfg = mock(PortalNotificationConfig.class);
when(cfg.getReferenceType()).thenReturn(NotificationReferenceType.API);
when(cfg.getReferenceId()).thenReturn("123");
when(cfg.getUser()).thenReturn("user");
when(cfg.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
PortalNotificationConfigEntity cfgEntity = mock(PortalNotificationConfigEntity.class);
when(cfgEntity.getReferenceType()).thenReturn(NotificationReferenceType.API.name());
when(cfgEntity.getReferenceId()).thenReturn("123");
when(cfgEntity.getUser()).thenReturn("user");
when(cfgEntity.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
when(portalNotificationConfigRepository.findById("user", NotificationReferenceType.API, "123")).thenReturn(of(cfg));
when(portalNotificationConfigRepository.update(any(PortalNotificationConfig.class))).thenReturn(cfg);
final PortalNotificationConfigEntity entity = portalNotificationConfigService.save(cfgEntity);
assertNotNull(entity);
assertEquals("referenceId", cfgEntity.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfgEntity.getReferenceType(), entity.getReferenceType());
assertEquals("user", cfgEntity.getUser(), entity.getUser());
assertEquals("hooks", cfgEntity.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, times(1)).findById("user", NotificationReferenceType.API, "123");
verify(portalNotificationConfigRepository, times(1)).update(any());
verify(portalNotificationConfigRepository, never()).delete(any());
verify(portalNotificationConfigRepository, never()).create(any());
}
use of io.gravitee.repository.management.model.PortalNotificationConfig in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_SaveTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
PortalNotificationConfig cfg = mock(PortalNotificationConfig.class);
when(cfg.getReferenceType()).thenReturn(NotificationReferenceType.API);
when(cfg.getReferenceId()).thenReturn("123");
when(cfg.getUser()).thenReturn("user");
when(cfg.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
PortalNotificationConfigEntity cfgEntity = mock(PortalNotificationConfigEntity.class);
when(cfgEntity.getReferenceType()).thenReturn(NotificationReferenceType.API.name());
when(cfgEntity.getReferenceId()).thenReturn("123");
when(cfgEntity.getUser()).thenReturn("user");
when(cfgEntity.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
when(portalNotificationConfigRepository.findById("user", NotificationReferenceType.API, "123")).thenReturn(empty());
when(portalNotificationConfigRepository.create(any(PortalNotificationConfig.class))).thenReturn(cfg);
final PortalNotificationConfigEntity entity = portalNotificationConfigService.save(cfgEntity);
assertNotNull(entity);
assertEquals("referenceId", cfgEntity.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfgEntity.getReferenceType(), entity.getReferenceType());
assertEquals("user", cfgEntity.getUser(), entity.getUser());
assertEquals("hooks", cfgEntity.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, times(1)).findById("user", NotificationReferenceType.API, "123");
verify(portalNotificationConfigRepository, times(1)).create(any());
verify(portalNotificationConfigRepository, never()).delete(any());
verify(portalNotificationConfigRepository, never()).update(any());
}
use of io.gravitee.repository.management.model.PortalNotificationConfig in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigServiceImpl method convert.
private PortalNotificationConfig convert(PortalNotificationConfigEntity entity) {
PortalNotificationConfig portalNotificationConfig = new PortalNotificationConfig();
portalNotificationConfig.setReferenceType(NotificationReferenceType.valueOf(entity.getReferenceType()));
portalNotificationConfig.setReferenceId(entity.getReferenceId());
portalNotificationConfig.setUser(entity.getUser());
portalNotificationConfig.setHooks(entity.getHooks());
return portalNotificationConfig;
}
use of io.gravitee.repository.management.model.PortalNotificationConfig in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigServiceImpl method save.
@Override
public PortalNotificationConfigEntity save(PortalNotificationConfigEntity notificationEntity) {
try {
if (notificationEntity.getHooks() == null || notificationEntity.getHooks().isEmpty()) {
portalNotificationConfigRepository.delete(convert(notificationEntity));
return getDefaultEmpty(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
} else {
Optional<PortalNotificationConfig> optionalConfig = portalNotificationConfigRepository.findById(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
PortalNotificationConfig notificationConfig = convert(notificationEntity);
if (optionalConfig.isPresent()) {
notificationConfig.setCreatedAt(optionalConfig.get().getCreatedAt());
notificationConfig.setUpdatedAt(new Date());
return convert(portalNotificationConfigRepository.update(notificationConfig));
} else {
notificationConfig.setCreatedAt(new Date());
notificationConfig.setUpdatedAt(notificationConfig.getCreatedAt());
return convert(portalNotificationConfigRepository.create(notificationConfig));
}
}
} catch (TechnicalException te) {
LOGGER.error("An error occurs while trying to save the notification settings {}", notificationEntity, te);
throw new TechnicalManagementException("An error occurs while trying to save the notification settings " + notificationEntity, te);
}
}
Aggregations