Commit 2f2268ea authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Renamed protocol to protocols in Transfer class. Added test class

parent 2785b8fb
...@@ -68,7 +68,7 @@ import javax.xml.bind.annotation.XmlType; ...@@ -68,7 +68,7 @@ import javax.xml.bind.annotation.XmlType;
"target", "target",
"direction", "direction",
"view", "view",
"protocol", "protocols",
"keepBytes" "keepBytes"
}) })
// <edit> // <edit>
...@@ -81,7 +81,8 @@ public class Transfer { ...@@ -81,7 +81,8 @@ public class Transfer {
protected String target; protected String target;
protected String direction; protected String direction;
protected View view; protected View view;
protected List<Protocol> protocol; @XmlElement(name = "protocol")
protected List<Protocol> protocols;
protected Boolean keepBytes; protected Boolean keepBytes;
// <edit> Fix: version is missing in VOSpace XSD // <edit> Fix: version is missing in VOSpace XSD
@XmlAttribute @XmlAttribute
...@@ -182,11 +183,11 @@ public class Transfer { ...@@ -182,11 +183,11 @@ public class Transfer {
* *
* *
*/ */
public List<Protocol> getProtocol() { public List<Protocol> getProtocols() {
if (protocol == null) { if (protocols == null) {
protocol = new ArrayList<Protocol>(); protocols = new ArrayList<>();
} }
return this.protocol; return this.protocols;
} }
/** /**
......
...@@ -65,9 +65,12 @@ public class JobSummaryTest { ...@@ -65,9 +65,12 @@ public class JobSummaryTest {
transfer.setVersion("2.1"); transfer.setVersion("2.1");
transfer.setTarget("vos://example.com!vospace/mydata1"); transfer.setTarget("vos://example.com!vospace/mydata1");
transfer.setDirection("pullFromVoSpace"); transfer.setDirection("pullFromVoSpace");
Protocol protocol = new Protocol(); Protocol protocol1 = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget"); protocol1.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocol().add(protocol); Protocol protocol2= new Protocol();
protocol2.setUri("ivo://ivoa.net/vospace/core#httpsget");
transfer.getProtocols().add(protocol1);
transfer.getProtocols().add(protocol2);
jobInfo.getAny().add(transfer); jobInfo.getAny().add(transfer);
...@@ -94,7 +97,7 @@ public class JobSummaryTest { ...@@ -94,7 +97,7 @@ public class JobSummaryTest {
assertEquals("pullFromVoSpace", transfer.getDirection()); assertEquals("pullFromVoSpace", transfer.getDirection());
assertEquals("vos://example.com!vospace/mydata1", transfer.getTarget()); assertEquals("vos://example.com!vospace/mydata1", transfer.getTarget());
Protocol protocol = transfer.getProtocol().get(0); Protocol protocol = transfer.getProtocols().get(0);
assertEquals("ivo://ivoa.net/vospace/core#httpget", protocol.getUri()); assertEquals("ivo://ivoa.net/vospace/core#httpget", protocol.getUri());
} }
} }
package net.ivoa.xml.vospace.v2;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXB;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class TransferTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String URI_PREFIX = "vos://example.com!vospace";
@Test
public void testXmlSerialization() throws Exception {
Transfer transfer = getTransfer();
String xml;
try ( StringWriter sw = new StringWriter()) {
JAXB.marshal(transfer, sw);
xml = sw.toString();
System.out.println(xml);
}
Transfer deserialized;
try ( StringReader sr = new StringReader(xml)) {
deserialized = JAXB.unmarshal(sr, Transfer.class);
}
verifyTransfersAreEquals(transfer, deserialized);
}
private Transfer getTransfer() {
Transfer transfer = new Transfer();
transfer.setTarget(URI_PREFIX + "/mynode");
transfer.setDirection("pullFromVoSpace");
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget");
protocol.setEndpoint("http://ia2.inaf.it/data?param1=value1&param2=value2");
transfer.getProtocols().add(protocol);
return transfer;
}
private void verifyTransfersAreEquals(Transfer serialized, Transfer deserialized) {
assertEquals(serialized.getTarget(), deserialized.getTarget());
assertEquals(serialized.getDirection(), deserialized.getDirection());
assertEquals(serialized.getProtocols().size(), deserialized.getProtocols().size());
assertEquals(serialized.getProtocols().get(0).getEndpoint(), deserialized.getProtocols().get(0).getEndpoint());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment