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;
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;
}
......
......@@ -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());
......
......@@ -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&param2=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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment