This commit is contained in:
Fabio Sinibaldi 2019-03-19 18:04:36 +00:00
parent 9be8b0dbb2
commit a4182fc2e4
14 changed files with 105 additions and 7 deletions

View File

@ -12,15 +12,16 @@ public class CatalogueInstanceDescriptor {
private HashMap<String,String> headersParameters=new HashMap<>();
public CatalogueInstanceDescriptor(String url) {
public CatalogueInstanceDescriptor() {
super();
this.url = url;
}
public String getUrl() {
return url;
}
public String getUser() {
return user;
}
@ -57,4 +58,17 @@ public class CatalogueInstanceDescriptor {
return this;
}
public CatalogueInstanceDescriptor setUrl(String url) {
this.url = url;
return this;
}
@Override
public String toString() {
return "CatalogueInstanceDescriptor [url=" + url + ", user=" + user + ", password=" + password
+ ", customToken=" + customToken + ", headersParameters=" + headersParameters + "]";
}
}

View File

@ -61,7 +61,7 @@ public class GCatController implements CatalogueController{
try {
builder= factory.newDocumentBuilder();
expr= xpath.compile("");
expr= xpath.compile("string(/bookstore/book/title/@lang)");
} catch (ParserConfigurationException | XPathExpressionException e) {
throw new RuntimeException("Unable to initialize Controller");
}

View File

@ -1,15 +1,99 @@
package org.gcube.data.publishing.gCatFeeder.catalogues.gCat;
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;
import org.gcube.data.publishing.gCatFeeder.tests.TokenSetter;
import org.gcube.data.publishing.gCatFeeder.utils.TokenUtils;
import org.gcube.data.publishing.gCataFeeder.catalogues.gCat.GCatPlugin;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class Interactions {
@Before
private void setToken() {
TokenSetter.set("/gcube/devsec");
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);
}
}
}
@Before
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");
}
@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));
}
}