Newer
Older
/*
* This file is part of vospace-rest
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import it.inaf.ia2.aa.ServletRapClient;
import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.UriService.ProtocolType;
import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.NodeUtils;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.exception.InternalFaultException;
Sonia Zorba
committed
import it.inaf.oats.vospace.exception.InvalidArgumentException;
Nicola Fulvio Calabria
committed
import it.inaf.oats.vospace.exception.NodeBusyException;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
Sonia Zorba
committed
import it.inaf.oats.vospace.exception.ProtocolNotSupportedException;
import it.inaf.oats.vospace.persistence.LinkedServiceDAO;
import it.inaf.oats.vospace.persistence.LocationDAO;
import it.inaf.oats.vospace.persistence.NodeDAO;
import it.inaf.oats.vospace.persistence.model.Location;
import it.inaf.oats.vospace.persistence.model.LocationType;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
Nicola Fulvio Calabria
committed
import net.ivoa.xml.vospace.v2.ContainerNode;
import net.ivoa.xml.vospace.v2.LinkNode;
Sonia Zorba
committed
import net.ivoa.xml.vospace.v2.Param;
import net.ivoa.xml.vospace.v2.Property;
Sonia Zorba
committed
import net.ivoa.xml.vospace.v2.Protocol;
import net.ivoa.xml.vospace.v2.View;
import static org.junit.jupiter.api.Assertions.assertEquals;
Nicola Fulvio Calabria
committed
import static org.junit.jupiter.api.Assertions.assertThrows;
Sonia Zorba
committed
import static org.junit.jupiter.api.Assertions.assertTrue;
Sonia Zorba
committed
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.BeforeEach;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Nicola Fulvio Calabria
committed
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.test.context.TestPropertySource;
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(properties = {"vospace-authority=example.com!vospace", "file-service-url=http://file-service"})
public class UriServiceTest {
@MockBean
@MockBean
private LocationDAO locationDAO;
Sonia Zorba
committed
@MockBean
private ServletRapClient rapClient;
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
@MockBean
private CreateNodeService createNodeService;
@MockBean
private LinkedServiceDAO linkedServiceDAO;
Sonia Zorba
committed
@MockBean
private FileServiceClient fileServiceClient;
@Autowired
private HttpServletRequest servletRequest;
private UriService uriService;
@TestConfiguration
public static class TestConfig {
/**
* Necessary because MockBean doesn't work with HttpServletRequest.
*/
@Bean
@Primary
public HttpServletRequest servletRequest() {
Sonia Zorba
committed
HttpServletRequest request = mock(HttpServletRequest.class);
User user = new User().setUserId("anonymous");
when(request.getUserPrincipal()).thenReturn(user);
return request;
public final static String PORTAL_URL = "http://portalurl.ia2.inaf.it/portal/files";
@BeforeEach
public void init() {
Location location = new Location();
location.setType(LocationType.ASYNC);
when(locationDAO.getNodeLocation(any())).thenReturn(Optional.of(location));
when(linkedServiceDAO.isLinkedServiceUrl(eq(PORTAL_URL))).thenReturn(Boolean.TRUE);
@Test
public void testPublicUrl() {
String dataUri = "vos://example.com!vospace/mydata1";
Node node = new DataNode();
node.setUri(dataUri);
Property property = new Property();
property.setUri(NodeProperties.PUBLIC_READ_URI);
property.setValue("true");
node.getProperties().add(property);
when(nodeDAO.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
JobSummary job = getJob();
Sonia Zorba
committed
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, uriService.getTransfer(job));
Sonia Zorba
committed
assertEquals("http://file-service/mydata1?jobId=job-id", negotiatedTransfer.getProtocols().get(0).getEndpoint());
public void testPrivateUrl() {
String dataUri = "vos://example.com!vospace/mydata1";
node.setUri(dataUri);
Nicola Fulvio Calabria
committed
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
node.getProperties().add(creator);
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1");
node.getProperties().add(readgroup);
when(nodeDAO.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
Nicola Fulvio Calabria
committed
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
when(rapClient.exchangeToken(argThat(req -> {
assertEquals("<token>", req.getSubjectToken());
assertEquals("http://file-service/mydata1", req.getResource());
return true;
}), any())).thenReturn("<new-token>");
JobSummary job = getJob();
Nicola Fulvio Calabria
committed
Transfer tr = uriService.getTransfer(job);
Sonia Zorba
committed
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, tr);
Sonia Zorba
committed
assertEquals("http://file-service/mydata1?jobId=job-id&token=<new-token>", negotiatedTransfer.getProtocols().get(0).getEndpoint());
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
@Test
public void testPrivateUrlPermissionDenied() {
String dataUri = "vos://example.com!vospace/mydata1";
Nicola Fulvio Calabria
committed
Node node = new DataNode();
node.setUri(dataUri);
Nicola Fulvio Calabria
committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user3");
node.getProperties().add(creator);
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1000");
node.getProperties().add(readgroup);
when(nodeDAO.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
when(rapClient.exchangeToken(argThat(req -> {
assertEquals("<token>", req.getSubjectToken());
assertEquals("http://file-service/mydata1", req.getResource());
return true;
}), any())).thenReturn("<new-token>");
JobSummary job = getJob();
Transfer tr = uriService.getTransfer(job);
Sonia Zorba
committed
assertThrows(PermissionDeniedException.class, () -> {
uriService.getNegotiatedTransfer(job, tr);
});
Nicola Fulvio Calabria
committed
}
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
@Test
public void testPrivateUrlNodeBusy() {
String dataUri = "vos://example.com!vospace/mydata1";
Nicola Fulvio Calabria
committed
DataNode node = new DataNode();
node.setUri(dataUri);
Nicola Fulvio Calabria
committed
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
node.getProperties().add(creator);
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1");
node.getProperties().add(readgroup);
Sonia Zorba
committed
node.setBusy(Boolean.TRUE);
Nicola Fulvio Calabria
committed
when(nodeDAO.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
when(rapClient.exchangeToken(argThat(req -> {
assertEquals("<token>", req.getSubjectToken());
assertEquals("http://file-service/mydata1", req.getResource());
return true;
}), any())).thenReturn("<new-token>");
JobSummary job = getJob();
Transfer tr = uriService.getTransfer(job);
Sonia Zorba
committed
assertThrows(NodeBusyException.class, () -> {
uriService.getNegotiatedTransfer(job, tr);
});
Nicola Fulvio Calabria
committed
}
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
@Test
public void pushToNonexistentNode() {
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
ContainerNode node = new ContainerNode();
node.setUri("vos://example.com!vospace/mydata1");
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
node.getProperties().add(creator);
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1");
node.getProperties().add(readgroup);
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
DataNode dnode = new DataNode();
dnode.setUri("vos://example.com!vospace/mydata1/mydata2");
dnode.getProperties().add(creator);
dnode.getProperties().add(readgroup);
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
Property writegroup = new Property();
writegroup.setUri(NodeProperties.GROUP_WRITE_URI);
writegroup.setValue("group1");
dnode.getProperties().add(writegroup);
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
when(nodeDAO.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
when(nodeDAO.listNode(eq("/mydata1/mydata2"))).thenReturn(Optional.empty());
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
when(user.getName()).thenReturn("user1");
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
when(servletRequest.getUserPrincipal()).thenReturn(user);
when(rapClient.exchangeToken(argThat(req -> {
assertEquals("<token>", req.getSubjectToken());
assertEquals("http://file-service/mydata1/mydata2", req.getResource());
return true;
}), any())).thenReturn("<new-token>");
JobSummary job = getPushToVoSpaceJob();
Transfer tr = uriService.getTransfer(job);
Sonia Zorba
committed
when(createNodeService.createNode(any(), any(), eq(user))).thenReturn(dnode);
Sonia Zorba
committed
Sonia Zorba
committed
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, tr);
Sonia Zorba
committed
verify(createNodeService, times(1)).createNode(any(), any(), eq(user));
Sonia Zorba
committed
Sonia Zorba
committed
assertEquals("http://file-service/mydata1/mydata2?jobId=job-id2&token=<new-token>", negotiatedTransfer.getProtocols().get(0).getEndpoint());
Nicola Fulvio Calabria
committed
}
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
@Test
public void pullFromLinkNode() {
// URI of pull target node
String targetOfPull = "vos://example.com!vospace/mylink1";
String targetOfLink = "vos://example.com!vospace/mydummydata1";
// Define node properties
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1");
// Define link node as target
LinkNode lnode = new LinkNode();
lnode.setUri(targetOfPull);
lnode.getProperties().add(creator);
lnode.getProperties().add(readgroup);
lnode.setTarget(targetOfLink);
DataNode dnode = new DataNode();
dnode.setUri(targetOfLink);
dnode.getProperties().add(creator);
dnode.getProperties().add(readgroup);
when(nodeDAO.listNode(eq(NodeUtils.getVosPath(lnode)))).thenReturn(Optional.of(lnode));
when(nodeDAO.listNode(eq(NodeUtils.getVosPath(dnode)))).thenReturn(Optional.of(dnode));
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
when(rapClient.exchangeToken(argThat(req -> {
assertEquals("<token>", req.getSubjectToken());
assertEquals("http://file-service/mydummydata1", req.getResource());
return true;
}), any())).thenReturn("<new-token>");
JobSummary job = getPullFromVoSpaceJob(targetOfPull);
Transfer tr = uriService.getTransfer(job);
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, tr);
assertEquals("http://file-service"
+ NodeUtils.getVosPath(dnode) +
"?jobId=job-id-pull&token=<new-token>",
negotiatedTransfer.getProtocols().get(0).getEndpoint());
}
@Test
public void pullFromCircularLinkNode() {
// URI of pull target node
String targetOfPull = "vos://example.com!vospace/mylink1";
String targetOfLink = "vos://example.com!vospace/mylink2";
// Define node properties
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
Property readgroup = new Property();
readgroup.setUri(NodeProperties.GROUP_READ_URI);
readgroup.setValue("group1");
// Define link node as target
LinkNode lnode = new LinkNode();
lnode.setUri(targetOfPull);
lnode.getProperties().add(creator);
lnode.getProperties().add(readgroup);
lnode.setTarget(targetOfLink);
LinkNode dnode = new LinkNode();
dnode.setUri(targetOfLink);
dnode.getProperties().add(creator);
dnode.getProperties().add(readgroup);
// Circular reference
dnode.setTarget(targetOfPull);
when(nodeDAO.listNode(eq(NodeUtils.getVosPath(lnode)))).thenReturn(Optional.of(lnode));
when(nodeDAO.listNode(eq(NodeUtils.getVosPath(dnode)))).thenReturn(Optional.of(dnode));
User user = mock(User.class);
when(user.getAccessToken()).thenReturn("<token>");
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
JobSummary job = getPullFromVoSpaceJob(targetOfPull);
Transfer tr = uriService.getTransfer(job);
assertThrows(InternalFaultException.class, () -> {
uriService.getNegotiatedTransfer(job, tr);
});
}
@Test
public void setNodeRemoteLocationTest() {
String nodeUri = "vos://example.com!vospace/test/f1/lbtfile.fits";
String contentUri = "http://archive.lbto.org/files/lbtfile.fits";
Location location = new Location();
location.setId(5);
when(locationDAO.findPortalLocation(eq("archive.lbto.org"))).thenReturn(Optional.of(location));
uriService.setNodeRemoteLocation(nodeUri, contentUri);
verify(nodeDAO).setNodeLocation(eq("/test/f1/lbtfile.fits"), eq(5), eq("lbtfile.fits"));
}
Sonia Zorba
committed
@Test
public void testSetSyncTransferEndpointsPullFromVoSpace() {
mockPublicNode();
Transfer transfer = new Transfer();
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1");
Sonia Zorba
committed
transfer.setDirection("pullFromVoSpace");
Protocol protocol1 = new Protocol();
protocol1.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocols().add(protocol1);
Protocol protocol2 = new Protocol();
protocol2.setUri("invalid_protocol");
transfer.getProtocols().add(protocol2);
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
assertEquals(2, transfer.getProtocols().size());
Sonia Zorba
committed
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
Sonia Zorba
committed
// invalid protocol is removed
Sonia Zorba
committed
assertEquals(1, negotiatedTransfer.getProtocols().size());
assertEquals("ivo://ivoa.net/vospace/core#httpget", negotiatedTransfer.getProtocols().get(0).getUri());
Sonia Zorba
committed
}
@Test
public void testSetSyncTransferEndpointsPushToVoSpace() {
Node node = mockPublicNode();
Property creator = new Property();
creator.setUri(NodeProperties.CREATOR_URI);
creator.setValue("user1");
node.getProperties().add(creator);
User user = mock(User.class);
when(user.getName()).thenReturn("user1");
when(servletRequest.getUserPrincipal()).thenReturn(user);
Transfer transfer = new Transfer();
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1");
Sonia Zorba
committed
transfer.setDirection("pushToVoSpace");
Protocol protocol1 = new Protocol();
protocol1.setUri("ivo://ivoa.net/vospace/core#httpput");
transfer.getProtocols().add(protocol1);
Protocol protocol2 = new Protocol();
protocol2.setUri("invalid_protocol");
transfer.getProtocols().add(protocol2);
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
assertEquals(2, transfer.getProtocols().size());
Sonia Zorba
committed
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
Sonia Zorba
committed
// invalid protocol is removed
Sonia Zorba
committed
assertEquals(1, negotiatedTransfer.getProtocols().size());
assertEquals("ivo://ivoa.net/vospace/core#httpput", negotiatedTransfer.getProtocols().get(0).getUri());
Sonia Zorba
committed
}
@Test
public void testSetSyncTransferEndpointsUnsupportedProtocol() {
Transfer transfer = new Transfer();
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1");
Sonia Zorba
committed
transfer.setDirection("pullFromVoSpace");
Protocol protocol = new Protocol();
protocol.setUri("invalid_protocol");
transfer.getProtocols().add(protocol);
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
try {
Sonia Zorba
committed
uriService.getNegotiatedTransfer(job, transfer);
Sonia Zorba
committed
fail("Expected ProtocolNotSupportedException");
} catch (ProtocolNotSupportedException ex) {
}
}
@Test
public void testSetSyncTransferEndpointsNoProtocols() {
Transfer transfer = new Transfer();
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1");
Sonia Zorba
committed
transfer.setDirection("pullFromVoSpace");
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
try {
Sonia Zorba
committed
uriService.getNegotiatedTransfer(job, transfer);
Sonia Zorba
committed
fail("Expected InvalidArgumentException");
} catch (InvalidArgumentException ex) {
}
}
@Test
public void testTarArchiveViewEndpoint() {
testArchiveViewEndpoint(Views.TAR_VIEW_URI);
}
@Test
public void testZipArchiveViewEndpoint() {
testArchiveViewEndpoint(Views.ZIP_VIEW_URI);
}
Sonia Zorba
committed
Sonia Zorba
committed
@Test
public void testInvalidTransferNoProtocols() {
Transfer transfer = new Transfer();
transfer.setDirection("pullFromVoSpace");
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/file1");
Sonia Zorba
committed
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
mockPublicNode("file1");
mockPublicNode("file2");
InvalidArgumentException ex = assertThrows(InvalidArgumentException.class, () -> {
uriService.getNegotiatedTransfer(job, transfer);
});
assertTrue(ex.getMessage().contains("no protocol"));
}
private void testArchiveViewEndpoint(String viewUri) {
Transfer transfer = new Transfer();
transfer.setDirection("pullFromVoSpace");
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/parent_dir");
Sonia Zorba
committed
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocols().add(protocol);
View view = new View();
view.setUri(viewUri);
Sonia Zorba
committed
Param param1 = new Param();
param1.setUri(viewUri + "/include");
param1.setValue("file1");
view.getParam().add(param1);
Param param2 = new Param();
param2.setUri(viewUri + "/include");
param2.setValue("file2");
view.getParam().add(param2);
transfer.setView(view);
JobSummary job = new JobSummary();
job.setJobId("archive-job-id");
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
Sonia Zorba
committed
mockPublicNode("parent_dir");
mockPublicNode("parent_dir/file1");
mockPublicNode("parent_dir/file2");
when(fileServiceClient.startArchiveJob(any(), any()))
.thenReturn("http://file-service/mockarchive");
Sonia Zorba
committed
uriService.getNegotiatedTransfer(job, transfer);
verify(fileServiceClient, times(1)).startArchiveJob(transfer, "archive-job-id");
}
Sonia Zorba
committed
private Node mockPublicNode() {
return mockPublicNode("mydata1");
}
private Node mockPublicNode(String name) {
Sonia Zorba
committed
DataNode node = new DataNode();
node.setUri("vos://example.com!vospace/" + name);
Sonia Zorba
committed
Property publicProperty = new Property();
publicProperty.setUri(NodeProperties.PUBLIC_READ_URI);
publicProperty.setValue(String.valueOf(true));
node.getProperties().add(publicProperty);
when(nodeDAO.listNode(eq("/" + name))).thenReturn(Optional.of(node));
Sonia Zorba
committed
return node;
}
Sonia Zorba
committed
private JobSummary getJob() {
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1");
transfer.setDirection(JobService.JobDirection.pullFromVoSpace.toString());
Sonia Zorba
committed
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocols().add(protocol);
JobSummary job = new JobSummary();
job.setJobId("job-id");
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
return job;
Sonia Zorba
committed
Nicola Fulvio Calabria
committed
private JobSummary getPushToVoSpaceJob() {
Transfer transfer = new Transfer();
Sonia Zorba
committed
transfer.setTarget("vos://example.com!vospace/mydata1/mydata2");
transfer.setDirection(JobService.JobDirection.pushToVoSpace.toString());
Sonia Zorba
committed
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpput");
transfer.getProtocols().add(protocol);
Nicola Fulvio Calabria
committed
JobSummary job = new JobSummary();
job.setJobId("job-id2");
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
Sonia Zorba
committed
return job;
Nicola Fulvio Calabria
committed
}
private JobSummary getPullFromVoSpaceJob(String target) {
Transfer transfer = new Transfer();
transfer.setTarget(target);
transfer.setDirection(JobService.JobDirection.pullFromVoSpace.toString());
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocols().add(protocol);
JobSummary job = new JobSummary();
job.setJobId("job-id-pull");
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
return job;
}
@Test
public void testProtocolType() {
List<ProtocolType> pts = List.of(ProtocolType.values());
int distinctUris =
pts.stream().map(pt -> pt.getUri()).distinct().collect(Collectors.toList()).size();
assertEquals(pts.size(), distinctUris);
}