Skip to content
Snippets Groups Projects
Commit b4dc6856 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Used List<String> instead of String for Transfer target field

parent d85ade80
No related branches found
No related tags found
No related merge requests found
Pipeline #1970 passed
...@@ -19,6 +19,7 @@ import javax.xml.bind.annotation.XmlAccessType; ...@@ -19,6 +19,7 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
...@@ -82,9 +83,12 @@ import javax.xml.bind.annotation.XmlType; ...@@ -82,9 +83,12 @@ import javax.xml.bind.annotation.XmlType;
// </edit> // </edit>
public class Transfer { public class Transfer {
@XmlElements({
@XmlElement(required = true) @XmlElement(required = true)
})
@XmlSchemaType(name = "anyURI") @XmlSchemaType(name = "anyURI")
protected String target; private List<String> target;
protected String direction; protected String direction;
protected View view; protected View view;
@XmlElement(name = "protocol") @XmlElement(name = "protocol")
...@@ -106,7 +110,7 @@ public class Transfer { ...@@ -106,7 +110,7 @@ public class Transfer {
* {@link String } * {@link String }
* *
*/ */
public String getTarget() { public List<String> getTarget() {
return target; return target;
} }
...@@ -118,7 +122,7 @@ public class Transfer { ...@@ -118,7 +122,7 @@ public class Transfer {
* {@link String } * {@link String }
* *
*/ */
public void setTarget(String value) { public void setTarget(List<String> value) {
this.target = value; this.target = value;
} }
......
...@@ -8,6 +8,7 @@ package net.ivoa.xml.uws.v1; ...@@ -8,6 +8,7 @@ package net.ivoa.xml.uws.v1;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Arrays;
import javax.xml.bind.JAXB; import javax.xml.bind.JAXB;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.DatatypeFactory;
...@@ -62,7 +63,7 @@ public class JobSummaryTest { ...@@ -62,7 +63,7 @@ public class JobSummaryTest {
*/ */
@Test @Test
public void testDeserializeTransferServiceResponse() throws Exception { 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); MAPPER.readValue(response, JobSummary.class);
} }
...@@ -77,7 +78,7 @@ public class JobSummaryTest { ...@@ -77,7 +78,7 @@ public class JobSummaryTest {
Transfer transfer = new Transfer(); Transfer transfer = new Transfer();
transfer.setVersion("2.1"); transfer.setVersion("2.1");
transfer.setTarget("vos://example.com!vospace/mydata1"); transfer.setTarget(Arrays.asList("vos://example.com!vospace/mydata1"));
transfer.setDirection("pullFromVoSpace"); transfer.setDirection("pullFromVoSpace");
Protocol protocol1 = new Protocol(); Protocol protocol1 = new Protocol();
protocol1.setUri("ivo://ivoa.net/vospace/core#httpget"); protocol1.setUri("ivo://ivoa.net/vospace/core#httpget");
...@@ -109,7 +110,7 @@ public class JobSummaryTest { ...@@ -109,7 +110,7 @@ public class JobSummaryTest {
Transfer transfer = (Transfer) deserializedJob.getJobInfo().getAny().get(0); Transfer transfer = (Transfer) deserializedJob.getJobInfo().getAny().get(0);
assertEquals("2.1", transfer.getVersion()); assertEquals("2.1", transfer.getVersion());
assertEquals("pullFromVoSpace", transfer.getDirection()); 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); Protocol protocol = transfer.getProtocols().get(0);
assertEquals("ivo://ivoa.net/vospace/core#httpget", protocol.getUri()); assertEquals("ivo://ivoa.net/vospace/core#httpget", protocol.getUri());
......
...@@ -9,8 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -9,8 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeProperties;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Arrays;
import javax.xml.bind.JAXB; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class TransferTest { public class TransferTest {
...@@ -20,15 +23,31 @@ public class TransferTest { ...@@ -20,15 +23,31 @@ public class TransferTest {
private static final String URI_PREFIX = "vos://example.com!vospace"; private static final String URI_PREFIX = "vos://example.com!vospace";
@Test @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; String xml;
try ( StringWriter sw = new StringWriter()) { try ( StringWriter sw = new StringWriter()) {
JAXB.marshal(transfer, sw); JAXB.marshal(transfer, sw);
xml = sw.toString(); xml = sw.toString();
System.out.println(xml); System.out.println(xml);
assertTrue(xml.contains("<vos:transfer"));
} }
Transfer deserialized; Transfer deserialized;
...@@ -39,10 +58,9 @@ public class TransferTest { ...@@ -39,10 +58,9 @@ public class TransferTest {
verifyTransfersAreEquals(transfer, deserialized); verifyTransfersAreEquals(transfer, deserialized);
} }
private Transfer getTransfer() { private Transfer getBaseTransfer() {
Transfer transfer = new Transfer();
transfer.setTarget(URI_PREFIX + "/mynode"); Transfer transfer = new Transfer();
transfer.setDirection("pullFromVoSpace"); transfer.setDirection("pullFromVoSpace");
Protocol protocol = new Protocol(); Protocol protocol = new Protocol();
...@@ -62,7 +80,7 @@ public class TransferTest { ...@@ -62,7 +80,7 @@ public class TransferTest {
private void verifyTransfersAreEquals(Transfer serialized, Transfer deserialized) { 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.getDirection(), deserialized.getDirection());
assertEquals(serialized.getProtocols().size(), deserialized.getProtocols().size()); assertEquals(serialized.getProtocols().size(), deserialized.getProtocols().size());
assertEquals(serialized.getParam().size(), deserialized.getParam().size()); assertEquals(serialized.getParam().size(), deserialized.getParam().size());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment