ckan2zenodo-library/src/test/java/org/gcube/tests/TransformationTests.java

75 lines
2.4 KiB
Java

package org.gcube.tests;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.data.publishing.ckan2zenodo.Translator;
import org.gcube.data.publishing.ckan2zenodo.commons.IS;
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
import org.junit.BeforeClass;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TransformationTests {
static ObjectMapper mapper=null;
static Map<String,String> mappings=new HashMap<String,String>();
@BeforeClass
public static void init () {
mapper=TestCommons.getMapper();
mappings.put("/blue_cloud_dataset.json", "/blue_cloud_dataset.xml");
}
@Test
public void transform() throws Exception {
Translator basic=new Translator();
TestCommons.readAndTransform("/simpleItem.json",basic);
TestCommons.readAndTransform("/FSKXModel.json",basic);
TestCommons.readAndTransform("/ResearchObject.json",basic);
}
@Test
public void transformWithMappings() throws Exception {
GenericResource res=Resources.unmarshal(GenericResource.class, TransformationTests.class.getResourceAsStream("/ResearchObject.xml"));
Translator t=new Translator(IS.readMappings(res));
// TestCommons.readAndTransform("/ResearchObject.json", t);
// 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);
}
}
@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());
}
}