diff --git a/src/main/java/net/ivoa/xml/vospace/v2/Transfer.java b/src/main/java/net/ivoa/xml/vospace/v2/Transfer.java index 63e2216449058bbd0d67383bac41c9e24e5232c8..d85c6ad3ca0467473206c7870152932ebbff6d91 100644 --- a/src/main/java/net/ivoa/xml/vospace/v2/Transfer.java +++ b/src/main/java/net/ivoa/xml/vospace/v2/Transfer.java @@ -19,6 +19,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlType; @@ -82,9 +83,12 @@ import javax.xml.bind.annotation.XmlType; // </edit> public class Transfer { - @XmlElement(required = true) + @XmlElements({ + @XmlElement(required = true) + }) @XmlSchemaType(name = "anyURI") - protected String target; + private List<String> target; + protected String direction; protected View view; @XmlElement(name = "protocol") @@ -106,7 +110,7 @@ public class Transfer { * {@link String } * */ - public String getTarget() { + public List<String> getTarget() { return target; } @@ -118,7 +122,7 @@ public class Transfer { * {@link String } * */ - public void setTarget(String value) { + public void setTarget(List<String> value) { this.target = value; } diff --git a/src/test/java/net/ivoa/xml/uws/v1/JobSummaryTest.java b/src/test/java/net/ivoa/xml/uws/v1/JobSummaryTest.java index bac05d194d1e85b9e064b568e8787a8907a2b0d8..6d87f6f6d97225ce23096463e4e3fbf180d8212c 100644 --- a/src/test/java/net/ivoa/xml/uws/v1/JobSummaryTest.java +++ b/src/test/java/net/ivoa/xml/uws/v1/JobSummaryTest.java @@ -8,6 +8,7 @@ package net.ivoa.xml.uws.v1; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.StringReader; import java.io.StringWriter; +import java.util.Arrays; import javax.xml.bind.JAXB; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; @@ -62,7 +63,7 @@ public class JobSummaryTest { */ @Test public void testDeserializeTransferServiceResponse() throws Exception { - String response = "{\"jobId\": \"917c784f814c4a1a91a9d5d1af07dbe9\", \"ownerId\": \"2386\", \"jobType\": \"pullToVoSpace\", \"phase\": \"PENDING\", \"startTime\": null, \"endTime\": null, \"creationTime\": \"2021-02-03T15:05:57.233602\", \"jobInfo\": {\"transfer\": {\"view\": null, \"target\": \"vos://example.com!vospace/szorba/aaa\", \"version\": null, \"direction\": \"pullToVoSpace\", \"keepBytes\": null, \"protocols\": [{\"uri\": \"ia2:async-recall\", \"param\": [{\"uri\": \"ia2:node-type\", \"value\": \"single\"}], \"endpoint\": null}]}}, \"results\": null}"; + String response = "{\"jobId\": \"917c784f814c4a1a91a9d5d1af07dbe9\", \"ownerId\": \"2386\", \"jobType\": \"pullToVoSpace\", \"phase\": \"PENDING\", \"startTime\": null, \"endTime\": null, \"creationTime\": \"2021-02-03T15:05:57.233602\", \"jobInfo\": {\"transfer\": {\"view\": null, \"target\": [\"vos://example.com!vospace/szorba/aaa\"], \"version\": null, \"direction\": \"pullToVoSpace\", \"keepBytes\": null, \"protocols\": [{\"uri\": \"ia2:async-recall\", \"endpoint\": null}]}}, \"results\": null}"; MAPPER.readValue(response, JobSummary.class); } @@ -77,7 +78,7 @@ public class JobSummaryTest { Transfer transfer = new Transfer(); transfer.setVersion("2.1"); - transfer.setTarget("vos://example.com!vospace/mydata1"); + transfer.setTarget(Arrays.asList("vos://example.com!vospace/mydata1")); transfer.setDirection("pullFromVoSpace"); Protocol protocol1 = new Protocol(); protocol1.setUri("ivo://ivoa.net/vospace/core#httpget"); @@ -109,7 +110,7 @@ public class JobSummaryTest { Transfer transfer = (Transfer) deserializedJob.getJobInfo().getAny().get(0); assertEquals("2.1", transfer.getVersion()); assertEquals("pullFromVoSpace", transfer.getDirection()); - assertEquals("vos://example.com!vospace/mydata1", transfer.getTarget()); + assertArrayEquals(new String[]{"vos://example.com!vospace/mydata1"}, transfer.getTarget().toArray(String[]::new)); Protocol protocol = transfer.getProtocols().get(0); assertEquals("ivo://ivoa.net/vospace/core#httpget", protocol.getUri()); diff --git a/src/test/java/net/ivoa/xml/vospace/v2/TransferTest.java b/src/test/java/net/ivoa/xml/vospace/v2/TransferTest.java index b0932553690ed8f18df23f0ba6ab274c564db3a5..4f4af5187ccba4af1e05d173eabacddbefffa83b 100644 --- a/src/test/java/net/ivoa/xml/vospace/v2/TransferTest.java +++ b/src/test/java/net/ivoa/xml/vospace/v2/TransferTest.java @@ -9,8 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.inaf.oats.vospace.datamodel.NodeProperties; import java.io.StringReader; import java.io.StringWriter; +import java.util.Arrays; import javax.xml.bind.JAXB; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class TransferTest { @@ -20,15 +23,31 @@ public class TransferTest { private static final String URI_PREFIX = "vos://example.com!vospace"; @Test - public void testXmlSerialization() throws Exception { + public void testSingleTarget() throws Exception { - Transfer transfer = getTransfer(); + Transfer transfer = getBaseTransfer(); + transfer.setTarget(Arrays.asList(URI_PREFIX + "/mynode")); + + testXmlSerialization(transfer); + } + + @Test + public void testMultipleTargets() throws Exception { + + Transfer transfer = getBaseTransfer(); + transfer.setTarget(Arrays.asList(URI_PREFIX + "/mynode1", URI_PREFIX + "/mynode2")); + + testXmlSerialization(transfer); + } + + private void testXmlSerialization(Transfer transfer) throws Exception { String xml; try ( StringWriter sw = new StringWriter()) { JAXB.marshal(transfer, sw); xml = sw.toString(); System.out.println(xml); + assertTrue(xml.contains("<vos:transfer")); } Transfer deserialized; @@ -39,22 +58,21 @@ public class TransferTest { verifyTransfersAreEquals(transfer, deserialized); } - private Transfer getTransfer() { - Transfer transfer = new Transfer(); + private Transfer getBaseTransfer() { - transfer.setTarget(URI_PREFIX + "/mynode"); - transfer.setDirection("pullFromVoSpace"); + Transfer transfer = new Transfer(); + transfer.setDirection("pullFromVoSpace"); Protocol protocol = new Protocol(); protocol.setUri("ivo://ivoa.net/vospace/core#httpget"); protocol.setEndpoint("http://ia2.inaf.it/data?param1=value1¶m2=value2"); transfer.getProtocols().add(protocol); - + Param groupWriteParam = new Param(); groupWriteParam.setUri(NodeProperties.GROUP_WRITE_URI); groupWriteParam.setValue("group1 group2"); - + transfer.getParam().add(groupWriteParam); return transfer; @@ -62,7 +80,7 @@ public class TransferTest { private void verifyTransfersAreEquals(Transfer serialized, Transfer deserialized) { - assertEquals(serialized.getTarget(), deserialized.getTarget()); + assertArrayEquals(serialized.getTarget().toArray(String[]::new), deserialized.getTarget().toArray(String[]::new)); assertEquals(serialized.getDirection(), deserialized.getDirection()); assertEquals(serialized.getProtocols().size(), deserialized.getProtocols().size()); assertEquals(serialized.getParam().size(), deserialized.getParam().size());