Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-file-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Environments
Terraform modules
Monitor
Incidents
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-file-service
Commits
071f849d
Commit
071f849d
authored
3 years ago
by
Nicola Fulvio Calabria
Browse files
Options
Downloads
Patches
Plain Diff
Test fix
parent
16ff8bff
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/it/inaf/ia2/transfer/service/ArchiveServiceTest.java
+22
-14
22 additions, 14 deletions
...java/it/inaf/ia2/transfer/service/ArchiveServiceTest.java
with
22 additions
and
14 deletions
src/test/java/it/inaf/ia2/transfer/service/ArchiveServiceTest.java
+
22
−
14
View file @
071f849d
...
...
@@ -11,6 +11,7 @@ import it.inaf.ia2.transfer.persistence.JobDAO;
import
it.inaf.ia2.transfer.persistence.LocationDAO
;
import
it.inaf.ia2.transfer.persistence.model.FileInfo
;
import
it.inaf.oats.vospace.exception.QuotaExceededException
;
import
it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -38,6 +39,7 @@ import org.kamranzafar.jtar.TarEntry;
import
org.kamranzafar.jtar.TarInputStream
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
org.mockito.Mockito
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -47,6 +49,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.test.context.ContextConfiguration
;
...
...
@@ -70,9 +73,6 @@ public class ArchiveServiceTest {
@MockBean
private
RestTemplate
restTemplate
;
@MockBean
private
HttpServletRequest
servletRequest
;
@MockBean
private
AuthorizationService
authorizationService
;
...
...
@@ -93,7 +93,6 @@ public class ArchiveServiceTest {
}
// TODO: refactor tests
/*
@Test
public
void
testTarGeneration
()
throws
Exception
{
...
...
@@ -115,7 +114,6 @@ public class ArchiveServiceTest {
});
}
@Test
public
void
testZipGeneration
()
throws
Exception
{
...
...
@@ -137,7 +135,6 @@ public class ArchiveServiceTest {
});
}
@Test
public
void
testArchiveQuotaExceeded
()
throws
Exception
{
...
...
@@ -145,8 +142,10 @@ public class ArchiveServiceTest {
job
.
setPrincipal
(
new
TokenPrincipal
(
"user2"
,
"token2"
));
job
.
setJobId
(
"job2"
);
job
.
setType
(
ArchiveJob
.
Type
.
ZIP
);
job.setVosPaths(Arrays.asList("/ignore"));
job
.
setEntryDescriptors
(
List
.
of
(
this
.
getArchiveEntryDescriptor
(
"/ignore"
)));
HttpServletRequest
servletRequest
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
when
(
servletRequest
.
getUserPrincipal
()).
thenReturn
(
job
.
getPrincipal
());
File
user2Dir
=
tmpDir
.
toPath
().
resolve
(
"user2"
).
toFile
();
...
...
@@ -165,7 +164,7 @@ public class ArchiveServiceTest {
archiveService
.
createArchive
(
job
,
servletRequest
);
});
}
private
static
abstract
class
TestArchiveHandler
<
I
extends
InputStream
,
E
>
{
private
final
I
is
;
...
...
@@ -202,8 +201,14 @@ public class ArchiveServiceTest {
job
.
setPrincipal
(
new
TokenPrincipal
(
"user1"
,
"token1"
));
job
.
setJobId
(
"abcdef"
);
job
.
setType
(
type
);
job.setVosPaths(Arrays.asList(parent + "/dir1", parent + "/dir2", parent + "/file6"));
job
.
setEntryDescriptors
(
List
.
of
(
this
.
getArchiveEntryDescriptor
(
parent
+
"/dir1"
),
this
.
getArchiveEntryDescriptor
(
parent
+
"/dir2"
),
this
.
getArchiveEntryDescriptor
(
parent
+
"/file6"
)
));
HttpServletRequest
servletRequest
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
when
(
servletRequest
.
getUserPrincipal
()).
thenReturn
(
job
.
getPrincipal
());
when
(
authorizationService
.
isDownloadable
(
any
(),
any
())).
thenReturn
(
true
);
...
...
@@ -251,7 +256,7 @@ public class ArchiveServiceTest {
TestArchiveHandler
<
I
,
E
>
testArchiveHandler
=
testArchiveGetter
.
apply
(
new
FileInputStream
(
result
));
try (
InputStream is = testArchiveHandler.getInputStream()) {
try
(
InputStream
is
=
testArchiveHandler
.
getInputStream
())
{
E
entry
;
while
((
entry
=
testArchiveHandler
.
getNextEntry
())
!=
null
)
{
assertFalse
(
i
>=
expectedSequence
.
size
(),
"Found more entries than in expected sequence"
);
...
...
@@ -288,12 +293,15 @@ public class ArchiveServiceTest {
private
File
createFile
(
File
parent
,
String
path
)
throws
Exception
{
File
file
=
parent
.
toPath
().
resolve
(
path
).
toFile
();
file.getParentFile().mkdirs();
file
.
getParentFile
().
mkdirs
();
file
.
createNewFile
();
Files
.
write
(
file
.
toPath
(),
"some data"
.
getBytes
());
return
file
;
}
*/
private
ArchiveEntryDescriptor
getArchiveEntryDescriptor
(
String
vosPath
)
{
return
new
ArchiveEntryDescriptor
(
vosPath
);
}
/**
* @TestPropertySource annotation can't be used in this test because we need
...
...
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