diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/ParticipantAccessTests.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/ParticipantAccessTests.java index db019c74..60f9fe89 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/ParticipantAccessTests.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/ParticipantAccessTests.java @@ -33,6 +33,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.HttpHeaders; import org.springframework.http.MediaType; @@ -57,6 +58,7 @@ @SpringBootTest(webEnvironment = RANDOM_PORT) @ExtendWith(MockitoExtension.class) +@AutoConfigureMockMvc @Test(groups = "participantAccess") public class ParticipantAccessTests extends AbstractTestNGSpringContextTests { @@ -75,9 +77,6 @@ public class ParticipantAccessTests extends AbstractTestNGSpringContextTests { @Autowired private ObjectMapper objectMapper; - @Autowired - private WebApplicationContext context; - @Autowired private AuthenticatedUserController authenticatedUserController; @@ -87,6 +86,7 @@ public class ParticipantAccessTests extends AbstractTestNGSpringContextTests { @Autowired private ParticipantProvider participantProvider; + @Autowired private MockMvc mockMvc; private String jwtToken; @@ -107,10 +107,6 @@ private T fromJson(String payload, Class clazz) throws IOException { @BeforeClass public void setUp() throws Exception { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - authenticatedUserController.createUser(null, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME, USER_PASSWORD, USER_ROLES); AuthRequest request = new AuthRequest(); diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/RestSimpleChampionshipTest.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/RestSimpleChampionshipTest.java index b653714d..16d5df24 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/RestSimpleChampionshipTest.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/RestSimpleChampionshipTest.java @@ -48,17 +48,14 @@ import com.softwaremagico.kt.rest.controllers.AuthenticatedUserController; import com.softwaremagico.kt.rest.security.dto.AuthRequest; 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.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -78,6 +75,7 @@ @SpringBootTest +@AutoConfigureMockMvc @Test(groups = {"restSimpleChampionshipTest"}) public class RestSimpleChampionshipTest extends AbstractTestNGSpringContextTests { @@ -95,18 +93,12 @@ public class RestSimpleChampionshipTest extends AbstractTestNGSpringContextTests private static final String CLUB_CITY = "Valencia"; - @Autowired - private WebApplicationContext context; - @Autowired private ObjectMapper objectMapper; @Autowired private AuthenticatedUserController authenticatedUserController; - @Autowired - private AuthenticationManager authenticationManager; - @Autowired private GroupController groupController; @@ -134,7 +126,7 @@ public class RestSimpleChampionshipTest extends AbstractTestNGSpringContextTests @Autowired private ClubController clubController; - + @Autowired private MockMvc mockMvc; private String jwtToken; @@ -179,13 +171,6 @@ private T fromJson(String payload, Class clazz) throws IOException { } @BeforeClass - public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - } - - @BeforeClass(dependsOnMethods = "setUp") public void setAuthentication() throws Exception { //Create the admin user authenticatedUserController.createUser(null, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME, USER_PASSWORD, USER_ROLES); diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/UserRegisterTests.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/UserRegisterTests.java index 92a7cea7..ff95ac47 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/UserRegisterTests.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/rest/UserRegisterTests.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.HttpHeaders; import org.springframework.http.MediaType; @@ -54,6 +55,7 @@ @SpringBootTest(webEnvironment = RANDOM_PORT) @ExtendWith(MockitoExtension.class) +@AutoConfigureMockMvc @Test(groups = "userRegister") public class UserRegisterTests extends AbstractTestNGSpringContextTests { @@ -68,10 +70,8 @@ public class UserRegisterTests extends AbstractTestNGSpringContextTests { private static final String CLUB_CITY = "Valencia"; - private MockMvc mockMvc; - @Autowired - private WebApplicationContext context; + private MockMvc mockMvc; @Autowired private ObjectMapper objectMapper; @@ -94,10 +94,6 @@ private T fromJson(String payload, Class clazz) throws IOException { @BeforeClass public void setUp() throws Exception { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - authenticatedUserController.createUser(null, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME, USER_PASSWORD, USER_ROLES); AuthRequest request = new AuthRequest(); diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/BruteForceTests.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/BruteForceTests.java index 853a67ac..8a0b5df0 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/BruteForceTests.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/BruteForceTests.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.HttpHeaders; import org.springframework.http.MediaType; @@ -51,6 +52,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @SpringBootTest(webEnvironment = RANDOM_PORT) +@AutoConfigureMockMvc @ExtendWith(MockitoExtension.class) @Test(groups = "bruteForce") public class BruteForceTests extends AbstractTestNGSpringContextTests { @@ -59,10 +61,8 @@ public class BruteForceTests extends AbstractTestNGSpringContextTests { private static final String USER_LAST_NAME = "User"; private static final String USER_PASSWORD = "password"; - private MockMvc mockMvc; - @Autowired - private WebApplicationContext context; + private MockMvc mockMvc; @Autowired private ObjectMapper objectMapper; @@ -81,13 +81,6 @@ private T fromJson(String payload, Class clazz) throws IOException { return objectMapper.readValue(payload, clazz); } - @BeforeClass - public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - } - @BeforeMethod public void clearDatabase() { authenticatedUserController.findAll().forEach(authenticatedUser -> authenticatedUserController.delete(authenticatedUser)); diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/RestAccessTests.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/RestAccessTests.java index 8a38752a..45e17ce2 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/RestAccessTests.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/RestAccessTests.java @@ -10,12 +10,12 @@ * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * #L% @@ -24,6 +24,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.web.servlet.MockMvc; @@ -46,20 +47,13 @@ @SpringBootTest(webEnvironment = RANDOM_PORT) @ExtendWith(MockitoExtension.class) +@AutoConfigureMockMvc @Test(groups = "restAccess") public class RestAccessTests extends AbstractTestNGSpringContextTests { @Autowired - private WebApplicationContext context; private MockMvc mockMvc; - @BeforeClass - public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity()) - .build(); - } - @Test public void checkPublicRestService() throws Exception { //Info services are opened in rest-server library diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/TestAuthApi.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/TestAuthApi.java index cf801e19..bcb92974 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/TestAuthApi.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/TestAuthApi.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.HttpHeaders; import org.springframework.http.MediaType; @@ -56,6 +57,7 @@ @SpringBootTest(webEnvironment = RANDOM_PORT) @ExtendWith(MockitoExtension.class) +@AutoConfigureMockMvc @Test(groups = "authApi") public class TestAuthApi extends AbstractTestNGSpringContextTests { private static final String USER_NAME = "user"; @@ -75,10 +77,8 @@ public class TestAuthApi extends AbstractTestNGSpringContextTests { private static final String USER2_NEW_FIRST_NAME = "New Test2"; private static final String USER2_NEW_LAST_NAME = "New User2"; - private MockMvc mockMvc; - @Autowired - private WebApplicationContext context; + private MockMvc mockMvc; @Autowired private ObjectMapper objectMapper; @@ -101,10 +101,6 @@ private T fromJson(String payload, Class clazz) throws IOException { @BeforeClass public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - authenticatedUserController.createUser(null, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME, USER_PASSWORD, USER_ROLES); } diff --git a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/UserRegistrationTest.java b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/UserRegistrationTest.java index 702b7102..d04702cc 100644 --- a/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/UserRegistrationTest.java +++ b/backend/kendo-tournament-rest/src/test/java/com/softwaremagico/kt/security/UserRegistrationTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; 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.HttpHeaders; import org.springframework.http.MediaType; @@ -56,6 +57,7 @@ @SpringBootTest(webEnvironment = RANDOM_PORT) @ExtendWith(MockitoExtension.class) +@AutoConfigureMockMvc @Test(groups = "userRegistration") public class UserRegistrationTest extends AbstractTestNGSpringContextTests { public static final String USER_NAME_2 = "Goku"; @@ -68,7 +70,6 @@ public class UserRegistrationTest extends AbstractTestNGSpringContextTests { private static final String[] USER_ROLES = new String[] {"admin", "viewer"}; @Autowired - private WebApplicationContext context; private MockMvc mockMvc; @@ -96,10 +97,6 @@ private T fromJson(String payload, Class clazz) throws IOException { @BeforeClass public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .build(); - authenticatedUserController.findAll().forEach(authenticatedUser -> authenticatedUserController.delete(authenticatedUser)); }