54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
|
package metrics;
|
||
|
|
||
|
import eu.dnetlib.repo.manager.controllers.PrometheusController;
|
||
|
import eu.dnetlib.repo.manager.service.PiWikService;
|
||
|
import org.junit.Before;
|
||
|
import org.junit.Test;
|
||
|
import org.mockito.InjectMocks;
|
||
|
import org.mockito.Mock;
|
||
|
import org.mockito.MockitoAnnotations;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.stereotype.Component;
|
||
|
|
||
|
import static org.junit.Assert.assertTrue;
|
||
|
import static org.mockito.Mockito.when;
|
||
|
|
||
|
@Component
|
||
|
public class PrometheusTest {
|
||
|
|
||
|
private static final int TOTAL = 10;
|
||
|
private static final int VALIDATED = 8;
|
||
|
|
||
|
@Autowired
|
||
|
@Mock
|
||
|
PiWikService piWikService;
|
||
|
|
||
|
@Autowired
|
||
|
@InjectMocks
|
||
|
private PrometheusController prometheusController;
|
||
|
|
||
|
@Before
|
||
|
public void setUp() throws Exception {
|
||
|
MockitoAnnotations.initMocks(this);
|
||
|
|
||
|
when(piWikService.getTotal()).thenReturn(TOTAL);
|
||
|
when(piWikService.getValidated(true)).thenReturn(VALIDATED);
|
||
|
when(piWikService.getValidated(false)).thenReturn(TOTAL - VALIDATED);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testMetrics() {
|
||
|
String report = prometheusController.getMetrics();
|
||
|
assertTrue(report.startsWith("#"));
|
||
|
System.out.println(report);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testPiwikMetrics() {
|
||
|
assertTrue(piWikService.getValidated(false).equals(TOTAL - VALIDATED));
|
||
|
String report = prometheusController.getPiwikMetrics();
|
||
|
assertTrue(report.contains("total_total " + TOTAL));
|
||
|
assertTrue(report.contains("validated_total " + VALIDATED));
|
||
|
System.out.println(report);
|
||
|
}
|
||
|
}
|