1
|
package metrics;
|
2
|
|
3
|
import eu.dnetlib.repo.manager.controllers.PrometheusController;
|
4
|
import eu.dnetlib.repo.manager.service.PiWikService;
|
5
|
import org.junit.Before;
|
6
|
import org.junit.Test;
|
7
|
import org.mockito.InjectMocks;
|
8
|
import org.mockito.Mock;
|
9
|
import org.mockito.MockitoAnnotations;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.stereotype.Component;
|
12
|
|
13
|
import static org.junit.Assert.assertTrue;
|
14
|
import static org.mockito.Mockito.when;
|
15
|
|
16
|
@Component
|
17
|
public class PrometheusTest {
|
18
|
|
19
|
private static final int TOTAL = 10;
|
20
|
private static final int VALIDATED = 8;
|
21
|
|
22
|
@Autowired
|
23
|
@Mock
|
24
|
PiWikService piWikService;
|
25
|
|
26
|
@Autowired
|
27
|
@InjectMocks
|
28
|
private PrometheusController prometheusController;
|
29
|
|
30
|
@Before
|
31
|
public void setUp() throws Exception {
|
32
|
MockitoAnnotations.initMocks(this);
|
33
|
|
34
|
when(piWikService.getTotal()).thenReturn(TOTAL);
|
35
|
when(piWikService.getValidated(true)).thenReturn(VALIDATED);
|
36
|
when(piWikService.getValidated(false)).thenReturn(TOTAL - VALIDATED);
|
37
|
}
|
38
|
|
39
|
@Test
|
40
|
public void testMetrics() {
|
41
|
String report = prometheusController.getMetrics();
|
42
|
assertTrue(report.startsWith("#"));
|
43
|
System.out.println(report);
|
44
|
}
|
45
|
|
46
|
@Test
|
47
|
public void testPiwikMetrics() {
|
48
|
assertTrue(piWikService.getValidated(false).equals(TOTAL - VALIDATED));
|
49
|
String report = prometheusController.getPiwikMetrics();
|
50
|
assertTrue(report.contains("total_total " + TOTAL));
|
51
|
assertTrue(report.contains("validated_total " + VALIDATED));
|
52
|
System.out.println(report);
|
53
|
}
|
54
|
}
|