update test

This commit is contained in:
f43nd1r 2018-07-06 03:43:35 +02:00
parent 35c14042b2
commit da4fda7cae
2 changed files with 13 additions and 8 deletions

View file

@ -55,9 +55,8 @@ public class RestReportInterface {
public static final String PARAM_ID = "id"; public static final String PARAM_ID = "id";
public static final String PARAM_MAIL = "mail"; public static final String PARAM_MAIL = "mail";
public static final String REPORT_PATH = "report"; public static final String REPORT_PATH = "report";
public static final String MULTIPART_MIXED = "multipart/mixed"; public static final String REPORT = "ACRA_REPORT";
private static final String REPORT = "ACRA_REPORT"; public static final String ATTACHMENT = "ACRA_ATTACHMENT";
private static final String ATTACHMENT = "ACRA_ATTACHMENT";
@NonNull private final DataService dataService; @NonNull private final DataService dataService;
@Autowired @Autowired

View file

@ -41,8 +41,14 @@ import java.util.Optional;
import static com.faendir.acra.rest.RestReportInterface.*; import static com.faendir.acra.rest.RestReportInterface.*;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@ -56,11 +62,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebMvcTest(controllers = RestReportInterface.class, includeFilters = @ComponentScan.Filter(classes = EnableWebSecurity.class), excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = VaadinSessionSecurityContextHolderStrategy.class)) @WebMvcTest(controllers = RestReportInterface.class, includeFilters = @ComponentScan.Filter(classes = EnableWebSecurity.class), excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = VaadinSessionSecurityContextHolderStrategy.class))
@WithMockUser(roles = {"REPORTER", "USER"}) @WithMockUser(roles = {"REPORTER", "USER"})
public class RestReportInterfaceTest { public class RestReportInterfaceTest {
private final String TEST_STRING = "TEST";
@MockBean UserService userService; @MockBean UserService userService;
@MockBean DataService dataService; @MockBean DataService dataService;
@Autowired RestReportInterface restReportInterface; @Autowired RestReportInterface restReportInterface;
@Autowired MockMvc mvc; @Autowired MockMvc mvc;
private final String TEST_STRING = "TEST";
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -77,9 +83,9 @@ public class RestReportInterfaceTest {
@Test @Test
public void report2() throws Exception { public void report2() throws Exception {
MockMultipartFile file = spy(new MockMultipartFile(TEST_STRING, TEST_STRING.getBytes())); mvc.perform(multipart("/" + REPORT_PATH).file(new MockMultipartFile(REPORT, TEST_STRING, APPLICATION_JSON_VALUE, new byte[0]))
when(file.getName()).thenReturn(null).thenReturn(""); .file(new MockMultipartFile(ATTACHMENT, TEST_STRING, APPLICATION_OCTET_STREAM_VALUE, new byte[0]))
mvc.perform(multipart("/" + REPORT_PATH).file(file).contentType(MULTIPART_MIXED)).andExpect(status().isOk()); .contentType(MULTIPART_FORM_DATA)).andExpect(status().isOk());
verify(dataService, times(1)).createNewReport(any(), any(), any()); verify(dataService, times(1)).createNewReport(any(), any(), any());
} }