2020-09-07 15:36:30 +02:00
|
|
|
package eu.dnetlib.ariadneplus.reader.utils;
|
|
|
|
|
2020-09-07 15:37:05 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2020-09-07 15:36:30 +02:00
|
|
|
public class ESUtilsTest {
|
2020-09-07 15:37:05 +02:00
|
|
|
|
2020-11-30 13:27:28 +01:00
|
|
|
// Elastic search format: yyyy-MM-dd or yyyy
|
|
|
|
|
2020-09-07 15:37:05 +02:00
|
|
|
@Test
|
|
|
|
public void testParseDate(){
|
|
|
|
String date = "2013-03-13";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals(parsed, date);
|
2020-09-07 15:37:05 +02:00
|
|
|
}
|
2020-11-30 13:27:28 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testBSTDate(){
|
|
|
|
String date = "Fri May 15 13:21:02 BST 2020";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals("2020-05-15", parsed);
|
2020-11-30 13:27:28 +01:00
|
|
|
}
|
2021-01-26 16:39:47 +01:00
|
|
|
|
2022-11-17 14:38:03 +01:00
|
|
|
|
2021-01-26 16:39:47 +01:00
|
|
|
@Test
|
|
|
|
public void testYearDate(){
|
|
|
|
String date = "2012";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals("2012", parsed);
|
2021-01-26 16:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testEmtyDate(){
|
|
|
|
String date = "";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals("0000", parsed);
|
2021-01-26 16:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testErrorDate(){
|
|
|
|
String date = "????";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals("0000", parsed);
|
2021-01-26 16:39:47 +01:00
|
|
|
}
|
2022-11-17 14:38:03 +01:00
|
|
|
@Test
|
|
|
|
public void testUnknownDate(){
|
|
|
|
String date = "unknown";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
|
|
|
Assert.assertEquals("0000", parsed);
|
|
|
|
}
|
|
|
|
|
2022-11-16 16:31:47 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDateMonthString(){
|
|
|
|
String date = "27-Oct-2022";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
|
|
|
System.out.println(parsed);
|
2022-11-17 14:38:03 +01:00
|
|
|
Assert.assertEquals("2022-10-27", parsed);
|
|
|
|
}
|
|
|
|
@Test
|
|
|
|
public void testDateCapitalMonthString(){
|
|
|
|
String date = "27-OCT-2022";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
|
|
|
System.out.println(parsed);
|
|
|
|
Assert.assertEquals("2022-10-27", parsed);
|
2022-11-16 16:31:47 +01:00
|
|
|
}
|
|
|
|
|
2022-11-17 14:38:03 +01:00
|
|
|
@Test
|
|
|
|
public void testDateMonthString2(){
|
|
|
|
String date = "27 Oct 2022";
|
|
|
|
String parsed = ESUtils.getESFormatDate(date);
|
|
|
|
System.out.println(parsed);
|
|
|
|
Assert.assertEquals("2022-10-27", parsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-07 15:36:30 +02:00
|
|
|
}
|