From 6a3d3015175bab1e00a35e906c940b077dd002d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Thomas?= Date: Tue, 11 Feb 2020 22:54:28 +0100 Subject: [PATCH] Internal help: Add basic controller tests --- .../InternalHelpControllerIntTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 airsonic-main/src/test/java/org/airsonic/player/controller/InternalHelpControllerIntTest.java diff --git a/airsonic-main/src/test/java/org/airsonic/player/controller/InternalHelpControllerIntTest.java b/airsonic-main/src/test/java/org/airsonic/player/controller/InternalHelpControllerIntTest.java new file mode 100644 index 00000000..66dcb83e --- /dev/null +++ b/airsonic-main/src/test/java/org/airsonic/player/controller/InternalHelpControllerIntTest.java @@ -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()); + } +}