Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
file-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
file-service
Commits
886640a6
Commit
886640a6
authored
May 22, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加删除功能单元测试
parent
280410ec
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
0 deletions
+99
-0
DeleteController.java
...freight/file/module/file/controller/DeleteController.java
+7
-0
FileForm.java
.../java/com/esv/freight/file/module/file/form/FileForm.java
+7
-0
DeleteControllerTest.java
...ght/file/module/file/controller/DeleteControllerTest.java
+56
-0
UploadControllerTest.java
...ght/file/module/file/controller/UploadControllerTest.java
+29
-0
No files found.
src/main/java/com/esv/freight/file/module/file/controller/DeleteController.java
View file @
886640a6
...
@@ -32,6 +32,13 @@ public class DeleteController {
...
@@ -32,6 +32,13 @@ public class DeleteController {
this
.
fileMetaService
=
fileMetaService
;
this
.
fileMetaService
=
fileMetaService
;
}
}
/**
* description 删除单个文件
* param [fileForm]
* return com.esv.freight.file.common.response.EResponse
* author Administrator
* createTime 2020/05/22 9:26
**/
@PostMapping
(
"/single"
)
@PostMapping
(
"/single"
)
public
EResponse
deleteSingleFile
(
@RequestBody
@Validated
(
ValidatorDelete
.
class
)
FileForm
fileForm
)
throws
EException
{
public
EResponse
deleteSingleFile
(
@RequestBody
@Validated
(
ValidatorDelete
.
class
)
FileForm
fileForm
)
throws
EException
{
fileMetaService
.
deleteFile
(
fileForm
);
fileMetaService
.
deleteFile
(
fileForm
);
...
...
src/main/java/com/esv/freight/file/module/file/form/FileForm.java
View file @
886640a6
...
@@ -4,6 +4,8 @@ import com.esv.freight.file.common.validator.groups.ValidatorDelete;
...
@@ -4,6 +4,8 @@ import com.esv.freight.file.common.validator.groups.ValidatorDelete;
import
com.esv.freight.file.common.validator.groups.ValidatorDetail
;
import
com.esv.freight.file.common.validator.groups.ValidatorDetail
;
import
com.esv.freight.file.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.file.common.validator.groups.ValidatorInsert
;
import
lombok.Data
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotBlank
;
...
@@ -34,4 +36,9 @@ public class FileForm {
...
@@ -34,4 +36,9 @@ public class FileForm {
@Length
(
max
=
64
,
message
=
"参数id长度不合法"
,
groups
=
{
ValidatorDelete
.
class
,
ValidatorDetail
.
class
})
@Length
(
max
=
64
,
message
=
"参数id长度不合法"
,
groups
=
{
ValidatorDelete
.
class
,
ValidatorDetail
.
class
})
@NotBlank
(
message
=
"参数id不能为空"
,
groups
=
{
ValidatorDelete
.
class
,
ValidatorDetail
.
class
})
@NotBlank
(
message
=
"参数id不能为空"
,
groups
=
{
ValidatorDelete
.
class
,
ValidatorDetail
.
class
})
private
String
id
;
private
String
id
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
}
src/test/java/com/esv/freight/file/module/file/controller/DeleteControllerTest.java
0 → 100644
View file @
886640a6
package
com
.
esv
.
freight
.
file
.
module
.
file
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.file.BaseTestController
;
import
com.esv.freight.file.common.response.ECode
;
import
com.esv.freight.file.module.file.form.FileForm
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Assert
;
import
org.junit.FixMethodOrder
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.MethodSorters
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
org.springframework.test.web.servlet.result.MockMvcResultHandlers
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
/**
* @description:
* @project: freight-file-service
* @name: com.esv.freight.file.module.file.controller.DeleteControllerTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/22 9:25
* @version:1.0
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@Slf4j
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
DeleteControllerTest
extends
BaseTestController
{
@Test
public
void
a1_deleteSingleFile_success_test
()
throws
Exception
{
String
url
=
"/delete/single"
;
FileForm
form
=
new
FileForm
();
form
.
setId
(
"5ec6469a29c8560d78274b4b"
);
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
content
(
form
.
toString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
ECode
.
SUCCESS
.
code
(),
result
.
getIntValue
(
"code"
));
}
}
src/test/java/com/esv/freight/file/module/file/controller/UploadControllerTest.java
View file @
886640a6
...
@@ -100,6 +100,35 @@ public class UploadControllerTest extends BaseTestController {
...
@@ -100,6 +100,35 @@ public class UploadControllerTest extends BaseTestController {
fileUrl
=
result
.
getJSONObject
(
"data"
).
getString
(
"url"
);
fileUrl
=
result
.
getJSONObject
(
"data"
).
getString
(
"url"
);
}
}
@Test
public
void
a3_uploadSingleFile_word_success_test
()
throws
Exception
{
String
url
=
"/upload/single"
;
JSONObject
reqJson
=
new
JSONObject
();
// 构造数据
String
filepath
=
"D:\\test\\线上合同-货主.docx"
;
File
file
=
new
File
(
filepath
);
InputStream
input
=
new
FileInputStream
(
file
);
reqJson
.
put
(
"fileType"
,
"word"
);
reqJson
.
put
(
"fileData"
,
Base64
.
getEncoder
().
encodeToString
(
IOUtils
.
toByteArray
(
input
)));
reqJson
.
put
(
"fileName"
,
"线下合同-货主"
);
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
ECode
.
SUCCESS
.
code
(),
result
.
getIntValue
(
"code"
));
fileId
=
result
.
getJSONObject
(
"data"
).
getString
(
"id"
);
fileUrl
=
result
.
getJSONObject
(
"data"
).
getString
(
"url"
);
}
@Test
@Test
public
void
b1_uploadSingleFile_file_type_error_test
()
throws
Exception
{
public
void
b1_uploadSingleFile_file_type_error_test
()
throws
Exception
{
String
url
=
"/upload/single"
;
String
url
=
"/upload/single"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment