2019-12-02 18:02:11 +01:00
|
|
|
package org.gcube.tests;
|
|
|
|
|
2020-06-24 16:47:01 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2019-12-05 11:56:51 +01:00
|
|
|
import org.gcube.common.resources.gcore.GenericResource;
|
|
|
|
import org.gcube.common.resources.gcore.Resources;
|
2019-12-10 17:06:52 +01:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.Translator;
|
2019-12-05 11:56:51 +01:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.commons.IS;
|
2020-02-03 18:14:47 +01:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
|
|
|
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
2019-12-02 18:02:11 +01:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
public class TransformationTests {
|
|
|
|
|
|
|
|
static ObjectMapper mapper=null;
|
2020-06-24 16:47:01 +02:00
|
|
|
|
|
|
|
static Map<String,String> mappings=new HashMap<String,String>();
|
|
|
|
|
2019-12-02 18:02:11 +01:00
|
|
|
@BeforeClass
|
|
|
|
public static void init () {
|
|
|
|
mapper=TestCommons.getMapper();
|
2020-06-24 16:47:01 +02:00
|
|
|
|
|
|
|
mappings.put("/blue_cloud_dataset.json", "/blue_cloud_dataset.xml");
|
2019-12-02 18:02:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
2019-12-03 15:58:35 +01:00
|
|
|
public void transform() throws Exception {
|
2019-12-10 17:06:52 +01:00
|
|
|
Translator basic=new Translator();
|
2019-12-05 11:56:51 +01:00
|
|
|
TestCommons.readAndTransform("/simpleItem.json",basic);
|
|
|
|
TestCommons.readAndTransform("/FSKXModel.json",basic);
|
2020-01-13 16:49:50 +01:00
|
|
|
TestCommons.readAndTransform("/ResearchObject.json",basic);
|
2019-12-02 18:02:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-03 12:50:36 +01:00
|
|
|
@Test
|
2019-12-05 11:56:51 +01:00
|
|
|
public void transformWithMappings() throws Exception {
|
2019-12-03 15:58:35 +01:00
|
|
|
|
2020-01-13 16:49:50 +01:00
|
|
|
GenericResource res=Resources.unmarshal(GenericResource.class, TransformationTests.class.getResourceAsStream("/ResearchObject.xml"));
|
|
|
|
Translator t=new Translator(IS.readMappings(res));
|
|
|
|
// TestCommons.readAndTransform("/ResearchObject.json", t);
|
2020-06-24 16:47:01 +02:00
|
|
|
// TestCommons.readAndTransform("/crop_parameters.json",t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Entry<String,String> entry:mappings.entrySet()) {
|
|
|
|
GenericResource resource=Resources.unmarshal(GenericResource.class, TransformationTests.class.getResourceAsStream(entry.getValue()));
|
|
|
|
Translator translator=new Translator(IS.readMappings(resource));
|
|
|
|
TestCommons.readAndTransform(entry.getKey(), translator);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-03 15:58:35 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 18:14:47 +01:00
|
|
|
@Test
|
|
|
|
public void filterResources() throws Exception {
|
|
|
|
GenericResource res=Resources.unmarshal(GenericResource.class, TransformationTests.class.getResourceAsStream("/ResearchObject.xml"));
|
|
|
|
Translator t=new Translator(IS.readMappings(res),IS.readResourceFilters(res));
|
|
|
|
|
|
|
|
String json=TestCommons.convertStreamToString(TransformationTests.class.getResourceAsStream("/ResearchObject.json"));
|
|
|
|
CkanItemDescriptor desc=new CkanItemDescriptor(json);
|
|
|
|
|
|
|
|
for(CkanResource filtered:t.filterResources(desc))
|
|
|
|
System.out.println("NAME : "+filtered.getName()+ " FORMAT : "+filtered.getFormat());
|
|
|
|
}
|
2020-06-18 13:46:19 +02:00
|
|
|
|
|
|
|
|
2019-12-02 18:02:11 +01:00
|
|
|
}
|