Search in sources :

Example 6 with PortalNotificationConfigEntity

use of io.gravitee.management.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.

the class PortalNotificationSettingsResource method convert.

private PortalNotificationConfigEntity convert(GenericNotificationConfigEntity generic) {
    PortalNotificationConfigEntity portalNotificationConfigEntity = new PortalNotificationConfigEntity();
    portalNotificationConfigEntity.setConfigType(generic.getConfigType());
    portalNotificationConfigEntity.setReferenceType(generic.getReferenceType());
    portalNotificationConfigEntity.setReferenceId(generic.getReferenceId());
    portalNotificationConfigEntity.setUser(getAuthenticatedUser());
    portalNotificationConfigEntity.setHooks(generic.getHooks());
    return portalNotificationConfigEntity;
}
Also used : PortalNotificationConfigEntity(io.gravitee.management.model.notification.PortalNotificationConfigEntity)

Example 7 with PortalNotificationConfigEntity

use of io.gravitee.management.model.notification.PortalNotificationConfigEntity 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());
}
Also used : PortalNotificationConfig(io.gravitee.repository.management.model.PortalNotificationConfig) PortalNotificationConfigEntity(io.gravitee.management.model.notification.PortalNotificationConfigEntity) Test(org.junit.Test)

Example 8 with PortalNotificationConfigEntity

use of io.gravitee.management.model.notification.PortalNotificationConfigEntity 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());
}
Also used : PortalNotificationConfig(io.gravitee.repository.management.model.PortalNotificationConfig) PortalNotificationConfigEntity(io.gravitee.management.model.notification.PortalNotificationConfigEntity) Test(org.junit.Test)

Example 9 with PortalNotificationConfigEntity

use of io.gravitee.management.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiNotificationSettingsResource method convert.

private PortalNotificationConfigEntity convert(GenericNotificationConfigEntity generic) {
    PortalNotificationConfigEntity portalNotificationConfigEntity = new PortalNotificationConfigEntity();
    portalNotificationConfigEntity.setConfigType(generic.getConfigType());
    portalNotificationConfigEntity.setReferenceType(generic.getReferenceType());
    portalNotificationConfigEntity.setReferenceId(generic.getReferenceId());
    portalNotificationConfigEntity.setUser(getAuthenticatedUser());
    portalNotificationConfigEntity.setHooks(generic.getHooks());
    return portalNotificationConfigEntity;
}
Also used : PortalNotificationConfigEntity(io.gravitee.management.model.notification.PortalNotificationConfigEntity)

Example 10 with PortalNotificationConfigEntity

use of io.gravitee.management.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.

the class PortalNotificationConfigServiceImpl method getDefaultEmpty.

private PortalNotificationConfigEntity getDefaultEmpty(String user, NotificationReferenceType referenceType, String referenceId) {
    PortalNotificationConfigEntity portalNotificationConfigEntity = new PortalNotificationConfigEntity();
    portalNotificationConfigEntity.setConfigType(NotificationConfigType.PORTAL);
    portalNotificationConfigEntity.setReferenceType(referenceType.name());
    portalNotificationConfigEntity.setReferenceId(referenceId);
    portalNotificationConfigEntity.setUser(user);
    portalNotificationConfigEntity.setHooks(Collections.emptyList());
    return portalNotificationConfigEntity;
}
Also used : PortalNotificationConfigEntity(io.gravitee.management.model.notification.PortalNotificationConfigEntity)

Aggregations

PortalNotificationConfigEntity (io.gravitee.management.model.notification.PortalNotificationConfigEntity)10 Test (org.junit.Test)5 PortalNotificationConfig (io.gravitee.repository.management.model.PortalNotificationConfig)3