Skip to content

Commit ea5a366

Browse files
Sheikah45Brutus5000
authored andcommitted
move MapsControllerTest to integration tests
1 parent 9e82b7c commit ea5a366

2 files changed

Lines changed: 16 additions & 43 deletions

File tree

src/test/java/com/faforever/api/map/MapsControllerTest.java renamed to src/inttest/java/com/faforever/api/map/MapsControllerTest.java

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,65 @@
11
package com.faforever.api.map;
22

3-
import com.faforever.api.config.FafApiProperties;
4-
import com.faforever.api.config.TestWebSecurityConfig;
5-
import com.faforever.api.player.PlayerService;
6-
import com.fasterxml.jackson.databind.JsonNode;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import com.faforever.api.AbstractIntegrationTest;
84
import com.google.common.io.ByteStreams;
95
import org.junit.jupiter.api.Test;
10-
import org.junit.jupiter.api.extension.ExtendWith;
11-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
12-
import org.springframework.boot.test.mock.mockito.MockBean;
13-
import org.springframework.context.annotation.Import;
6+
import org.springframework.beans.factory.annotation.Autowired;
147
import org.springframework.mock.web.MockMultipartFile;
15-
import org.springframework.security.core.userdetails.UserDetailsService;
16-
import org.springframework.test.context.junit.jupiter.SpringExtension;
17-
import org.springframework.test.web.servlet.MockMvc;
8+
import org.springframework.security.test.context.support.WithUserDetails;
9+
import org.springframework.test.context.jdbc.Sql;
1810

19-
import javax.inject.Inject;
2011
import java.io.InputStream;
2112

2213
import static org.hamcrest.Matchers.hasSize;
2314
import static org.hamcrest.Matchers.is;
24-
import static org.mockito.Matchers.anyString;
25-
import static org.mockito.Mockito.when;
2615
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
2716
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
2817
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2918

30-
@ExtendWith(SpringExtension.class)
31-
@WebMvcTest(MapsController.class)
32-
@Import(TestWebSecurityConfig.class)
33-
public class MapsControllerTest {
19+
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/truncateTables.sql")
20+
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql")
21+
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapVersion.sql")
22+
public class MapsControllerTest extends AbstractIntegrationTest{
3423

35-
private MockMvc mvc;
36-
@MockBean
37-
private UserDetailsService userDetailsService;
38-
@MockBean
39-
private MapService mapService;
40-
@MockBean
41-
private FafApiProperties fafApiProperties;
42-
@MockBean
43-
private PlayerService playerService;
44-
@MockBean
45-
private ObjectMapper objectMapper;
46-
47-
@Inject
48-
void init(MockMvc mvc) {
49-
this.mvc = mvc;
50-
}
24+
@Autowired
25+
MapRepository mapRepository;
5126

27+
@WithUserDetails(AUTH_USER)
5228
@Test
5329
void fileMissing() throws Exception {
54-
this.mvc.perform(multipart("/maps/upload"))
30+
mockMvc.perform(multipart("/maps/upload"))
5531
.andExpect(status().isBadRequest())
5632
.andExpect(jsonPath("$.errors", hasSize(1)))
5733
.andExpect(jsonPath("$.errors[0].title", is("org.springframework.web.multipart.support.MissingServletRequestPartException")))
5834
.andExpect(jsonPath("$.errors[0].detail", is("Required request part 'file' is not present")));
5935
}
6036

37+
@WithUserDetails(AUTH_USER)
6138
@Test
6239
void jsonMetaDataMissing() throws Exception {
6340
MockMultipartFile file = new MockMultipartFile("file", "filename.txt", "text/plain", "some xml".getBytes());
6441

65-
this.mvc.perform(multipart("/maps/upload")
42+
mockMvc.perform(multipart("/maps/upload")
6643
.file(file))
6744
.andExpect(status().isBadRequest())
6845
.andExpect(jsonPath("$.errors", hasSize(1)))
6946
.andExpect(jsonPath("$.errors[0].title", is("org.springframework.web.bind.MissingServletRequestParameterException")))
7047
.andExpect(jsonPath("$.errors[0].detail", is("Required String parameter 'metadata' is not present")));
7148
}
7249

50+
@WithUserDetails(AUTH_USER)
7351
@Test
7452
void successUpload() throws Exception {
75-
FafApiProperties props = new FafApiProperties();
7653
String jsonString = "{}";
77-
ObjectMapper mapper = new ObjectMapper();
78-
JsonNode node = mapper.readTree(jsonString);
7954

80-
when(fafApiProperties.getMap()).thenReturn(props.getMap());
81-
when(objectMapper.readTree(anyString())).thenReturn(node);
8255
String zipFile = "command_conquer_rush.v0007.zip";
8356
try (InputStream inputStream = loadMapResourceAsStream(zipFile)) {
8457
MockMultipartFile file = new MockMultipartFile("file",
8558
zipFile,
8659
"application/zip",
8760
ByteStreams.toByteArray(inputStream));
8861

89-
this.mvc.perform(multipart("/maps/upload")
62+
mockMvc.perform(multipart("/maps/upload")
9063
.file(file)
9164
.param("metadata", jsonString)
9265
).andExpect(status().isOk());
5.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)