diff --git a/restservice/pom.xml b/restservice/pom.xml index 7680742..62aa58e 100755 --- a/restservice/pom.xml +++ b/restservice/pom.xml @@ -27,7 +27,7 @@ junit junit - 4.11 + 4.12 test @@ -42,6 +42,14 @@ spring-boot-starter-web + + + org.springframework.security + spring-security-test + 5.3.4.RELEASE + test + + org.springframework.boot spring-boot-starter-security diff --git a/restservice/src/test/java/com/plannaplan/AppTest.java b/restservice/src/test/java/com/plannaplan/AppTest.java deleted file mode 100755 index c2cebc0..0000000 --- a/restservice/src/test/java/com/plannaplan/AppTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.plannaplan; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} diff --git a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java new file mode 100755 index 0000000..42d2804 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java @@ -0,0 +1,51 @@ +package com.plannaplan.controllers; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; + +import java.io.InputStream; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ContextConfiguration +public class ConfigControllerTest { + + private static final String FILE_NAME = "Zajecia.xlsx"; + private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config"; + + @Autowired + private WebApplicationContext webApplicationContext; + + @Test + public void shouldReturnOK() throws Exception { + final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME); + final MockMultipartFile file = new MockMultipartFile("file", inputStream); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file)).andExpect(status().isOk()); + + } + + @Test + public void shouldReturnNoAuthorized() throws Exception { + final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME); + final MockMultipartFile file = new MockMultipartFile("file", inputStream); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file)).andExpect(status().is4xxClientError()); + + } +} diff --git a/restservice/src/test/resources/Zajecia.xlsx b/restservice/src/test/resources/Zajecia.xlsx new file mode 100755 index 0000000..57c8e9c Binary files /dev/null and b/restservice/src/test/resources/Zajecia.xlsx differ