283 lines
11 KiB
Java
283 lines
11 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.infrastructure.detachedres.detachedreslibrary;
|
|
|
|
import java.io.File;
|
|
import java.io.StringWriter;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.GregorianCalendar;
|
|
import java.util.LinkedHashMap;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
import javax.xml.bind.Marshaller;
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.DetachedREsJAXB;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.GatewayJAXB;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VOJAXB;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VREJAXB;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants;
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi
|
|
*
|
|
*
|
|
*/
|
|
public class DetachedREsTest extends TestCase {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(DetachedREsTest.class);
|
|
|
|
@Test
|
|
public void testDetachedREsResource() {
|
|
if (Constants.TEST_ENABLE) {
|
|
logger.debug("Test Enabled");
|
|
|
|
try {
|
|
DetachedREsClient detachedREsClient = new DetachedREsClient();
|
|
DetachedREs detachedREs = detachedREsClient.getDetachedREs();
|
|
logger.debug("DetachedREs: " + detachedREs);
|
|
assertTrue(true);
|
|
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
assertTrue("Error searching the resource!", false);
|
|
}
|
|
|
|
} else {
|
|
logger.debug("Test Disabled");
|
|
assertTrue(true);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testDetachedREsMarshaller() {
|
|
if (Constants.TEST_ENABLE) {
|
|
logger.debug("Test Enabled");
|
|
|
|
try {
|
|
logger.info("Check Marshalling");
|
|
|
|
GatewayJAXB blueBridgeGateway = new GatewayJAXB();
|
|
blueBridgeGateway.setScope("-1");
|
|
blueBridgeGateway.setName("BlueBridge Gateway");
|
|
|
|
VOJAXB gCubeApps = new VOJAXB();
|
|
gCubeApps.setScope("/d4science.research-infrastructures.eu/gCubeApps");
|
|
gCubeApps.setName("gCubeApps");
|
|
|
|
VREJAXB blueBridgeProject = new VREJAXB();
|
|
blueBridgeProject.setScope("/d4science.research-infrastructures.eu/gcubeApps/BlueBridgeProject");
|
|
blueBridgeProject.setName("BlueBridgeProject");
|
|
blueBridgeProject.setStartDate(new GregorianCalendar(2018, GregorianCalendar.FEBRUARY, 10).getTime());
|
|
blueBridgeProject.setEndDate(new GregorianCalendar(2020, GregorianCalendar.JANUARY, 1).getTime());
|
|
blueBridgeProject.setCatalogUrl("http://service.d4science.org/catalogurl");
|
|
blueBridgeProject
|
|
.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
|
|
|
|
LinkedHashMap<String, VREJAXB> vres = new LinkedHashMap<>();
|
|
vres.put("/d4science.research-infrastructures.eu/gcubeApps/BlueBridgeProject", blueBridgeProject);
|
|
gCubeApps.setVres(vres);
|
|
|
|
LinkedHashMap<String, VOJAXB> vos = new LinkedHashMap<>();
|
|
vos.put("/d4science.research-infrastructures.eu/gCubeApps", gCubeApps);
|
|
blueBridgeGateway.setVos(vos);
|
|
|
|
LinkedHashMap<String, GatewayJAXB> gateways = new LinkedHashMap<>();
|
|
gateways.put("-1", blueBridgeGateway);
|
|
|
|
DetachedREsJAXB detachedREs = new DetachedREsJAXB();
|
|
detachedREs.setEnabled(true);
|
|
detachedREs.setGateways(gateways);
|
|
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(DetachedREsJAXB.class);
|
|
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
|
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
|
|
// Print XML String to Console
|
|
StringWriter sw = new StringWriter();
|
|
|
|
// Write XML to StringWriter
|
|
jaxbMarshaller.marshal(detachedREs, sw);
|
|
|
|
// Verify XML Content
|
|
String xmlContent = sw.toString();
|
|
logger.debug(xmlContent);
|
|
|
|
logger.info("Check Unmarshalling");
|
|
Path path = Files.createTempFile("DetachedREsData", ".xml");
|
|
File file = path.toFile();
|
|
jaxbMarshaller.marshal(detachedREs, file);
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
DetachedREsJAXB configUnmarshalled = (DetachedREsJAXB) jaxbUnmarshaller.unmarshal(file);
|
|
logger.debug("DetachedREs unmarshallded: " + configUnmarshalled);
|
|
file.delete();
|
|
logger.info("Success!");
|
|
assertTrue(true);
|
|
|
|
} catch (Throwable e) {
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
assertTrue("Error in DetachedREs Marshal!", false);
|
|
}
|
|
} else {
|
|
logger.debug("Test Disabled");
|
|
assertTrue(true);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testDetachedREsMarshallerProd() {
|
|
if (Constants.TEST_ENABLE) {
|
|
logger.debug("Test Enabled");
|
|
|
|
try {
|
|
logger.info("Check Marshalling");
|
|
|
|
GatewayJAXB blueBridgeGateway = new GatewayJAXB();
|
|
blueBridgeGateway.setScope("-1");
|
|
blueBridgeGateway.setName("BlueBridge Gateway");
|
|
|
|
// gCubeApps
|
|
final String GCUBEAPPS = "gCubeApps";
|
|
VOJAXB gCubeApps = new VOJAXB();
|
|
gCubeApps.setScope("/d4science.research-infrastructures.eu/" + GCUBEAPPS);
|
|
gCubeApps.setName(GCUBEAPPS);
|
|
|
|
LinkedHashMap<String, VREJAXB> gCubeAppsVREs = new LinkedHashMap<>();
|
|
|
|
String[] gCubeAppsVREsArray = { "AquacultureTrainingLab", "BlueBRIDGE-PSC", "BlueBridgeProject",
|
|
"CES_TCRE", "ICES_DALSA", "ICES_DASC", "ICES_FIACO", "ICES_StockAssessmentAdvanced",
|
|
"ICES_TCSSM", "iSearch", "SIASPA" };
|
|
|
|
for (String vre : gCubeAppsVREsArray) {
|
|
VREJAXB gCubeAppsVREJAXB = new VREJAXB();
|
|
gCubeAppsVREJAXB.setScope("/d4science.research-infrastructures.eu/" + GCUBEAPPS + "/" + vre);
|
|
gCubeAppsVREJAXB.setName(new String(vre).replace("_", ""));
|
|
gCubeAppsVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime());
|
|
gCubeAppsVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime());
|
|
gCubeAppsVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/"+vre);
|
|
gCubeAppsVREJAXB
|
|
.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
|
|
gCubeAppsVREs.put("/d4science.research-infrastructures.eu/" + GCUBEAPPS + "/" + vre,
|
|
gCubeAppsVREJAXB);
|
|
}
|
|
gCubeApps.setVres(gCubeAppsVREs);
|
|
|
|
// FARM
|
|
final String FARM = "FARM";
|
|
VOJAXB farm = new VOJAXB();
|
|
farm.setScope("/d4science.research-infrastructures.eu/" + FARM);
|
|
farm.setName(FARM);
|
|
|
|
LinkedHashMap<String, VREJAXB> farmVREs = new LinkedHashMap<>();
|
|
|
|
String[] farmVREsArray = { "AlieiaVRE", "Aquabiotech", "ARDAG_Aquaculture", "EllinikaPsariaVRE",
|
|
"ForkysVRE", "GALAXIDI", "iLKNAK_Aquaculture", "KIMAGRO_Fishfarming", "MARKELLOS_Aquaculture",
|
|
"NHREUS_Aquaculture", "STRATOS_AQUACULTURES", "SustainableBlueEconomy", "TBTI_VRE" };
|
|
|
|
for (String vre : farmVREsArray) {
|
|
VREJAXB farmVREJAXB = new VREJAXB();
|
|
farmVREJAXB.setScope("/d4science.research-infrastructures.eu/" + FARM + "/" + vre);
|
|
farmVREJAXB.setName(new String(vre).replace("_", ""));
|
|
farmVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime());
|
|
farmVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime());
|
|
farmVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/"+vre);
|
|
farmVREJAXB
|
|
.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
|
|
farmVREs.put("/d4science.research-infrastructures.eu/" + FARM + "/" + vre, farmVREJAXB);
|
|
}
|
|
farm.setVres(farmVREs);
|
|
|
|
// D4Research
|
|
final String D4RESEARCH = "D4Research";
|
|
VOJAXB d4Research = new VOJAXB();
|
|
d4Research.setScope("/d4science.research-infrastructures.eu/" + D4RESEARCH);
|
|
|
|
d4Research.setName(D4RESEARCH);
|
|
|
|
LinkedHashMap<String, VREJAXB> d4ResearchVREs = new LinkedHashMap<>();
|
|
|
|
String[] d4ResearchVREsArray = { "Blue-Datathon", "BlueBRIDGEReview", "DRuMFISH",
|
|
"ICES_AbundanceEstimationFromAcoustic", "ICES_BNetworkAnalysis", "ICES_FIACO2017",
|
|
"ICES_IntroStockAssessment", "ICES_IntroToREnv", "ICES_LogbookData", "ICES_MSE", "ICES_MSY",
|
|
"InfraTraining" };
|
|
|
|
for (String vre : d4ResearchVREsArray) {
|
|
VREJAXB d4ResearchVREJAXB = new VREJAXB();
|
|
d4ResearchVREJAXB.setScope("/d4science.research-infrastructures.eu/" + D4RESEARCH + "/" + vre);
|
|
d4ResearchVREJAXB.setName(new String(vre).replace("_", ""));
|
|
d4ResearchVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime());
|
|
d4ResearchVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime());
|
|
d4ResearchVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/"+vre);
|
|
d4ResearchVREJAXB
|
|
.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
|
|
d4ResearchVREs.put("/d4science.research-infrastructures.eu/" + D4RESEARCH + "/" + vre,
|
|
d4ResearchVREJAXB);
|
|
}
|
|
d4Research.setVres(d4ResearchVREs);
|
|
|
|
// Gateway
|
|
LinkedHashMap<String, VOJAXB> vos = new LinkedHashMap<>();
|
|
vos.put("/d4science.research-infrastructures.eu/" + D4RESEARCH, d4Research);
|
|
vos.put("/d4science.research-infrastructures.eu/" + FARM, farm);
|
|
vos.put("/d4science.research-infrastructures.eu/" + GCUBEAPPS, gCubeApps);
|
|
|
|
blueBridgeGateway.setVos(vos);
|
|
|
|
LinkedHashMap<String, GatewayJAXB> gateways = new LinkedHashMap<>();
|
|
gateways.put("-1", blueBridgeGateway);
|
|
|
|
DetachedREsJAXB detachedREs = new DetachedREsJAXB();
|
|
detachedREs.setEnabled(true);
|
|
detachedREs.setGateways(gateways);
|
|
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(DetachedREsJAXB.class);
|
|
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
|
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
|
|
// Print XML String to Console
|
|
StringWriter sw = new StringWriter();
|
|
|
|
// Write XML to StringWriter
|
|
jaxbMarshaller.marshal(detachedREs, sw);
|
|
|
|
// Verify XML Content
|
|
String xmlContent = sw.toString();
|
|
logger.debug(xmlContent);
|
|
|
|
logger.info("Check Unmarshalling");
|
|
Path path = Files.createTempFile("DetachedREsData", ".xml");
|
|
File file = path.toFile();
|
|
jaxbMarshaller.marshal(detachedREs, file);
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
DetachedREsJAXB configUnmarshalled = (DetachedREsJAXB) jaxbUnmarshaller.unmarshal(file);
|
|
logger.debug("DetachedREs unmarshallded: " + configUnmarshalled);
|
|
file.delete();
|
|
logger.info("Success!");
|
|
assertTrue(true);
|
|
|
|
} catch (Throwable e) {
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
assertTrue("Error in DetachedREs Marshal!", false);
|
|
}
|
|
} else {
|
|
logger.debug("Test Disabled");
|
|
assertTrue(true);
|
|
}
|
|
}
|
|
|
|
}
|