From 1327a239e88da183124dbf2d7e28f602ef342893 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 30 Oct 2020 16:53:41 +0100 Subject: [PATCH] Made wepAppContex commont --- .../plannaplan/controllers/AbstractControllerTest.java | 10 ++++++++++ .../controllers/AssignmentsControllerTest.java | 6 +----- .../controllers/CommisionControllerTest.java | 6 +----- .../plannaplan/controllers/ConfigControllerTest.java | 6 +----- .../plannaplan/controllers/CoursesControllerTest.java | 7 +------ .../plannaplan/controllers/GroupControllerTest.java | 7 +------ .../plannaplan/controllers/TokenControllerTest.java | 6 +----- .../plannaplan/controllers/UsersControllerTest.java | 6 +----- 8 files changed, 17 insertions(+), 37 deletions(-) create mode 100755 restservice/src/test/java/com/plannaplan/controllers/AbstractControllerTest.java diff --git a/restservice/src/test/java/com/plannaplan/controllers/AbstractControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/AbstractControllerTest.java new file mode 100755 index 0000000..753cab8 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/controllers/AbstractControllerTest.java @@ -0,0 +1,10 @@ +package com.plannaplan.controllers; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.context.WebApplicationContext; + +public abstract class AbstractControllerTest { + @Autowired + protected WebApplicationContext webApplicationContext; + +} diff --git a/restservice/src/test/java/com/plannaplan/controllers/AssignmentsControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/AssignmentsControllerTest.java index 5e7e578..e80b447 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/AssignmentsControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/AssignmentsControllerTest.java @@ -12,7 +12,6 @@ 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; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; @@ -21,14 +20,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class AssignmentsControllerTest { +public class AssignmentsControllerTest extends AbstractControllerTest { private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/getCurrentAssignments"; private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain"; - @Autowired - private WebApplicationContext webApplicationContext; - @Autowired private UserService service; diff --git a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java index bf371d7..f0339c2 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java @@ -9,7 +9,6 @@ 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; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -26,10 +25,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class CommisionControllerTest { - - @Autowired - private WebApplicationContext webApplicationContext; +public class CommisionControllerTest extends AbstractControllerTest { @Autowired private UserService service; diff --git a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java index 1c322c8..2c445af 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java @@ -20,20 +20,16 @@ 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 { +public class ConfigControllerTest extends AbstractControllerTest { private static final String FILE_NAME = "Zajecia.xlsx"; private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config"; private static final String TEST_MAIL = "notexisting@mail.domain"; - @Autowired - private WebApplicationContext webApplicationContext; - @Autowired private UserService service; diff --git a/restservice/src/test/java/com/plannaplan/controllers/CoursesControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CoursesControllerTest.java index 67af08f..a01d396 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CoursesControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CoursesControllerTest.java @@ -2,13 +2,11 @@ package com.plannaplan.controllers; 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.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; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -16,14 +14,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class CoursesControllerTest { +public class CoursesControllerTest extends AbstractControllerTest { private static final String COURSES_ENDPOINT = "/api/v1/courses/getCourses"; private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/getCoursesWithGroups"; - @Autowired - private WebApplicationContext webApplicationContext; - @Test public void shouldReturnAllCoursesOk() throws Exception { diff --git a/restservice/src/test/java/com/plannaplan/controllers/GroupControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/GroupControllerTest.java index 4698bdc..aefad82 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/GroupControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/GroupControllerTest.java @@ -2,13 +2,11 @@ package com.plannaplan.controllers; 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.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; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -16,12 +14,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class GroupControllerTest { +public class GroupControllerTest extends AbstractControllerTest { private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/getCourseGroups"; - @Autowired - private WebApplicationContext webApplicationContext; - @Test public void shouldFailWithNoParaeter() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); diff --git a/restservice/src/test/java/com/plannaplan/controllers/TokenControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/TokenControllerTest.java index 79ee95b..9716a68 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/TokenControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/TokenControllerTest.java @@ -3,13 +3,11 @@ package com.plannaplan.controllers; import org.junit.Ignore; 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.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; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -17,10 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class TokenControllerTest { +public class TokenControllerTest extends AbstractControllerTest { private final String TOKEN_ENDPOINT = "/token"; - @Autowired - private WebApplicationContext webApplicationContext; @Test public void shouldFailWithNoParameter() throws Exception { diff --git a/restservice/src/test/java/com/plannaplan/controllers/UsersControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/UsersControllerTest.java index b55850d..f2771ba 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/UsersControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/UsersControllerTest.java @@ -12,7 +12,6 @@ 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; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; @@ -21,12 +20,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration -public class UsersControllerTest { +public class UsersControllerTest extends AbstractControllerTest { private static final String ENDPOINT = "/api/v1/users/searchForStudents"; - @Autowired - private WebApplicationContext webApplicationContext; - @Autowired private UserService service;