Search in sources :

Example 1 with NotificationToMetricConverter

use of com.yahoo.athenz.common.server.notification.NotificationToMetricConverter in project athenz by yahoo.

the class MetricNotificationServiceTest method testNotify.

@Test
public void testNotify() {
    Metric metric = Mockito.mock(Metric.class);
    MetricNotificationService metricNotificationService = new MetricNotificationService(metric);
    String[] attributesList1 = new String[] { "key1", "attribute11", "key2", "attribute12", "key3", "attribute13" };
    String[] attributesList2 = new String[] { "key1", "attribute21", "key2", "attribute22", "key3", "attribute23" };
    List<String[]> attributes = new ArrayList<>();
    attributes.add(attributesList1);
    attributes.add(attributesList2);
    NotificationToMetricConverter notificationToMetricConverter = Mockito.mock(NotificationToMetricConverter.class);
    Mockito.when(notificationToMetricConverter.getNotificationAsMetrics(Mockito.any(), Mockito.any())).thenReturn(new NotificationMetric(attributes));
    Notification notification = new Notification();
    notification.setNotificationToMetricConverter(notificationToMetricConverter);
    boolean notify = metricNotificationService.notify(notification);
    assertTrue(notify);
    ArgumentCaptor<String> captorMetric = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String[]> captorAttributes = ArgumentCaptor.forClass(String[].class);
    Mockito.verify(metric, Mockito.times(2)).increment(captorMetric.capture(), captorAttributes.capture());
    assertEquals(2, captorMetric.getAllValues().size());
    assertEquals("athenz_notification", captorMetric.getAllValues().get(0));
    assertEquals("athenz_notification", captorMetric.getAllValues().get(1));
    // Mockito captures all varargs arguments in a single array
    assertEquals(12, captorAttributes.getAllValues().size());
    List<String> expectedAttributes = new ArrayList<String>(Arrays.asList("key1", "attribute11", "key2", "attribute12", "key3", "attribute13", "key1", "attribute21", "key2", "attribute22", "key3", "attribute23"));
    assertEquals(expectedAttributes, captorAttributes.getAllValues());
}
Also used : NotificationMetric(com.yahoo.athenz.common.server.notification.NotificationMetric) Notification(com.yahoo.athenz.common.server.notification.Notification) NotificationToMetricConverter(com.yahoo.athenz.common.server.notification.NotificationToMetricConverter) NotificationMetric(com.yahoo.athenz.common.server.notification.NotificationMetric) Metric(com.yahoo.athenz.common.metrics.Metric) Test(org.testng.annotations.Test)

Aggregations

Metric (com.yahoo.athenz.common.metrics.Metric)1 Notification (com.yahoo.athenz.common.server.notification.Notification)1 NotificationMetric (com.yahoo.athenz.common.server.notification.NotificationMetric)1 NotificationToMetricConverter (com.yahoo.athenz.common.server.notification.NotificationToMetricConverter)1 Test (org.testng.annotations.Test)1