Search in sources :

Example 1 with EmailConfig

use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddDuplicateReceiver.

@Test
public void testAddDuplicateReceiver() throws AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    List<EmailConfig> emailConfigList = new ArrayList<>();
    emailConfigList.add(new EmailConfig("ermias@kth.se"));
    Receiver receiver = new Receiver("team-X-mails").withEmailConfigs(emailConfigList);
    Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
        alertManagerConfigController.addReceiver(receiver);
    });
}
Also used : EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 2 with EmailConfig

use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testUpdateReceiverRollbackServerException.

@Test
public void testUpdateReceiverRollbackServerException() throws AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
    Mockito.when(client.reload()).thenThrow(AlertManagerServerException.class);
    List<EmailConfig> emailConfigList = new ArrayList<>();
    emailConfigList.add(new EmailConfig("team-Z+alerts@example.org"));
    Receiver receiver = new Receiver("team-Z-email").withEmailConfigs(emailConfigList);
    Assert.assertThrows(AlertManagerServerException.class, () -> {
        AlertManagerConfig config = alertManagerConfigController.addReceiver(receiver);
        alertManagerConfigController.writeAndReload(config);
    });
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    assert !alertManagerConfig.getReceivers().contains(receiver);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 3 with EmailConfig

use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testUpdateReceiver.

@Test
public void testUpdateReceiver() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    EmailConfig emailConfig = new EmailConfig("team-Y+alerts@example.org");
    List<EmailConfig> emailConfigList = new ArrayList<>();
    emailConfigList.add(emailConfig);
    Receiver receiver = new Receiver("team-Y-mail").withEmailConfigs(emailConfigList);
    AlertManagerConfig config = alertManagerConfigController.updateReceiver("team-Y-mails", receiver);
    alertManagerConfigController.writeAndReload(config);
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    int index = alertManagerConfig.getReceivers().indexOf(receiver);
    assert index > -1;
    Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
    assert updatedReceiver.getEmailConfigs().contains(emailConfig);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 4 with EmailConfig

use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddEmailValidation.

@Test
public void testAddEmailValidation() throws AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    EmailConfig emailConfig = new EmailConfig();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addEmailToReceiver("team-X-mails", emailConfig);
    });
}
Also used : EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) Test(org.junit.Test)

Example 5 with EmailConfig

use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddEmailToReceiver.

@Test
public void testAddEmailToReceiver() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerNoSuchElementException, AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    EmailConfig emailConfig = new EmailConfig("team-X+alerts@example.org");
    Receiver receiver = new Receiver("team-X-mails");
    AlertManagerConfig config = alertManagerConfigController.addEmailToReceiver("team-X-mails", emailConfig);
    alertManagerConfigController.writeAndReload(config);
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    int index = alertManagerConfig.getReceivers().indexOf(receiver);
    Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
    assert updatedReceiver.getEmailConfigs().contains(emailConfig);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Aggregations

EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)13 Test (org.junit.Test)11 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)10 ArrayList (java.util.ArrayList)8 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)6 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)1 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)1 Entry (io.hops.hopsworks.api.alert.Entry)1 AlertReceiver (io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver)1