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 java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
|
|
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-03-19 18:02:08 +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-03-19 18:02:08 +01:00
|
|
|
import org.junit.Before;
|
2019-03-19 19:04:36 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2019-03-19 18:02:08 +01:00
|
|
|
|
|
|
|
public class Interactions {
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
private static class CustomTargetFormat implements CatalogueFormatData{
|
|
|
|
|
|
|
|
private String fileName;
|
|
|
|
|
|
|
|
public CustomTargetFormat(String fileName) {
|
|
|
|
super();
|
|
|
|
this.fileName = fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toCatalogueFormat() {
|
|
|
|
try {
|
|
|
|
return new String(Files.readAllBytes(Paths.get(fileName)));
|
|
|
|
}catch(Exception e) {
|
|
|
|
throw new RuntimeException("Unable to read file "+fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-19 18:02:08 +01:00
|
|
|
@Before
|
2019-03-19 19:04:36 +01:00
|
|
|
public void setToken() {
|
|
|
|
TokenSetter.set("/gcube/preprod/preVRE");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CatalogueController getController() throws ControllerInstantiationFault {
|
|
|
|
GCatPlugin plugin=new GCatPlugin();
|
|
|
|
return plugin.instantiateController(new CatalogueInstanceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected=ControllerInstantiationFault.class)
|
|
|
|
public void testFailInstance() throws ControllerInstantiationFault {
|
|
|
|
GCatPlugin plugin=new GCatPlugin();
|
|
|
|
plugin.instantiateController(new CatalogueInstanceDescriptor().setUrl("http://no.where.com"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void duplicates() {
|
|
|
|
try {
|
|
|
|
publish(getController(),"full.json");
|
|
|
|
publish(getController(),"full.json");
|
|
|
|
}catch(Exception e) {
|
|
|
|
Assert.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected=PublicationException.class)
|
|
|
|
public void missingProfile() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault {
|
|
|
|
publish(getController(),"missingProfile.json");
|
2019-03-19 18:02:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-19 19:04:36 +01:00
|
|
|
@Test(expected=WrongObjectFormatException.class)
|
|
|
|
public void noitem() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault {
|
|
|
|
publish(getController(),"noItem.json");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void item() {
|
|
|
|
try {
|
|
|
|
publish(getController(),"onlyItem.json");
|
|
|
|
} catch (WrongObjectFormatException | PublicationException | ControllerInstantiationFault e) {
|
|
|
|
Assert.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static PublishReport publish(CatalogueController controller, String filename) throws CatalogueInteractionException, WrongObjectFormatException, PublicationException {
|
|
|
|
return controller.publishItem(new CustomTargetFormat(filename));
|
|
|
|
}
|
2019-03-19 18:02:08 +01:00
|
|
|
}
|