Internal help: Add basic controller tests
This commit is contained in:
committed by
jvoisin
parent
bd4153962f
commit
6a3d301517
+44
@@ -0,0 +1,44 @@
|
||||
package org.airsonic.player.controller;
|
||||
|
||||
import org.airsonic.player.util.HomeRule;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class InternalHelpControllerIntTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@ClassRule
|
||||
public static final HomeRule classRule = new HomeRule(); // sets airsonic.home to a temporary dir
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "admin", roles = {"USER", "ADMIN"})
|
||||
public void testOkForAdmins() throws Exception {
|
||||
mvc.perform(get("/internalhelp")
|
||||
.contentType(MediaType.TEXT_HTML))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "user", roles = {"USER"})
|
||||
public void testNotOkForUsers() throws Exception {
|
||||
mvc.perform(get("/internalhelp")
|
||||
.contentType(MediaType.TEXT_HTML))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user