Added test
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-api@119752 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
02302b0ae8
commit
e2d6156065
|
@ -3,7 +3,21 @@
|
|||
*/
|
||||
package org.gcube.vremanagement.executor.api.types;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.util.JAXBSource;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
|
@ -11,16 +25,45 @@ import org.junit.Test;
|
|||
*/
|
||||
public class LaunchParameterTest {
|
||||
|
||||
public static final String EVERY_FIVE_MINUTE_PATTERN = "5 * * * *";
|
||||
private static Logger logger = LoggerFactory.getLogger(LaunchParameterTest.class);
|
||||
|
||||
protected Marshaller createMarshaller(JAXBContext context) throws JAXBException{
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
|
||||
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedulingPattern(){
|
||||
/*
|
||||
SchedulingPattern schedulingPattern = new SchedulingPattern(EVERY_FIVE_MINUTE_PATTERN);
|
||||
Scheduling scheduling = new Scheduling(schedulingPattern);
|
||||
LaunchParameter launchParameter = new LaunchParameter("Test-Plugin", new HashMap<String, Object>(), scheduling);
|
||||
Assert.assertTrue(EVERY_FIVE_MINUTE_PATTERN.compareTo(launchParameter.getScheduling().getSchedulingPattern().toString())==0);
|
||||
Assert.assertTrue(launchParameter.getScheduling().getSchedulingTimes()==0);
|
||||
*/
|
||||
public void testSerialization() throws JAXBException {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put("Hello", "World");
|
||||
long sleepTime = 10000;
|
||||
inputs.put("sleepTime", sleepTime);
|
||||
Scheduling scheduling = new Scheduling(20);
|
||||
|
||||
LaunchParameter launchParameter = new LaunchParameter("HelloWorld", inputs, true, scheduling);
|
||||
logger.debug("{} to be serialized : {}", launchParameter.getClass().getSimpleName(), launchParameter);
|
||||
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance(LaunchParameter.class);
|
||||
JAXBElement<LaunchParameter> jaxbElement = new JAXBElement<LaunchParameter>(new QName("org.gcube"), LaunchParameter.class, launchParameter);
|
||||
JAXBSource source = new JAXBSource(context, jaxbElement);
|
||||
|
||||
Marshaller marshaller = createMarshaller(context);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
marshaller.marshal(jaxbElement, stringWriter);
|
||||
logger.debug("Marshalled {} : {}", launchParameter.getClass().getSimpleName(), stringWriter);
|
||||
|
||||
|
||||
|
||||
JAXBContext contextOut = JAXBContext.newInstance(LaunchParameter.class);
|
||||
Unmarshaller unmarshaller = contextOut.createUnmarshaller();
|
||||
JAXBElement<LaunchParameter> jaxbElementOut = unmarshaller.unmarshal(source, LaunchParameter.class);
|
||||
|
||||
|
||||
LaunchParameter launchParameterUnmarshalled = jaxbElementOut.getValue();
|
||||
logger.debug("Deserialized {} : {}", launchParameter.getClass().getSimpleName(), launchParameterUnmarshalled);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue