Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-rest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VOSpace INAF
vospace-rest
Commits
728d2057
Commit
728d2057
authored
3 years ago
by
Sonia Zorba
Browse files
Options
Downloads
Patches
Plain Diff
Fixed issue in paths of tar/zip archive requests
parent
bc75a9c1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/it/inaf/oats/vospace/FileServiceClient.java
+4
-3
4 additions, 3 deletions
src/main/java/it/inaf/oats/vospace/FileServiceClient.java
src/test/java/it/inaf/oats/vospace/FileServiceClientTest.java
+25
-4
25 additions, 4 deletions
...test/java/it/inaf/oats/vospace/FileServiceClientTest.java
with
29 additions
and
7 deletions
src/main/java/it/inaf/oats/vospace/FileServiceClient.java
+
4
−
3
View file @
728d2057
...
@@ -45,7 +45,8 @@ public class FileServiceClient {
...
@@ -45,7 +45,8 @@ public class FileServiceClient {
throw
new
IllegalArgumentException
(
"Target size is "
+
transfer
.
getTarget
().
size
());
throw
new
IllegalArgumentException
(
"Target size is "
+
transfer
.
getTarget
().
size
());
}
}
String
target
=
transfer
.
getTarget
().
get
(
0
);
String
target
=
transfer
.
getTarget
().
get
(
0
)
.
substring
(
"vos://"
.
length
()
+
authority
.
length
());
String
viewUri
=
transfer
.
getView
().
getUri
();
String
viewUri
=
transfer
.
getView
().
getUri
();
...
@@ -65,7 +66,7 @@ public class FileServiceClient {
...
@@ -65,7 +66,7 @@ public class FileServiceClient {
if
(
vosPaths
.
isEmpty
())
{
if
(
vosPaths
.
isEmpty
())
{
// Add target path
// Add target path
vosPaths
.
add
(
target
.
substring
(
"vos://"
.
length
()
+
authority
.
length
())
);
vosPaths
.
add
(
target
);
}
}
ArchiveRequest
archiveRequest
=
new
ArchiveRequest
();
ArchiveRequest
archiveRequest
=
new
ArchiveRequest
();
...
@@ -91,7 +92,7 @@ public class FileServiceClient {
...
@@ -91,7 +92,7 @@ public class FileServiceClient {
},
new
Object
[]{});
},
new
Object
[]{});
}
}
p
rivate
static
class
ArchiveRequest
{
p
ublic
static
class
ArchiveRequest
{
private
String
type
;
private
String
type
;
private
String
jobId
;
private
String
jobId
;
...
...
This diff is collapsed.
Click to expand it.
src/test/java/it/inaf/oats/vospace/FileServiceClientTest.java
+
25
−
4
View file @
728d2057
...
@@ -5,10 +5,14 @@
...
@@ -5,10 +5,14 @@
*/
*/
package
it.inaf.oats.vospace
;
package
it.inaf.oats.vospace
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
it.inaf.ia2.aa.data.User
;
import
it.inaf.ia2.aa.data.User
;
import
it.inaf.oats.vospace.FileServiceClient.ArchiveRequest
;
import
it.inaf.oats.vospace.datamodel.Views
;
import
it.inaf.oats.vospace.datamodel.Views
;
import
it.inaf.oats.vospace.exception.InvalidArgumentException
;
import
it.inaf.oats.vospace.exception.InvalidArgumentException
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.UncheckedIOException
;
import
java.net.URI
;
import
java.net.URI
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -44,6 +48,8 @@ import org.springframework.web.client.RestTemplate;
...
@@ -44,6 +48,8 @@ import org.springframework.web.client.RestTemplate;
@MockitoSettings
(
strictness
=
Strictness
.
LENIENT
)
@MockitoSettings
(
strictness
=
Strictness
.
LENIENT
)
public
class
FileServiceClientTest
{
public
class
FileServiceClientTest
{
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
@Mock
@Mock
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
...
@@ -88,7 +94,10 @@ public class FileServiceClientTest {
...
@@ -88,7 +94,10 @@ public class FileServiceClientTest {
view
.
setUri
(
Views
.
ZIP_VIEW_URI
);
view
.
setUri
(
Views
.
ZIP_VIEW_URI
);
transfer
.
setView
(
view
);
transfer
.
setView
(
view
);
testStartArchiveJob
(
transfer
);
ArchiveRequest
archiveRequest
=
testStartArchiveJob
(
transfer
);
assertEquals
(
1
,
archiveRequest
.
getPaths
().
size
());
assertEquals
(
"/mydir"
,
archiveRequest
.
getPaths
().
get
(
0
));
}
}
@Test
@Test
...
@@ -146,20 +155,26 @@ public class FileServiceClientTest {
...
@@ -146,20 +155,26 @@ public class FileServiceClientTest {
param2
.
setValue
(
"file2"
);
param2
.
setValue
(
"file2"
);
view
.
getParam
().
add
(
param2
);
view
.
getParam
().
add
(
param2
);
testStartArchiveJob
(
transfer
);
ArchiveRequest
archiveRequest
=
testStartArchiveJob
(
transfer
);
assertEquals
(
2
,
archiveRequest
.
getPaths
().
size
());
assertEquals
(
"/parent_dir/file1"
,
archiveRequest
.
getPaths
().
get
(
0
));
assertEquals
(
"/parent_dir/file2"
,
archiveRequest
.
getPaths
().
get
(
1
));
}
}
private
void
testStartArchiveJob
(
Transfer
transfer
)
{
private
ArchiveRequest
testStartArchiveJob
(
Transfer
transfer
)
{
User
user
=
mock
(
User
.
class
);
User
user
=
mock
(
User
.
class
);
when
(
user
.
getAccessToken
()).
thenReturn
(
"<token>"
);
when
(
user
.
getAccessToken
()).
thenReturn
(
"<token>"
);
when
(
request
.
getUserPrincipal
()).
thenReturn
(
user
);
when
(
request
.
getUserPrincipal
()).
thenReturn
(
user
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
doAnswer
(
invocation
->
{
doAnswer
(
invocation
->
{
RequestCallback
requestCallback
=
invocation
.
getArgument
(
2
);
RequestCallback
requestCallback
=
invocation
.
getArgument
(
2
);
ClientHttpRequest
mockedRequest
=
mock
(
ClientHttpRequest
.
class
);
ClientHttpRequest
mockedRequest
=
mock
(
ClientHttpRequest
.
class
);
HttpHeaders
mockedRequestHeaders
=
mock
(
HttpHeaders
.
class
);
HttpHeaders
mockedRequestHeaders
=
mock
(
HttpHeaders
.
class
);
when
(
mockedRequest
.
getBody
()).
thenReturn
(
new
ByteArrayOutputStream
()
);
when
(
mockedRequest
.
getBody
()).
thenReturn
(
baos
);
when
(
mockedRequest
.
getHeaders
()).
thenReturn
(
mockedRequestHeaders
);
when
(
mockedRequest
.
getHeaders
()).
thenReturn
(
mockedRequestHeaders
);
requestCallback
.
doWithRequest
(
mockedRequest
);
requestCallback
.
doWithRequest
(
mockedRequest
);
...
@@ -176,5 +191,11 @@ public class FileServiceClientTest {
...
@@ -176,5 +191,11 @@ public class FileServiceClientTest {
String
redirect
=
fileServiceClient
.
startArchiveJob
(
transfer
,
"job123"
);
String
redirect
=
fileServiceClient
.
startArchiveJob
(
transfer
,
"job123"
);
assertEquals
(
"http://file-service/archive/result"
,
redirect
);
assertEquals
(
"http://file-service/archive/result"
,
redirect
);
try
{
return
MAPPER
.
readValue
(
baos
.
toByteArray
(),
ArchiveRequest
.
class
);
}
catch
(
IOException
ex
)
{
throw
new
UncheckedIOException
(
ex
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment