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
4186e759
Commit
4186e759
authored
3 years ago
by
nfcalabria
Browse files
Options
Downloads
Patches
Plain Diff
Fixed PutFileControllerTest
parent
5aba6ce0
No related branches found
Branches containing commit
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/controller/PutFileControllerTest.java
+10
-67
10 additions, 67 deletions
...t/inaf/ia2/transfer/controller/PutFileControllerTest.java
with
10 additions
and
67 deletions
src/test/java/it/inaf/ia2/transfer/controller/PutFileControllerTest.java
+
10
−
67
View file @
4186e759
...
...
@@ -80,7 +80,7 @@ public class PutFileControllerTest {
when
(
fileDao
.
getRemainingQuota
(
any
())).
thenReturn
(
null
);
String
randomFileName
=
UUID
.
randomUUID
().
toString
();
createBaseFileInfo
(
randomFileName
);
FileInfo
fileInfo
=
createBaseFileInfo
(
randomFileName
);
MockMultipartFile
fakeFile
=
new
MockMultipartFile
(
"file"
,
"test.txt"
,
"text/plain"
,
"content"
.
getBytes
());
...
...
@@ -89,72 +89,17 @@ public class PutFileControllerTest {
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
File
file
=
Path
.
of
(
getTestFilePath
(
randomFileName
)).
toFile
();
File
file
=
Path
.
of
(
fileInfo
.
getFilePath
(
)).
toFile
();
assertTrue
(
file
.
exists
());
assertEquals
(
"content"
,
Files
.
contentOf
(
file
,
StandardCharsets
.
UTF_8
));
// TODO: refactor test
// verify(fileDao, times(1)).updateFileAttributes(anyInt(), eq("text/plain"), any(), eq(7l), eq("9A0364B9E99BB480DD25E1F0284C8555"));
verify
(
fileDao
,
times
(
1
)).
updateFileAttributes
(
anyInt
(),
any
(),
eq
(
"text/plain"
),
any
(),
eq
(
7
l
),
eq
(
"9A0364B9E99BB480DD25E1F0284C8555"
));
assertTrue
(
file
.
delete
());
}
@Test
public
void
putGenericFileWithNameConflictExtension
()
throws
Exception
{
putGenericFileWithNameConflict
(
"test.txt"
,
"test-1.txt"
,
"test-2.txt"
);
}
@Test
public
void
putGenericFileWithNameConflictNoExtension
()
throws
Exception
{
putGenericFileWithNameConflict
(
"test"
,
"test-1"
,
"test-2"
);
}
private
void
putGenericFileWithNameConflict
(
String
name1
,
String
name2
,
String
name3
)
throws
Exception
{
when
(
fileDao
.
getRemainingQuota
(
any
())).
thenReturn
(
null
);
createBaseFileInfo
(
name1
);
MockMultipartFile
fakeFile
=
new
MockMultipartFile
(
"file"
,
"test.txt"
,
"text/plain"
,
"content"
.
getBytes
());
mockMvc
.
perform
(
putMultipart
(
"/path/to/test.txt"
)
.
file
(
fakeFile
))
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
File
file
=
Path
.
of
(
getTestFilePath
(
name1
)).
toFile
();
assertTrue
(
file
.
exists
());
assertEquals
(
"content"
,
Files
.
contentOf
(
file
,
StandardCharsets
.
UTF_8
));
MockMultipartFile
fakeFile2
=
new
MockMultipartFile
(
"file"
,
"test.txt"
,
"text/plain"
,
"content2"
.
getBytes
());
mockMvc
.
perform
(
putMultipart
(
"/path/to/test.txt"
)
.
file
(
fakeFile2
))
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
File
file2
=
Path
.
of
(
getTestFilePath
(
name2
)).
toFile
();
assertTrue
(
file2
.
exists
());
assertEquals
(
"content2"
,
Files
.
contentOf
(
file2
,
StandardCharsets
.
UTF_8
));
MockMultipartFile
fakeFile3
=
new
MockMultipartFile
(
"file"
,
"test.txt"
,
"text/plain"
,
"content3"
.
getBytes
());
mockMvc
.
perform
(
putMultipart
(
"/path/to/test.txt"
)
.
file
(
fakeFile3
))
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
File
file3
=
Path
.
of
(
getTestFilePath
(
name3
)).
toFile
();
assertTrue
(
file3
.
exists
());
assertEquals
(
"content3"
,
Files
.
contentOf
(
file3
,
StandardCharsets
.
UTF_8
));
assertTrue
(
file
.
delete
());
assertTrue
(
file2
.
delete
());
assertTrue
(
file3
.
delete
());
}
@Test
public
void
putGenericFileWithJobId
()
throws
Exception
{
...
...
@@ -164,7 +109,7 @@ public class PutFileControllerTest {
when
(
jobDAO
.
isJobExisting
(
"pippo5"
)).
thenReturn
(
true
);
String
randomFileName
=
UUID
.
randomUUID
().
toString
();
createBaseFileInfo
(
randomFileName
);
FileInfo
fileInfo
=
createBaseFileInfo
(
randomFileName
);
MockMultipartFile
fakeFile
=
new
MockMultipartFile
(
"file"
,
"test.txt"
,
"text/plain"
,
"content"
.
getBytes
());
...
...
@@ -185,13 +130,14 @@ public class PutFileControllerTest {
verify
(
jobDAO
,
times
(
1
)).
isJobExisting
(
eq
(
"pippo5"
));
verify
(
jobDAO
,
times
(
1
)).
updateJobPhase
(
eq
(
ExecutionPhase
.
COMPLETED
),
any
());
File
file
=
Path
.
of
(
getTestFilePath
(
randomFileName
)).
toFile
();
File
file
=
Path
.
of
(
fileInfo
.
getFilePath
(
)).
toFile
();
assertTrue
(
file
.
exists
());
assertEquals
(
"content"
,
Files
.
contentOf
(
file
,
StandardCharsets
.
UTF_8
));
assertTrue
(
file
.
delete
());
}
@Test
public
void
testPutFileWithoutNodeInDatabase
()
throws
Exception
{
...
...
@@ -203,6 +149,7 @@ public class PutFileControllerTest {
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
testPutWithInputStream
()
throws
Exception
{
...
...
@@ -212,7 +159,7 @@ public class PutFileControllerTest {
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
}
@Test
public
void
testJobError
()
throws
Exception
{
...
...
@@ -299,7 +246,7 @@ public class PutFileControllerTest {
private
FileInfo
createBaseFileInfo
(
String
fileName
)
{
FileInfo
fileInfo
=
new
FileInfo
();
fileInfo
.
set
OsPath
(
getTestFilePath
(
fileName
));
fileInfo
.
set
ActualBasePath
(
temporaryDirectory
.
getAbsolutePath
(
));
fileInfo
.
setVirtualPath
(
"/path/to/"
+
fileName
);
fileInfo
.
setPublic
(
false
);
...
...
@@ -309,10 +256,6 @@ public class PutFileControllerTest {
return
fileInfo
;
}
private
String
getTestFilePath
(
String
fileName
)
{
return
temporaryDirectory
.
toPath
().
resolve
(
"subdir"
).
resolve
(
fileName
).
toFile
().
getAbsolutePath
();
}
private
MockMultipartHttpServletRequestBuilder
putMultipart
(
String
uri
)
{
MockMultipartHttpServletRequestBuilder
builder
=
MockMvcRequestBuilders
.
multipart
(
uri
);
builder
.
with
(
new
RequestPostProcessor
()
{
...
...
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