2019-03-19 18:02:08 +01:00
|
|
|
package org.gcube.data.publishing.gCatFeeder.catalogues.gCat;
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.CatalogueInteractionException;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.ControllerInstantiationFault;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.PublicationException;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
|
2019-04-01 15:30:16 +02:00
|
|
|
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
|
2019-04-01 16:23:05 +02:00
|
|
|
import org.gcube.data.publishing.gCatFeeder.tests.BaseCataloguePluginTest;
|
2021-11-09 14:31:58 +01:00
|
|
|
import org.gcube.data.publishing.gCatFeeder.tests.TokenSetter;
|
2019-03-19 19:04:36 +01:00
|
|
|
import org.gcube.data.publishing.gCataFeeder.catalogues.gCat.GCatPlugin;
|
|
|
|
import org.junit.Assert;
|
2019-04-01 16:23:05 +02:00
|
|
|
import org.junit.Assume;
|
2019-03-19 19:04:36 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2019-03-19 18:02:08 +01:00
|
|
|
|
2019-04-01 16:23:05 +02:00
|
|
|
public class Interactions extends BaseCataloguePluginTest{
|
2019-03-19 18:02:08 +01:00
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
private static class CustomTargetFormat implements CatalogueFormatData{
|
2019-04-01 16:23:05 +02:00
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
private String fileName;
|
|
|
|
|
|
|
|
public CustomTargetFormat(String fileName) {
|
|
|
|
super();
|
|
|
|
this.fileName = fileName;
|
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Override
|
|
|
|
public String toCatalogueFormat() {
|
|
|
|
try {
|
2019-04-03 15:59:18 +02:00
|
|
|
return convertStreamToString(this.getClass().getResourceAsStream((fileName)));
|
2019-03-19 19:04:36 +01:00
|
|
|
}catch(Exception e) {
|
2019-04-03 15:59:18 +02:00
|
|
|
throw new RuntimeException("Unable to read file "+fileName,e);
|
2019-03-19 19:04:36 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-03 15:59:18 +02:00
|
|
|
|
|
|
|
static String convertStreamToString(java.io.InputStream is) {
|
|
|
|
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
|
|
|
|
return s.hasNext() ? s.next() : "";
|
|
|
|
}
|
2019-03-19 19:04:36 +01:00
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
public CatalogueController getController() throws ControllerInstantiationFault {
|
|
|
|
GCatPlugin plugin=new GCatPlugin();
|
|
|
|
return plugin.instantiateController(new CatalogueInstanceDescriptor());
|
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Test(expected=ControllerInstantiationFault.class)
|
|
|
|
public void testFailInstance() throws ControllerInstantiationFault {
|
|
|
|
GCatPlugin plugin=new GCatPlugin();
|
|
|
|
plugin.instantiateController(new CatalogueInstanceDescriptor().setUrl("http://no.where.com"));
|
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Test
|
|
|
|
public void duplicates() {
|
2019-04-01 16:23:05 +02:00
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
try {
|
|
|
|
publish(getController(),"full.json");
|
|
|
|
publish(getController(),"full.json");
|
|
|
|
}catch(Exception e) {
|
|
|
|
Assert.fail(e.getMessage());
|
|
|
|
}
|
2019-03-19 19:04:36 +01:00
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
2019-04-02 17:46:32 +02:00
|
|
|
@Test
|
|
|
|
public void testDM() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, InternalConversionException, ControllerInstantiationFault {
|
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
publish(getController(),"full-algorithm.json");
|
|
|
|
}
|
|
|
|
|
2020-05-08 14:34:12 +02:00
|
|
|
@Test
|
|
|
|
public void testOAI() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, InternalConversionException, ControllerInstantiationFault {
|
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
publish(getController(),"oai_dc_full.json");
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:53:00 +01:00
|
|
|
@Test(expected=WrongObjectFormatException.class)
|
2019-04-01 15:30:16 +02:00
|
|
|
public void empties() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
|
2019-04-01 16:23:05 +02:00
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
publish(getController(),"empties.json");
|
2019-03-20 17:53:00 +01:00
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
2019-05-22 15:36:47 +02:00
|
|
|
@Test(expected=WrongObjectFormatException.class)
|
2019-04-01 15:30:16 +02:00
|
|
|
public void missingProfile() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
|
2019-04-01 16:23:05 +02:00
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
publish(getController(),"missingProfile.json");
|
2019-03-19 18:02:08 +01:00
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Test(expected=WrongObjectFormatException.class)
|
2019-04-01 15:30:16 +02:00
|
|
|
public void noitem() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
|
2019-04-01 16:23:05 +02:00
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
publish(getController(),"noItem.json");
|
2019-03-19 19:04:36 +01:00
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Test
|
|
|
|
public void item() {
|
2019-04-01 16:23:05 +02:00
|
|
|
Assume.assumeTrue(isTestInfrastructureEnabled());
|
2019-03-19 19:04:36 +01:00
|
|
|
try {
|
|
|
|
publish(getController(),"onlyItem.json");
|
2019-04-01 15:30:16 +02:00
|
|
|
} catch (WrongObjectFormatException | PublicationException | ControllerInstantiationFault | InternalConversionException e) {
|
2019-03-19 19:04:36 +01:00
|
|
|
Assert.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
2019-04-01 15:30:16 +02:00
|
|
|
private static PublishReport publish(CatalogueController controller, String filename) throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, InternalConversionException {
|
2019-03-19 19:04:36 +01:00
|
|
|
return controller.publishItem(new CustomTargetFormat(filename));
|
|
|
|
}
|
2019-03-19 18:02:08 +01:00
|
|
|
}
|