66
77package com .evolveum .midpoint .web .component ;
88
9- import org .apache .commons .fileupload2 .core .FileItem ;
10- import org .apache .commons .fileupload2 .core .FileItemHeaders ;
11- import org .apache .commons .fileupload2 .core .FileItemHeadersProvider ;
12- import org .apache .wicket .markup .html .form .upload .FileUpload ;
139import org .springframework .test .context .ActiveProfiles ;
1410import org .testng .annotations .Test ;
1511
16- import java .io .IOException ;
17- import java .io .InputStream ;
18- import java .io .OutputStream ;
19- import java .nio .charset .Charset ;
20- import java .nio .file .Path ;
21-
2212import static com .evolveum .midpoint .common .MimeTypeUtil .*;
2313
2414import com .evolveum .midpoint .web .component .input .validator .ContentTypeFileValidator ;
25- import com .evolveum .midpoint .web .component .input .validator .FileValidatorFactory ;
15+ import com .evolveum .midpoint .web .component .input .validator .FileValidatorUtil ;
2616
2717import static org .testng .Assert .assertEquals ;
2818
@@ -35,117 +25,25 @@ public class FileValidatorTest {
3525
3626 @ Test
3727 public void test4299ContentTypeFileValidator_validJPEG () throws Exception {
38- final FileUpload fu = new FileUpload (this .getFileItem (MIME_IMAGE_JPEG ));
3928 final ContentTypeFileValidator contentTypeFileValidator =
40- new ContentTypeFileValidator (FileValidatorFactory .getMimeTypes (FileValidatorFactory .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
41- final String deniedContentType = contentTypeFileValidator .validate (fu );
29+ new ContentTypeFileValidator (FileValidatorUtil .getMimeTypes (FileValidatorUtil .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
30+ final String deniedContentType = contentTypeFileValidator .validate (MIME_IMAGE_JPEG );
4231 assertEquals (deniedContentType , "" );
4332 }
4433
4534 @ Test
4635 public void test4299ContentTypeFileValidator_validPNG () throws Exception {
47- final FileUpload fu = new FileUpload (this .getFileItem (MIME_IMAGE_PNG ));
4836 final ContentTypeFileValidator contentTypeFileValidator =
49- new ContentTypeFileValidator (FileValidatorFactory .getMimeTypes (FileValidatorFactory .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
50- final String deniedContentType = contentTypeFileValidator .validate (fu );
37+ new ContentTypeFileValidator (FileValidatorUtil .getMimeTypes (FileValidatorUtil .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
38+ final String deniedContentType = contentTypeFileValidator .validate (MIME_IMAGE_PNG );
5139 assertEquals (deniedContentType , "" );
5240 }
5341
5442 @ Test
5543 public void test4299ContentTypeFileValidator_invalid () throws Exception {
56- final FileUpload fu = new FileUpload (this .getFileItem (MIME_APPLICATION_XML ));
5744 final ContentTypeFileValidator contentTypeFileValidator =
58- new ContentTypeFileValidator (FileValidatorFactory .getMimeTypes (FileValidatorFactory .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
59- final String deniedContentType = contentTypeFileValidator .validate (fu );
45+ new ContentTypeFileValidator (FileValidatorUtil .getMimeTypes (FileValidatorUtil .ALLOWED_UPLOAD_IMAGE_CONTENT_TYPES ));
46+ final String deniedContentType = contentTypeFileValidator .validate (MIME_APPLICATION_XML );
6047 assertEquals (deniedContentType , MIME_APPLICATION_XML );
6148 }
62-
63- private FileItem getFileItem (final String contentType ) {
64- return new FileItem () {
65- @ Override
66- public FileItem delete () throws IOException {
67- return null ;
68- }
69-
70- @ Override
71- public byte [] get () throws IOException {
72- return new byte [0 ];
73- }
74-
75- @ Override
76- public String getContentType () {
77- return contentType ;
78- }
79-
80- @ Override
81- public String getFieldName () {
82- return "" ;
83- }
84-
85- @ Override
86- public InputStream getInputStream () throws IOException {
87- return null ;
88- }
89-
90- @ Override
91- public String getName () {
92- return "" ;
93- }
94-
95- @ Override
96- public OutputStream getOutputStream () throws IOException {
97- return null ;
98- }
99-
100- @ Override
101- public long getSize () {
102- return 0 ;
103- }
104-
105- @ Override
106- public String getString () throws IOException {
107- return "" ;
108- }
109-
110- @ Override
111- public String getString (Charset charset ) throws IOException {
112- return "" ;
113- }
114-
115- @ Override
116- public boolean isFormField () {
117- return false ;
118- }
119-
120- @ Override
121- public boolean isInMemory () {
122- return false ;
123- }
124-
125- @ Override
126- public FileItem setFieldName (String s ) {
127- return null ;
128- }
129-
130- @ Override
131- public FileItem setFormField (boolean b ) {
132- return null ;
133- }
134-
135- @ Override
136- public FileItem write (Path path ) throws IOException {
137- return null ;
138- }
139-
140- @ Override
141- public FileItemHeaders getHeaders () {
142- return null ;
143- }
144-
145- @ Override
146- public FileItemHeadersProvider setHeaders (FileItemHeaders fileItemHeaders ) {
147- return null ;
148- }
149- };
150- }
15149}
0 commit comments