-
Notifications
You must be signed in to change notification settings - Fork 1
/
uploadTest.java
103 lines (76 loc) · 3.5 KB
/
uploadTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.sharefiles.root.uploadTests;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.sharefiles.root.RootApplication;
import org.sharefiles.root.config.ShareFilesConfig;
import org.sharefiles.root.controllers.UploadController;
import org.sharefiles.root.repository.UploadFilesRepository;
import org.sharefiles.root.services.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
//import org.junit.jupiter.api.Test;
//@SpringBootTest
//@RunWith(SpringRunner.class)
//@WebMvcTest(UploadController.class)
//@SpringBootTest
//@RunWith(SpringRunner.class)
//@WebMvcTest(value = UploadController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RootApplication.class)
@AutoConfigureMockMvc
@EnableAutoConfiguration(exclude=SecurityAutoConfiguration.class)
//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class uploadTest {
// @Autowired
@MockBean
private UploadFilesRepository uploadFilesRepository;
//@Autowired
@MockBean
private UploadService uploadService;
@Autowired
private MockMvc mockMvc;
@Spy
@InjectMocks
private UploadController controller = new UploadController();
private MockMultipartFile testFile1;
@Before
public void init() {
testFile1 = new MockMultipartFile("data", "test-file.txt", "text/plain","sample data1".getBytes());
//mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
@Test
public void registeredUploadServiceTest() {
uploadService.uploadFileRegistered(testFile1);
}
@Test
public void anonymousUploadServiceTest() {
uploadService.uploadFileAnon(testFile1);
}
@Test
public void anonymousUploadControllerTest() throws Exception {
MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "test-file.txt", MediaType.TEXT_PLAIN_VALUE,"sample data1".getBytes());
mockMvc.perform(MockMvcRequestBuilders.multipart("/upload")
.file(mockMultipartFile))
.andExpect(MockMvcResultMatchers.status().is(200))
.andExpect((ResultMatcher) content().string("File has been uploaded"));
}
@Test
public void testEnumValues() {
System.out.println(ShareFilesConfig.ANONYMOUS_DIRECTORY);
}
}