yes, i'm using junit 4.12
public class NebefRefOeItemReaderTest {
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
String wireMockPort = String.valueOf(wireMockRule.port());
RestTemplate restTemplate = new RestTemplate();
String refOeAPI = "/api/v1/referentiel/ref-oe";
String urlAPI = "
http://localhost:" + wireMockPort + refOeAPI;
NebefRefOeItemReader reader = new NebefRefOeItemReader(urlAPI, restTemplate);
List<NebefRefOeProteine> result = reader.fetchOeDataFromAPI(urlAPI, restTemplate);
@Before
public void init() {
WireMock.configureFor(wireMockRule.port());
}
@Test
public void shouldReturnEmptyListWhenNoDataFromProteine() {
stubFor(get(urlEqualTo(refOeAPI))
.willReturn(aResponse().withStatus(200).withBodyFile("src/test/resources/oes.json")));
assertNotNull(result.size());
}
@Test
public void shouldReturnRightMappedDataFromProteine() {
assertEquals(result.get(0).getNom(), "RES REACTIVE FLEXIBILITE SERVICES");
assertEquals(result.get(0).getCodeEic(), "17X100A100F0085M");
assertEquals(result.get(0).getCodeIsu(), "20971");
assertEquals(result.get(0).getReEffaceur(), null);
LocalDate ld = LocalDate.parse("2017-01-01");
assertEquals(LocalDate.parse(Utils.formatSimpleDate(result.get(0).getDateDebutValidite())), ld);
ld = LocalDate.parse("2099-12-31");
assertEquals(LocalDate.parse(Utils.formatSimpleDate(result.get(0).getDateFinValidite())), ld);
ZonedDateTime zdt = ZonedDateTime.parse("2017-04-24T22:00:00.000Z");
assertEquals(ZonedDateTime.ofInstant(result.get(0).getDateDerniereModif().toInstant(), ZoneId.of("Z")), zdt);
}
@Test
public void shouldReturnOnlyMostRecentDataFromProteine() {
ZonedDateTime lastModif = ZonedDateTime.parse("2017-04-24T22:00:00.000Z");
Iterator<NebefRefOeProteine> it = result.iterator();
while (it.hasNext()) {
assertTrue(ZonedDateTime.ofInstant(it.next().getDateDerniereModif().toInstant(), ZoneId.of("Z")) != null);
}
ZonedDateTime first = ZonedDateTime.ofInstant(result.get(0).getDateDerniereModif().toInstant(), ZoneId.of("Z"));
long minutes = ChronoUnit.MINUTES.between(lastModif, first);
System.out.println(minutes + " entre " + first.toString() + " et " + lastModif.toString());
}
}
Le lundi 23 avril 2018 16:33:51 UTC+2, Aziz Ben Miled a écrit :