2018-10-02 10:37:54 +02:00
|
|
|
package eu.dnetlib.pace.config;
|
|
|
|
|
2019-12-13 11:30:02 +01:00
|
|
|
|
2018-10-02 10:37:54 +02:00
|
|
|
import eu.dnetlib.pace.AbstractPaceTest;
|
2019-12-17 09:16:26 +01:00
|
|
|
import eu.dnetlib.pace.model.Field;
|
|
|
|
import eu.dnetlib.pace.model.FieldList;
|
2019-12-05 14:14:25 +01:00
|
|
|
import eu.dnetlib.pace.model.MapDocument;
|
2019-12-17 09:16:26 +01:00
|
|
|
import eu.dnetlib.pace.tree.JsonListMatch;
|
2019-12-05 14:14:25 +01:00
|
|
|
import eu.dnetlib.pace.util.MapDocumentUtil;
|
2018-10-02 10:37:54 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2019-11-07 12:47:12 +01:00
|
|
|
import java.util.Map;
|
2019-12-18 09:29:44 +01:00
|
|
|
import java.util.stream.Collectors;
|
2019-11-07 12:47:12 +01:00
|
|
|
|
2018-10-26 14:55:59 +02:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2018-10-02 10:37:54 +02:00
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
|
|
|
public class ConfigTest extends AbstractPaceTest {
|
|
|
|
|
|
|
|
@Test
|
2018-10-29 16:16:11 +01:00
|
|
|
public void dedupConfigSerializationTest() {
|
2019-12-17 09:16:26 +01:00
|
|
|
final DedupConfig cfgFromClasspath = DedupConfig.load(readFromClasspath("organization.current.conf.json"));
|
2018-10-02 10:37:54 +02:00
|
|
|
|
2018-10-29 16:16:11 +01:00
|
|
|
final String conf = cfgFromClasspath.toString();
|
|
|
|
|
|
|
|
final DedupConfig cfgFromSerialization = DedupConfig.load(conf);
|
|
|
|
|
|
|
|
assertEquals(cfgFromClasspath.toString(), cfgFromSerialization.toString());
|
|
|
|
|
2018-10-26 14:55:59 +02:00
|
|
|
assertNotNull(cfgFromClasspath);
|
2018-10-29 16:16:11 +01:00
|
|
|
assertNotNull(cfgFromSerialization);
|
2018-10-02 10:37:54 +02:00
|
|
|
}
|
|
|
|
|
2018-10-29 11:13:55 +01:00
|
|
|
@Test
|
|
|
|
public void dedupConfigTest() {
|
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
DedupConfig load = DedupConfig.load(readFromClasspath("organization.current.conf.json"));
|
2018-10-29 11:13:55 +01:00
|
|
|
|
|
|
|
System.out.println(load.toString());
|
|
|
|
}
|
|
|
|
|
2019-10-08 15:13:45 +02:00
|
|
|
@Test
|
2019-11-07 12:47:12 +01:00
|
|
|
public void initTranslationMapTest() {
|
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
DedupConfig load = DedupConfig.load(readFromClasspath("organization.current.conf.json"));
|
2019-11-07 12:47:12 +01:00
|
|
|
|
|
|
|
Map<String, String> translationMap = load.translationMap();
|
|
|
|
|
|
|
|
System.out.println("translationMap = " + translationMap.size());
|
2019-10-08 15:13:45 +02:00
|
|
|
|
2019-11-07 12:47:12 +01:00
|
|
|
for (String key: translationMap.keySet()) {
|
|
|
|
if (translationMap.get(key).equals("key::1"))
|
|
|
|
System.out.println("key = " + key);
|
|
|
|
}
|
2019-10-08 15:13:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-23 16:31:45 +02:00
|
|
|
@Test
|
|
|
|
public void emptyTranslationMapTest() {
|
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
DedupConfig load = DedupConfig.load(readFromClasspath("organization.no_synonyms.conf.json"));
|
2019-10-23 16:31:45 +02:00
|
|
|
|
|
|
|
assertEquals(0, load.getPace().translationMap().keySet().size());
|
|
|
|
}
|
|
|
|
|
2019-12-05 14:14:25 +01:00
|
|
|
@Test
|
2019-12-17 09:16:26 +01:00
|
|
|
public void asMapDocumentTest() throws Exception {
|
2019-12-05 14:14:25 +01:00
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
DedupConfig dedupConf = DedupConfig.load(readFromClasspath("publication.current.conf.json"));
|
2019-12-05 14:14:25 +01:00
|
|
|
|
2019-12-18 09:29:44 +01:00
|
|
|
final String json = readFromClasspath("pub2.json");
|
2019-12-05 14:14:25 +01:00
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
final MapDocument mapDocument = MapDocumentUtil.asMapDocumentWithJPath(dedupConf, json);
|
2019-12-05 14:14:25 +01:00
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
System.out.println("mapDocument = " + mapDocument.getFieldMap());
|
2019-12-05 14:14:25 +01:00
|
|
|
|
2019-12-18 09:29:44 +01:00
|
|
|
|
|
|
|
System.out.println(mapDocument.getFieldMap().values().stream().map(Field::isEmpty).count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testJPath() {
|
|
|
|
final String json = readFromClasspath("pub2.json");
|
|
|
|
|
|
|
|
final String jpath ="$.pid";
|
|
|
|
|
|
|
|
|
|
|
|
final List<String> jPathList = MapDocumentUtil.getJPathList(jpath, json, Type.JSON);
|
|
|
|
|
|
|
|
System.out.println("jPathList = " + jPathList);
|
|
|
|
|
|
|
|
|
2019-12-17 09:16:26 +01:00
|
|
|
}
|
2018-10-02 10:37:54 +02:00
|
|
|
}
|