diff --git a/pom.xml b/pom.xml index e7879da..11f9777 100644 --- a/pom.xml +++ b/pom.xml @@ -151,21 +151,6 @@ h2 test - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - - - org.mockito - mockito-core - test - org.springframework.boot spring-boot-starter-test diff --git a/src/test/java/org/gridsuite/useradmin/server/NoAdminTest.java b/src/test/java/org/gridsuite/useradmin/server/NoAdminTest.java index 0a63034..972b110 100644 --- a/src/test/java/org/gridsuite/useradmin/server/NoAdminTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/NoAdminTest.java @@ -6,9 +6,9 @@ */ package org.gridsuite.useradmin.server; +import org.gridsuite.useradmin.server.entity.UserInfosEntity; import org.gridsuite.useradmin.server.repository.ConnectionRepository; import org.gridsuite.useradmin.server.repository.UserInfosRepository; -import org.gridsuite.useradmin.server.entity.UserInfosEntity; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +39,7 @@ class NoAdminTest { private ConnectionRepository connectionRepository; @AfterEach - public void cleanDB() { + void cleanDB() { userInfosRepository.deleteAll(); connectionRepository.deleteAll(); } diff --git a/src/test/java/org/gridsuite/useradmin/server/NoQuotaTest.java b/src/test/java/org/gridsuite/useradmin/server/NoQuotaTest.java index 92ccea1..b0c0911 100644 --- a/src/test/java/org/gridsuite/useradmin/server/NoQuotaTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/NoQuotaTest.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; -import lombok.SneakyThrows; import org.gridsuite.useradmin.server.dto.UserInfos; import org.gridsuite.useradmin.server.dto.UserProfile; import org.gridsuite.useradmin.server.entity.UserProfileEntity; @@ -65,27 +64,25 @@ class NoQuotaTest { private ObjectWriter objectWriter; @BeforeEach - public void setUp() { + void setUp() { objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); } @AfterEach - public void cleanDB() { + void cleanDB() { userInfosRepository.deleteAll(); userProfileRepository.deleteAll(); } @Test - @SneakyThrows - void testProfileCreation() { + void testProfileCreation() throws Exception { createProfile(PROFILE_ONE, null, null); // test with quotas createProfile(PROFILE_TWO, 10, 20); } @Test - @SneakyThrows - void testUserCreationWithoutProfile() { + void testUserCreationWithoutProfile() throws Exception { createUser(USER_SUB); assertTrue(getMaxAllowedBuilds(USER_SUB).isEmpty()); @@ -93,8 +90,7 @@ void testUserCreationWithoutProfile() { } @Test - @SneakyThrows - void testUserCreationWithProfile() { + void testUserCreationWithProfile() throws Exception { //profile with no quotas createProfile(PROFILE_ONE, null, null); createUser(USER_SUB); @@ -112,8 +108,7 @@ void testUserCreationWithProfile() { assertEquals("20", getMaxAllowedBuilds(USER_SUB_TWO)); } - @SneakyThrows - private void createProfile(String profileName, Integer maxAllowedCases, Integer maxAllowedBuilds) { + private void createProfile(String profileName, Integer maxAllowedCases, Integer maxAllowedBuilds) throws Exception { UserProfile profileInfo = new UserProfile(null, profileName, null, false, maxAllowedCases, maxAllowedBuilds); performPost(API_BASE_PATH + "/profiles", profileInfo); @@ -124,8 +119,7 @@ private void createProfile(String profileName, Integer maxAllowedCases, Integer assertEquals(maxAllowedBuilds, createdProfile.get().getMaxAllowedBuilds()); } - @SneakyThrows - private void createUser(String userSub) { + private void createUser(String userSub) throws Exception { performPost(API_BASE_PATH + "/users/" + userSub, null); // check user creation @@ -135,32 +129,27 @@ private void createUser(String userSub) { assertEquals(userSub, userInfos.sub()); } - @SneakyThrows - private UserInfos getUserInfos(String userSub) { + private UserInfos getUserInfos(String userSub) throws Exception { MvcResult result = performGet(API_BASE_PATH + "/users/" + userSub); return objectMapper.readValue(result.getResponse().getContentAsString(), UserInfos.class); } - @SneakyThrows - private void associateProfileToUser(String userSub, String profileName) { + private void associateProfileToUser(String userSub, String profileName) throws Exception { UserInfos userInfos = new UserInfos(userSub, false, profileName, null, null, null); performPut(API_BASE_PATH + "/users/" + userSub, userInfos); } - @SneakyThrows - private String getMaxAllowedBuilds(String userSub) { + private String getMaxAllowedBuilds(String userSub) throws Exception { MvcResult result = performGet(API_BASE_PATH + "/users/" + userSub + "/profile/max-builds"); return result.getResponse().getContentAsString(); } - @SneakyThrows - private String getMaxAllowedCases(String userSub) { + private String getMaxAllowedCases(String userSub) throws Exception { MvcResult result = performGet(API_BASE_PATH + "/users/" + userSub + "/profile/max-cases"); return result.getResponse().getContentAsString(); } - @SneakyThrows - private void performPost(String url, Object content) { + private void performPost(String url, Object content) throws Exception { mockMvc.perform(post(url) .content(content != null ? objectWriter.writeValueAsString(content) : "") .contentType(APPLICATION_JSON) @@ -168,8 +157,7 @@ private void performPost(String url, Object content) { .andExpect(status().isCreated()); } - @SneakyThrows - private void performPut(String url, Object content) { + private void performPut(String url, Object content) throws Exception { mockMvc.perform(put(url) .content(objectWriter.writeValueAsString(content)) .contentType(APPLICATION_JSON) @@ -177,8 +165,7 @@ private void performPut(String url, Object content) { .andExpect(status().isOk()); } - @SneakyThrows - private MvcResult performGet(String url) { + private MvcResult performGet(String url) throws Exception { return mockMvc.perform(get(url) .header("userId", ADMIN_USER)) .andExpect(status().isOk()) diff --git a/src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java b/src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java index a31e7c9..2ea0b2d 100644 --- a/src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; -import lombok.SneakyThrows; import org.gridsuite.useradmin.server.dto.UserInfos; import org.gridsuite.useradmin.server.dto.UserProfile; import org.gridsuite.useradmin.server.entity.ConnectionEntity; @@ -67,14 +66,14 @@ class UserAdminTest { @Autowired private OutputDestination output; - private final String maintenanceMessageDestination = "config.message"; + private static final String MAINTENANCE_MESSAGE_DESTINATION = "config.message"; - private final String userMessageDestination = "directory.update"; + private static final String USER_MESSAGE_DESTINATION = "directory.update"; private static final long TIMEOUT = 1000; @AfterEach - public void cleanDB() { + void cleanDB() { userInfosRepository.deleteAll(); userProfileRepository.deleteAll(); connectionRepository.deleteAll(); @@ -103,8 +102,7 @@ void testUserAdmin() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(0, userInfos.size()); @@ -124,8 +122,7 @@ void testUserAdmin() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(1, userInfos.size()); @@ -160,8 +157,7 @@ void testUserAdmin() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(0, userInfos.size()); mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB) @@ -211,8 +207,7 @@ void testUserAdmin() throws Exception { } @Test - @SneakyThrows - void testUpdateUser() { + void testUpdateUser() throws Exception { createUser(USER_SUB); createProfile(PROFILE_1); @@ -227,20 +222,17 @@ void testUpdateUser() { } @Test - @SneakyThrows - void testUpdateUserNotFound() { + void testUpdateUserNotFound() throws Exception { updateUser("nofFound", new UserInfos("nofFound", false, "prof", null, null, null), HttpStatus.NOT_FOUND, ADMIN_USER); } @Test - @SneakyThrows - void testUpdateUserForbidden() { + void testUpdateUserForbidden() throws Exception { updateUser("dummy", new UserInfos("dummy", false, "prof", null, null, null), HttpStatus.FORBIDDEN, NOT_ADMIN); } @Test - @SneakyThrows - void testGetUserProfileNotFound() { + void testGetUserProfileNotFound() throws Exception { getUserProfile("BadUser", HttpStatus.NOT_FOUND); } @@ -264,8 +256,7 @@ void testGetConnections() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(2, userInfos.size()); @@ -283,8 +274,7 @@ void testGetConnections() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(2, connectionEntities.size()); @@ -298,8 +288,7 @@ void testGetConnections() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertEquals(2, connectionEntities.size()); mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/connections") @@ -363,7 +352,7 @@ void testSendUserMessage() throws Exception { } private void assertUserMessageSent(String messageId, String sub) { - Message message = output.receive(TIMEOUT, userMessageDestination); + Message message = output.receive(TIMEOUT, USER_MESSAGE_DESTINATION); MessageHeaders headers = message.getHeaders(); assertEquals(messageId, headers.get(HEADER_USER_MESSAGE)); assertEquals(sub, headers.get(HEADER_USER_ID)); @@ -371,7 +360,7 @@ private void assertUserMessageSent(String messageId, String sub) { } private void assertMaintenanceMessageSent(String maintenanceMessage, Integer duration) { - Message message = output.receive(TIMEOUT, maintenanceMessageDestination); + Message message = output.receive(TIMEOUT, MAINTENANCE_MESSAGE_DESTINATION); assertEquals(maintenanceMessage, new String(message.getPayload())); MessageHeaders headers = message.getHeaders(); assertEquals(MESSAGE_TYPE_MAINTENANCE, headers.get(HEADER_MESSAGE_TYPE)); @@ -379,14 +368,13 @@ private void assertMaintenanceMessageSent(String maintenanceMessage, Integer dur } private void assertCancelMaintenanceMessageSent() { - Message message = output.receive(TIMEOUT, maintenanceMessageDestination); + Message message = output.receive(TIMEOUT, MAINTENANCE_MESSAGE_DESTINATION); assertEquals("", new String(message.getPayload())); MessageHeaders headers = message.getHeaders(); assertEquals(MESSAGE_TYPE_CANCEL_MAINTENANCE, headers.get(HEADER_MESSAGE_TYPE)); } - @SneakyThrows - private void createUser(String userName) { + private void createUser(String userName) throws Exception { mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/users/{sub}", userName) .header("userId", ADMIN_USER) ) @@ -398,16 +386,14 @@ private void createUser(String userName) { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); // the new user has no profile by default assertNotNull(userInfos); assertNull(userInfos.profileName()); assertEquals(userName, userInfos.sub()); } - @SneakyThrows - private void createProfile(String profileName) { + private void createProfile(String profileName) throws Exception { ObjectWriter objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); UserProfile profileInfo = new UserProfile(null, profileName, null, false, null, null); mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/profiles") @@ -419,8 +405,7 @@ private void createProfile(String profileName) { .andReturn(); } - @SneakyThrows - private void updateUser(String updatedUserName, UserInfos userInfos, HttpStatusCode status, String userName) { + private void updateUser(String updatedUserName, UserInfos userInfos, HttpStatusCode status, String userName) throws Exception { ObjectWriter objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); mockMvc.perform(put("/" + UserAdminApi.API_VERSION + "/users/{sub}", updatedUserName) .content(objectWriter.writeValueAsString(userInfos)) @@ -435,8 +420,7 @@ private void updateUser(String updatedUserName, UserInfos userInfos, HttpStatusC .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); // the new user has the new name and profile assertNotNull(updatedUserInfos); assertEquals(userInfos.sub(), updatedUserInfos.sub()); @@ -444,15 +428,13 @@ private void updateUser(String updatedUserName, UserInfos userInfos, HttpStatusC } } - @SneakyThrows - private UserProfile getUserProfile(String userName, HttpStatusCode status) { + private UserProfile getUserProfile(String userName, HttpStatusCode status) throws Exception { String response = mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/users/" + userName + "/profile") .contentType(APPLICATION_JSON)) .andExpect(status().is(status.value())) .andReturn().getResponse().getContentAsString(); if (status == HttpStatus.OK) { - return objectMapper.readValue(response, new TypeReference<>() { - }); + return objectMapper.readValue(response, new TypeReference<>() { }); } return null; } diff --git a/src/test/java/org/gridsuite/useradmin/server/UserProfileTest.java b/src/test/java/org/gridsuite/useradmin/server/UserProfileTest.java index 3493f25..1f5b8d5 100644 --- a/src/test/java/org/gridsuite/useradmin/server/UserProfileTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/UserProfileTest.java @@ -9,9 +9,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.matching.StringValuePattern; -import lombok.SneakyThrows; import org.gridsuite.useradmin.server.dto.ElementAttributes; import org.gridsuite.useradmin.server.dto.UserProfile; import org.gridsuite.useradmin.server.entity.UserInfosEntity; @@ -20,20 +20,17 @@ import org.gridsuite.useradmin.server.repository.UserProfileRepository; import org.gridsuite.useradmin.server.service.DirectoryService; import org.gridsuite.useradmin.server.utils.WireMockUtils; -import org.junit.Assert; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; 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.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; -import com.github.tomakehurst.wiremock.WireMockServer; import org.springframework.test.web.servlet.MvcResult; import java.util.List; @@ -43,24 +40,17 @@ import java.util.stream.Collectors; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @author David Braquart */ -@RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc -public class UserProfileTest { +class UserProfileTest { @Autowired private MockMvc mockMvc; @@ -82,8 +72,8 @@ public class UserProfileTest { private ObjectWriter objectWriter; - @Before - public void setUp() { + @BeforeEach + void setUp() { wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); wireMockServer.start(); DirectoryService.setDirectoryServerBaseUri(wireMockServer.baseUrl()); @@ -91,14 +81,14 @@ public void setUp() { objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); } - @After - public void tearOff() { + @AfterEach + void tearOff() { userInfosRepository.deleteAll(); userProfileRepository.deleteAll(); try { wireMockServer.checkForUnmatchedRequests(); - Assert.assertEquals(0, wireMockServer.findAll(WireMock.anyRequestedFor(WireMock.anyUrl())).size()); + assertEquals(0, wireMockServer.findAll(WireMock.anyRequestedFor(WireMock.anyUrl())).size()); } finally { wireMockServer.shutdown(); } @@ -110,14 +100,13 @@ public void tearOff() { private static final String PROFILE_2 = "profile_2"; @Test - public void testEmptyProfileList() { + void testEmptyProfileList() throws Exception { // no existing profile in empty db assertEquals(0, getProfileList().size()); } @Test - @SneakyThrows - public void testCreateProfile() { + void testCreateProfile() throws Exception { createProfile(PROFILE_1, ADMIN_USER, 10, 15, HttpStatus.CREATED); List userProfiles = getProfileList(); @@ -132,14 +121,12 @@ public void testCreateProfile() { } @Test - @SneakyThrows - public void testCreateProfileForbidden() { + void testCreateProfileForbidden() throws Exception { createProfile(PROFILE_1, NOT_ADMIN, 1, 0, HttpStatus.FORBIDDEN); } @Test - @SneakyThrows - public void testDeleteExistingProfile() { + void testDeleteExistingProfile() throws Exception { createProfile(PROFILE_1, ADMIN_USER, null, null, HttpStatus.CREATED); assertEquals(1, getProfileList().size()); removeProfile(PROFILE_1, ADMIN_USER, HttpStatus.NO_CONTENT); @@ -147,44 +134,37 @@ public void testDeleteExistingProfile() { } @Test - @SneakyThrows - public void testDeleteProfileForbidden() { + void testDeleteProfileForbidden() throws Exception { removeProfile(PROFILE_1, NOT_ADMIN, HttpStatus.FORBIDDEN); } @Test - @SneakyThrows - public void testDeleteProfileNotFound() { + void testDeleteProfileNotFound() throws Exception { removeProfile("noExist", ADMIN_USER, HttpStatus.NOT_FOUND); } @Test - @SneakyThrows - public void testProfileUpdateNotFound() { + void testProfileUpdateNotFound() throws Exception { updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null), ADMIN_USER, HttpStatus.NOT_FOUND); } @Test - @SneakyThrows - public void testProfileUpdateForbidden() { + void testProfileUpdateForbidden() throws Exception { updateProfile(new UserProfile(UUID.randomUUID(), PROFILE_2, null, null, null, null), NOT_ADMIN, HttpStatus.FORBIDDEN); } @Test - @SneakyThrows - public void testProfileUpdateValidityOk() { + void testProfileUpdateValidityOk() throws Exception { updateProfile(true); } @Test - @SneakyThrows - public void testProfileUpdateValidityKo() { + void testProfileUpdateValidityKo() throws Exception { updateProfile(false); } @Test - @SneakyThrows - public void testGetProfileMaxAllowedCases() { + void testGetProfileMaxAllowedCases() throws Exception { UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, 15, null); UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, userProfileEntity); userProfileRepository.save(userProfileEntity); @@ -199,8 +179,7 @@ public void testGetProfileMaxAllowedCases() { } @Test - @SneakyThrows - public void testGetProfileMaxAllowedBuilds() { + void testGetProfileMaxAllowedBuilds() throws Exception { UserProfileEntity userProfileEntity = new UserProfileEntity(UUID.randomUUID(), "profileName", null, null, 15); UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, userProfileEntity); userProfileRepository.save(userProfileEntity); @@ -215,8 +194,7 @@ public void testGetProfileMaxAllowedBuilds() { } @Test - @SneakyThrows - public void testGetProfileMaxAllowedCasesWithNoProfileSet() { + void testGetProfileMaxAllowedCasesWithNoProfileSet() throws Exception { UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, null); userInfosRepository.save(userInfosEntity); @@ -230,8 +208,7 @@ public void testGetProfileMaxAllowedCasesWithNoProfileSet() { } @Test - @SneakyThrows - public void testGetProfileMaxAllowedBuildsWithNoProfileSet() { + void testGetProfileMaxAllowedBuildsWithNoProfileSet() throws Exception { UserInfosEntity userInfosEntity = new UserInfosEntity(UUID.randomUUID(), ADMIN_USER, null); userInfosRepository.save(userInfosEntity); @@ -244,8 +221,7 @@ public void testGetProfileMaxAllowedBuildsWithNoProfileSet() { assertEquals(defaultMaxAllowedBuilds, result.getResponse().getContentAsString()); } - @SneakyThrows - private void updateProfile(boolean validParameters) { + private void updateProfile(boolean validParameters) throws Exception { UUID lfParametersUuid = UUID.randomUUID(); // stub for parameters elements existence check final String urlPath = "/v1/elements"; @@ -253,7 +229,7 @@ private void updateProfile(boolean validParameters) { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(urlPath + "\\?strictMode=false&ids=" + lfParametersUuid)) .willReturn(WireMock.ok() .withBody(objectMapper.writeValueAsString(existingElements)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); UUID profileUuid = createProfile(PROFILE_1, ADMIN_USER, null, 0, HttpStatus.CREATED); @@ -271,12 +247,11 @@ private void updateProfile(boolean validParameters) { assertEquals(11, userProfiles.get(0).maxAllowedBuilds()); } - private Map handleQueryParams(List paramIds) { + private static Map handleQueryParams(List paramIds) { return Map.of("ids", WireMock.matching(paramIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - @SneakyThrows - private UUID createProfile(String profileName, String userName, Integer maxAllowedCases, Integer maxAllowedBuilds, HttpStatusCode status) { + private UUID createProfile(String profileName, String userName, Integer maxAllowedCases, Integer maxAllowedBuilds, HttpStatusCode status) throws Exception { UserProfile profileInfo = new UserProfile(null, profileName, null, false, maxAllowedCases, maxAllowedBuilds); mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/profiles") .content(objectWriter.writeValueAsString(profileInfo)) @@ -303,20 +278,17 @@ private UUID createProfile(String profileName, String userName, Integer maxAllow return null; } - @SneakyThrows - private List getProfileList() { + private List getProfileList() throws Exception { return objectMapper.readValue( mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/profiles") .header("userId", ADMIN_USER) .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); } - @SneakyThrows - private void removeProfile(String profileName, String userName, HttpStatusCode status) { + private void removeProfile(String profileName, String userName, HttpStatusCode status) throws Exception { mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/profiles") .content(objectWriter.writeValueAsString(List.of(profileName))) .contentType(MediaType.APPLICATION_JSON) @@ -326,8 +298,7 @@ private void removeProfile(String profileName, String userName, HttpStatusCode s .andReturn(); } - @SneakyThrows - private void updateProfile(UserProfile newData, String userName, HttpStatusCode status) { + private void updateProfile(UserProfile newData, String userName, HttpStatusCode status) throws Exception { mockMvc.perform(put("/" + UserAdminApi.API_VERSION + "/profiles/{profileUuid}", newData.id()) .content(objectWriter.writeValueAsString(newData)) .contentType(MediaType.APPLICATION_JSON) @@ -342,8 +313,7 @@ private void updateProfile(UserProfile newData, String userName, HttpStatusCode .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); + new TypeReference<>() { }); assertNotNull(updatedProfile); assertEquals(newData.name(), updatedProfile.name()); assertEquals(newData.loadFlowParameterId(), updatedProfile.loadFlowParameterId()); diff --git a/src/test/java/org/gridsuite/useradmin/server/controller/UserInfosControllerTest.java b/src/test/java/org/gridsuite/useradmin/server/controller/UserInfosControllerTest.java index 6c76773..15f32d7 100644 --- a/src/test/java/org/gridsuite/useradmin/server/controller/UserInfosControllerTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/controller/UserInfosControllerTest.java @@ -25,9 +25,7 @@ import java.util.UUID; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -45,7 +43,7 @@ class UserInfosControllerTest { private static final String API_BASE_PATH = "/" + UserAdminApi.API_VERSION; @Autowired - UserProfileRepository userProfileRepository; + private UserProfileRepository userProfileRepository; @Autowired private UserInfosRepository userInfosRepository; @@ -85,6 +83,5 @@ void getUserDetail() throws Exception { assertEquals(10, userInfos.maxAllowedCases()); assertEquals(5, userInfos.numberCasesUsed()); assertEquals(20, userInfos.maxAllowedBuilds()); - } } diff --git a/src/test/java/org/gridsuite/useradmin/server/service/UserInfosServiceTest.java b/src/test/java/org/gridsuite/useradmin/server/service/UserInfosServiceTest.java index 1a01a3c..e5eacab 100644 --- a/src/test/java/org/gridsuite/useradmin/server/service/UserInfosServiceTest.java +++ b/src/test/java/org/gridsuite/useradmin/server/service/UserInfosServiceTest.java @@ -6,7 +6,6 @@ */ package org.gridsuite.useradmin.server.service; -import lombok.SneakyThrows; import org.gridsuite.useradmin.server.UserAdminApplication; import org.gridsuite.useradmin.server.UserAdminApplicationProps; import org.gridsuite.useradmin.server.dto.UserInfos; @@ -55,7 +54,6 @@ class UserInfosServiceTest { private UserInfosService userInfosService; @Test - @SneakyThrows void toDtoUserInfoTest() { // get number of cases used mock when(directoryServiceMock.getCasesCount("user_A")).thenReturn(3); diff --git a/src/test/java/org/gridsuite/useradmin/server/utils/WireMockUtils.java b/src/test/java/org/gridsuite/useradmin/server/utils/WireMockUtils.java index 2ebade0..b503406 100644 --- a/src/test/java/org/gridsuite/useradmin/server/utils/WireMockUtils.java +++ b/src/test/java/org/gridsuite/useradmin/server/utils/WireMockUtils.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class WireMockUtils {