diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f3d02810..c11e3934 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-java@v2 with: distribution: adopt - java-version: 17 + java-version: 21 - name: Set env run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/*/} - name: Dockerize with Maven diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 035a0053..81b4156a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 17, 19 ] + java: [ 17, 21, 22 ] steps: - uses: actions/checkout@v1 - name: Cache Maven Repo diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e5782f43..066abf30 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -18,7 +18,7 @@ jobs: uses: actions/setup-java@v2 with: distribution: adopt - java-version: 17 + java-version: 21 - name: Build with Maven run: mvn -B --no-transfer-progress org.jacoco:jacoco-maven-plugin:prepare-agent package --file pom.xml --settings settings.xml env: diff --git a/pom.xml b/pom.xml index 13d57c80..4900a125 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ spring-boot-starter-parent org.springframework.boot - 3.0.0 + 3.3.2 @@ -41,9 +41,8 @@ UTF-8 1.0.0m1 - 1.7.0 - 2.14.0 - 3.13.0 + 2.16.1 + 3.15.0 2.2.4 2.3.0 17 @@ -56,13 +55,13 @@ 1.2 3.1.3 false - 3.10.0.2594 + 4.0.0.4121 2.5.0.RELEASE 7.0.0.CR1 ${project.build.directory}/test-results - 0.8.0 - 5.3.1 - 3.9.0 + 0.9.0 + 7.2.2 + 3.12.0 @@ -96,7 +95,7 @@ org.jobrunr - jobrunr-spring-boot-starter + jobrunr-spring-boot-3-starter ${jobrunr.version} @@ -126,7 +125,7 @@ com.fasterxml.jackson.datatype - jackson-datatype-hibernate5 + jackson-datatype-hibernate6 com.fasterxml.jackson.datatype @@ -145,20 +144,12 @@ com.h2database h2 runtime - 1.4.200 + 2.3.230 - - - com.jayway.awaitility - awaitility - ${awaitility.version} - test - - org.apache.sshd sshd-core - 2.8.0 + 2.13.2 commons-io @@ -189,12 +180,12 @@ com.sun.xml.bind jaxb-core - 4.0.3 + 4.0.5 com.sun.xml.bind jaxb-impl - 4.0.3 + 4.0.5 com.fasterxml.jackson.module @@ -222,17 +213,17 @@ org.hibernate.orm hibernate-jcache - 6.1.5.Final + 6.5.2.Final org.ehcache ehcache-transactions - 3.10.6 + 3.10.8 org.hibernate.orm hibernate-envers - 6.1.5.Final + 6.5.2.Final org.hibernate.validator @@ -242,7 +233,7 @@ org.hibernate hibernate-entitymanager - 5.6.12.Final + 5.6.15.Final @@ -319,7 +310,7 @@ org.springframework.boot spring-boot-starter-oauth2-resource-server - 3.0.6 + 3.3.2 @@ -355,14 +346,14 @@ org.projectlombok lombok - 1.18.30 + 1.18.34 provided org.zalando problem-spring-web - 0.27.0 + 0.29.1 @@ -385,7 +376,7 @@ com.querydsl querydsl-core - 5.0.0 + 5.1.0 com.querydsl @@ -397,23 +388,23 @@ com.querydsl querydsl-jpa jakarta - 5.0.0 + 5.1.0 org.springframework.data spring-data-commons - 3.0.0 + 3.3.2 org.springdoc springdoc-openapi-ui - 1.7.0 + 1.8.0 org.springdoc springdoc-openapi-data-rest - 1.7.0 + 1.8.0 org.springframework.boot @@ -428,7 +419,7 @@ org.apache.sshd sshd-sftp - 2.8.0 + 2.13.2 org.powermock @@ -438,7 +429,7 @@ org.jacoco org.jacoco.agent - 0.8.11 + 0.8.12 org.pf4j @@ -478,7 +469,7 @@ org.liquibase liquibase-core - 4.17.2 + 4.29.1 @@ -502,7 +493,7 @@ org.springframework.data spring-data-commons - 2.7.5 + 3.3.2 @@ -534,7 +525,7 @@ org.apache.maven.plugins maven-release-plugin - 3.0.1 + 3.1.1 install @@ -542,7 +533,7 @@ org.codehaus.mojo properties-maven-plugin - 1.2.0 + 1.2.1 initialize @@ -560,7 +551,7 @@ org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.12 @@ -589,7 +580,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 ${java.version} ${java.version} @@ -602,7 +593,7 @@ org.projectlombok lombok - 1.18.30 + 1.18.34 org.projectlombok @@ -615,7 +606,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.3.1 2 true @@ -627,7 +618,7 @@ org.apache.maven.surefire surefire-junit4 - 3.2.5 + 3.3.1 @@ -688,7 +679,7 @@ org.openapitools openapi-generator-maven-plugin - 7.0.1 + 7.7.0 @@ -744,7 +735,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.10.0.2594 + 4.0.0.4121 diff --git a/src/main/java/fr/icdc/ebad/EbadApplication.java b/src/main/java/fr/icdc/ebad/EbadApplication.java index 30989da9..738b5ef5 100644 --- a/src/main/java/fr/icdc/ebad/EbadApplication.java +++ b/src/main/java/fr/icdc/ebad/EbadApplication.java @@ -13,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; import org.springframework.core.env.Environment; +import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -20,11 +21,14 @@ import java.net.UnknownHostException; import java.util.Arrays; +import static org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO; + @SpringBootApplication @ComponentScan(excludeFilters={@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value=SpringDocDataRestConfiguration.class)}) @EnableConfigurationProperties(EbadProperties.class) @EnableAsync @EnableScheduling +@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO) public class EbadApplication { private static final Logger APPLICATION_LOGGER = LoggerFactory.getLogger(EbadApplication.class); diff --git a/src/main/java/fr/icdc/ebad/config/DatabaseConfiguration.java b/src/main/java/fr/icdc/ebad/config/DatabaseConfiguration.java index 5df1dd2e..c9211661 100644 --- a/src/main/java/fr/icdc/ebad/config/DatabaseConfiguration.java +++ b/src/main/java/fr/icdc/ebad/config/DatabaseConfiguration.java @@ -1,6 +1,6 @@ package fr.icdc.ebad.config; -import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; +import com.fasterxml.jackson.datatype.hibernate6.Hibernate6Module; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @@ -14,7 +14,7 @@ @EnableTransactionManagement public class DatabaseConfiguration { @Bean - public Hibernate5Module hibernate5Module() { - return new Hibernate5Module(); + public Hibernate6Module hibernate5Module() { + return new Hibernate6Module(); } } diff --git a/src/main/java/fr/icdc/ebad/config/apidoc/CustomSpringDocDataRestConfiguration.java b/src/main/java/fr/icdc/ebad/config/apidoc/CustomSpringDocDataRestConfiguration.java index a3754ce2..e75efe5a 100644 --- a/src/main/java/fr/icdc/ebad/config/apidoc/CustomSpringDocDataRestConfiguration.java +++ b/src/main/java/fr/icdc/ebad/config/apidoc/CustomSpringDocDataRestConfiguration.java @@ -1,6 +1,7 @@ package fr.icdc.ebad.config.apidoc; import com.querydsl.core.types.Predicate; +import org.springdoc.core.SpringDocConfigProperties; import org.springdoc.core.customizers.DataRestDelegatingMethodParameterCustomizer; import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer; import org.springdoc.core.providers.RepositoryRestConfigurationProvider; @@ -62,7 +63,7 @@ class QuerydslProvider { QuerydslPredicateOperationCustomizer queryDslQuerydslPredicateOperationCustomizer(Optional querydslBindingsFactory) { if (querydslBindingsFactory.isPresent()) { getConfig().addRequestWrapperToIgnore(Predicate.class); - return new QuerydslPredicateOperationCustomizer(querydslBindingsFactory.get()); + return new QuerydslPredicateOperationCustomizer(querydslBindingsFactory.get(), new SpringDocConfigProperties()); } return null; } diff --git a/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java b/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java index a0855eb2..693640a3 100644 --- a/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java +++ b/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java @@ -24,10 +24,10 @@ @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class GlobalSetting { @Id - @Column(name = "key") + @Column(name = "`key`") private String key; - @Column(name = "value", nullable = false) + @Column(name = "`value`", nullable = false) private String value; @Column(name = "label", nullable = false) diff --git a/src/main/java/fr/icdc/ebad/repository/UserRepository.java b/src/main/java/fr/icdc/ebad/repository/UserRepository.java index 472cc64f..d1d00683 100644 --- a/src/main/java/fr/icdc/ebad/repository/UserRepository.java +++ b/src/main/java/fr/icdc/ebad/repository/UserRepository.java @@ -58,10 +58,10 @@ default void customize(QuerydslBindings bindings, QUser root) { @Query("select user from User user left join user.usageApplications usageApplication left join usageApplication.application application left join application.environnements environnement left join environnement.batchs batch where batch.id = :batch and user.login = :login and usageApplication.canManage = true") User findManagerFromBatch(@Param("batch") Long batch, @Param("login") String login); - @Query("select user from User user left join user.usageApplications usageApplication on user.id = usageApplication.user left join usageApplication.application application where application.id = :application and user.login = :login and usageApplication.canUse = true") + @Query("select user from User user left join user.usageApplications usageApplication on user.id = usageApplication.user.id left join usageApplication.application application where application.id = :application and user.login = :login and usageApplication.canUse = true") User findUserFromApplication(@Param("application") Long application, @Param("login") String login); - @Query("select user from User user left join user.usageApplications usageApplication on user.id = usageApplication.user left join usageApplication.application application where application.id = :application and user.login = :login and usageApplication.canManage = true") + @Query("select user from User user left join user.usageApplications usageApplication on user.id = usageApplication.user.id left join usageApplication.application application where application.id = :application and user.login = :login and usageApplication.canManage = true") User findManagerFromApplication(@Param("application") Long application, @Param("login") String login); @Query("select user from User user left join user.usageApplications usageApplication left join usageApplication.application application left join application.environnements environnement where environnement.id = :env and user.login = :login and usageApplication.canUse = true") diff --git a/src/main/java/fr/icdc/ebad/service/BatchService.java b/src/main/java/fr/icdc/ebad/service/BatchService.java index 47b961df..dcb0ef9d 100644 --- a/src/main/java/fr/icdc/ebad/service/BatchService.java +++ b/src/main/java/fr/icdc/ebad/service/BatchService.java @@ -14,6 +14,7 @@ import fr.icdc.ebad.repository.SchedulingRepository; import fr.icdc.ebad.security.SecurityUtils; import fr.icdc.ebad.service.util.EbadServiceException; +import org.jobrunr.jobs.JobId; import org.jobrunr.jobs.annotations.Job; import org.jobrunr.scheduling.JobScheduler; import org.slf4j.Logger; @@ -254,7 +255,7 @@ public void deleteBatch(Long id) { public void deleteScheduledJobFromBatch(Long batchId){ List schedulings = schedulingRepository.findAllByBatchId(batchId); schedulings.forEach(scheduling -> { - jobScheduler.delete(String.valueOf(scheduling.getId())); + jobScheduler.deleteRecurringJob(String.valueOf(scheduling.getId())); schedulingRepository.delete(scheduling); }); } diff --git a/src/main/java/fr/icdc/ebad/service/EnvironnementService.java b/src/main/java/fr/icdc/ebad/service/EnvironnementService.java index c2206eae..3625a920 100644 --- a/src/main/java/fr/icdc/ebad/service/EnvironnementService.java +++ b/src/main/java/fr/icdc/ebad/service/EnvironnementService.java @@ -24,6 +24,7 @@ import fr.icdc.ebad.service.util.EbadServiceException; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotNull; +import org.jobrunr.jobs.JobId; import org.jobrunr.scheduling.JobScheduler; import org.pf4j.PluginRuntimeException; import org.pf4j.PluginWrapper; @@ -154,7 +155,7 @@ public String getEspaceDisque(Long id) { public void deleteScheduledJobFromEnvironment(Long environmentId){ List schedulings = schedulingRepository.findAllByEnvironnementId(environmentId); schedulings.forEach(scheduling -> { - jobScheduler.delete(String.valueOf(scheduling.getId())); + jobScheduler.deleteRecurringJob(String.valueOf(scheduling.getId())); schedulingRepository.delete(scheduling); }); } diff --git a/src/main/java/fr/icdc/ebad/service/SchedulingService.java b/src/main/java/fr/icdc/ebad/service/SchedulingService.java index 3cd78b01..38c6be03 100644 --- a/src/main/java/fr/icdc/ebad/service/SchedulingService.java +++ b/src/main/java/fr/icdc/ebad/service/SchedulingService.java @@ -65,7 +65,7 @@ public Scheduling saveAndRun(Long batchId, Long environnementId, String paramete @Transactional public void remove(Long schedulingId) { Scheduling scheduling = schedulingRepository.getById(schedulingId); - jobScheduler.delete(String.valueOf(scheduling.getId())); + jobScheduler.deleteRecurringJob(String.valueOf(scheduling.getId())); schedulingRepository.delete(scheduling); } diff --git a/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java b/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java index e2692623..9408099a 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java +++ b/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java @@ -3,13 +3,13 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; +import jakarta.validation.ConstraintViolation; import lombok.Data; import org.hibernate.validator.internal.engine.path.PathImpl; import org.springframework.http.HttpStatus; import org.springframework.validation.FieldError; import org.springframework.validation.ObjectError; -import javax.validation.ConstraintViolation; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java b/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java index 5ff55ea4..01915aea 100644 --- a/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java @@ -19,6 +19,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -196,7 +197,7 @@ public void getAllAccreditationRequestToAnswerAdmin() { accreditationRequestList.add(accreditationRequest2); PageRequest pageRequest = PageRequest.of(0, 10); - when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList)); + when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList, Pageable.ofSize(accreditationRequestList.size()), accreditationRequestList.size())); Page result = accreditationRequestService.getAllAccreditationRequestToAnswer(pageRequest); @@ -221,7 +222,7 @@ public void getAllAccreditationRequestToAnswer() { application2.setId(2L); applications.add(application2); - PageImpl applicationPage = new PageImpl<>(applications); + PageImpl applicationPage = new PageImpl<>(applications, Pageable.ofSize(applications.size()), applications.size()); when(applicationRepository.findAllManagedByUser(any(), any())).thenReturn(applicationPage); @@ -248,7 +249,7 @@ public void getAllAccreditationRequestToAnswer() { accreditationRequestList.add(accreditationRequest2); PageRequest pageRequest = PageRequest.of(0, 10); - when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList)); + when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList, Pageable.ofSize(accreditationRequestList.size()), accreditationRequestList.size())); Page result = accreditationRequestService.getAllAccreditationRequestToAnswer(pageRequest); @@ -286,7 +287,7 @@ public void getMyAccreditationRequest() { accreditationRequestList.add(accreditationRequest2); PageRequest pageRequest = PageRequest.of(0, 10); - when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList)); + when(accreditationRequestRepository.findAll(any(Predicate.class), eq(pageRequest))).thenReturn(new PageImpl<>(accreditationRequestList, Pageable.ofSize(accreditationRequestList.size()), accreditationRequestList.size())); Page result = accreditationRequestService.getMyAccreditationRequest(pageRequest); diff --git a/src/test/java/fr/icdc/ebad/service/ApiTokenServiceTest.java b/src/test/java/fr/icdc/ebad/service/ApiTokenServiceTest.java index b98e79c7..fb09e5a7 100644 --- a/src/test/java/fr/icdc/ebad/service/ApiTokenServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/ApiTokenServiceTest.java @@ -48,7 +48,7 @@ public void findTokenByUser() { ApiToken apiToken2 = ApiToken.builder().id(2L).build(); apiTokens.add(apiToken1); apiTokens.add(apiToken2); - Page apiTokenPage = new PageImpl<>(apiTokens); + Page apiTokenPage = new PageImpl<>(apiTokens, Pageable.ofSize(apiTokens.size()), apiTokens.size()); when(apiTokenRepository.findAllByUserLogin(eq("myLogin"), eq(pageable))).thenReturn(apiTokenPage); Page results = apiTokenService.findTokenByUser("myLogin", pageable); diff --git a/src/test/java/fr/icdc/ebad/service/BatchServiceTest.java b/src/test/java/fr/icdc/ebad/service/BatchServiceTest.java index be3cfb69..f6d2e257 100644 --- a/src/test/java/fr/icdc/ebad/service/BatchServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/BatchServiceTest.java @@ -297,7 +297,7 @@ public void removeBatchsWithoutEnvironnement() { verify(logBatchRepository).deleteAllByBatchId(eq(1L)); verify(logBatchRepository).deleteAllByBatchId(eq(2L)); - verify(jobScheduler, times(1)).delete(eq("10")); + verify(jobScheduler, times(1)).deleteRecurringJob(eq("10")); verify(schedulingRepository, times(1)).delete(eq(scheduling)); verify(batchRepository).delete(batch1); @@ -440,7 +440,7 @@ public void testDeleteBatchById() { batchService.deleteBatch(1L); verify(logBatchRepository).deleteAllByBatchId(1L); verify(batchRepository).deleteById(1L); - verify(jobScheduler, times(1)).delete(eq("10")); + verify(jobScheduler, times(1)).deleteRecurringJob(eq("10")); verify(schedulingRepository, times(1)).delete(eq(scheduling)); } @@ -459,7 +459,7 @@ public void deleteBatch() { verify(logBatchRepository).deleteAllByBatchId(1L); verify(batchRepository).deleteById(1L); - verify(jobScheduler, times(1)).delete(eq("10")); + verify(jobScheduler, times(1)).deleteRecurringJob(eq("10")); verify(schedulingRepository, times(1)).delete(eq(scheduling)); } diff --git a/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java b/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java index 133d5547..e17c2c28 100644 --- a/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java @@ -167,7 +167,7 @@ public void deleteEnvironnement() { verify(batchRepository, times(1)).deleteAll(eq(environnement.getBatchs())); verify(directoryRepository, times(1)).deleteByEnvironnement(eq(environnement)); verify(environnementRepository, times(1)).delete(eq(environnement)); - verify(jobScheduler, times(1)).delete(eq("10")); + verify(jobScheduler, times(1)).deleteRecurringJob(eq("10")); verify(schedulingRepository, times(1)).delete(eq(scheduling)); } @@ -204,7 +204,7 @@ public void deleteEnvironnement2() { verify(batchRepository, times(0)).deleteAll(eq(environnement.getBatchs())); verify(directoryRepository, times(1)).deleteByEnvironnement(eq(environnement)); verify(environnementRepository, times(1)).delete(eq(environnement)); - verify(jobScheduler, times(1)).delete(eq("10")); + verify(jobScheduler, times(1)).deleteRecurringJob(eq("10")); verify(schedulingRepository, times(1)).delete(eq(scheduling)); } diff --git a/src/test/java/fr/icdc/ebad/web/rest/AccreditationRequestResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/AccreditationRequestResourceTest.java index 393e18e4..a517bf8c 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/AccreditationRequestResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/AccreditationRequestResourceTest.java @@ -9,6 +9,7 @@ import fr.icdc.ebad.service.AccreditationRequestService; import fr.icdc.ebad.web.rest.dto.CreationAccreditationRequestDto; import fr.icdc.ebad.web.rest.dto.ResponseAccreditationRequestDto; +import fr.icdc.ebad.web.rest.errors.ExceptionTranslator; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,6 +19,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; @@ -38,6 +40,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -53,6 +56,9 @@ public class AccreditationRequestResourceTest { @Autowired private AccreditationRequestResource accreditationRequestResource; + @Autowired + private ExceptionTranslator exceptionTranslator; + @Autowired private WebApplicationContext context; @@ -64,6 +70,7 @@ public void setup() { this.restMvc = MockMvcBuilders .standaloneSetup(accreditationRequestResource) .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .setControllerAdvice(exceptionTranslator) .build(); objectMapper.registerModule(new JavaTimeModule()); } @@ -93,12 +100,13 @@ public void findAll() throws Exception { accreditationRequestList.add(accreditationRequest1); accreditationRequestList.add(accreditationRequest2); - Page accreditationRequestPage = new PageImpl<>(accreditationRequestList); + Page accreditationRequestPage = new PageImpl<>(accreditationRequestList, Pageable.ofSize(2), 2); + when(accreditationRequestService.getAllAccreditationRequestToAnswer(any())).thenReturn(accreditationRequestPage); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/accreditation-requests/need-answer"); - restMvc.perform(builder) + restMvc.perform(builder).andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.content").isArray()) .andExpect(jsonPath("$.content", hasSize(2))) @@ -139,7 +147,7 @@ public void findAllMyRequest() throws Exception { accreditationRequestList.add(accreditationRequest1); accreditationRequestList.add(accreditationRequest2); - Page accreditationRequestPage = new PageImpl<>(accreditationRequestList); + Page accreditationRequestPage = new PageImpl<>(accreditationRequestList, Pageable.ofSize(accreditationRequestList.size()), accreditationRequestList.size()); when(accreditationRequestService.getMyAccreditationRequest(any())).thenReturn(accreditationRequestPage); diff --git a/src/test/java/fr/icdc/ebad/web/rest/ApiTokenResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/ApiTokenResourceTest.java index 6859bb05..74dfd1c7 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/ApiTokenResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/ApiTokenResourceTest.java @@ -74,7 +74,7 @@ public void findToken() throws Exception { ApiToken apiToken2 = ApiToken.builder().id(2L).build(); apiTokens.add(apiToken1); apiTokens.add(apiToken2); - Page apiTokenPage = new PageImpl<>(apiTokens); + Page apiTokenPage = new PageImpl<>(apiTokens, Pageable.ofSize(apiTokens.size()), apiTokens.size()); when(apiTokenService.findTokenByUser(eq("user"), ArgumentMatchers.any(Pageable.class))).thenReturn(apiTokenPage); restMvc.perform(builder) diff --git a/src/test/java/fr/icdc/ebad/web/rest/ApplicationResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/ApplicationResourceTest.java index 22783c21..2174f857 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/ApplicationResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/ApplicationResourceTest.java @@ -19,6 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.http.MediaType; @@ -103,7 +104,7 @@ public void findApplication() throws Exception { Application application2 = new Application(); application2.setId(2L); applications.add(application2); - PageImpl applicationPage = new PageImpl<>(applications); + PageImpl applicationPage = new PageImpl<>(applications, Pageable.ofSize(applications.size()), applications.size()); when(applicationService.findApplication(any(), any())).thenReturn(applicationPage); @@ -131,7 +132,7 @@ public void getAll() throws Exception { Application application2 = new Application(); application2.setId(2L); applications.add(application2); - PageImpl applicationPage = new PageImpl<>(applications); + PageImpl applicationPage = new PageImpl<>(applications, Pageable.ofSize(applications.size()), applications.size()); when(applicationService.getAllApplicationsUsed(any(), eq("user"))).thenReturn(applicationPage); when(userRepository.findUserFromApplication(anyLong(), anyString())).thenReturn(new User()); @@ -160,7 +161,8 @@ public void getAllWrite() throws Exception { application2.setId(2L); applications.add(application2); - PageImpl applicationPage = new PageImpl<>(applications); + PageImpl applicationPage = new PageImpl<>(applications, Pageable.ofSize(applications.size()), applications.size()); + when(applicationService.getAllApplicationsManaged(any(), eq("dtrouillet"))).thenReturn(applicationPage); when(userRepository.findManagerFromApplication(eq(1L), eq("dtrouillet"))).thenReturn(new User()); @@ -188,7 +190,7 @@ public void getAllManage() throws Exception { application2.setId(2L); applications.add(application2); - PageImpl applicationPage = new PageImpl<>(applications); + PageImpl applicationPage = new PageImpl<>(applications, Pageable.ofSize(applications.size()), applications.size()); when(applicationService.getAllApplications(any(), any())).thenReturn(applicationPage); restMvc.perform(builder) diff --git a/src/test/java/fr/icdc/ebad/web/rest/ChaineResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/ChaineResourceTest.java index b74882f8..f7e3b760 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/ChaineResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/ChaineResourceTest.java @@ -21,6 +21,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.http.MediaType; @@ -96,7 +97,7 @@ public void getAllFromEnv() throws Exception { chaines.add(chaine1); chaines.add(chaine2); - Page chainePage = new PageImpl<>(chaines); + Page chainePage = new PageImpl<>(chaines, Pageable.ofSize(chaines.size()), chaines.size()); when(chaineService.getAllChaineFromEnvironmentWithPageable(any(), any(), argThat((environnement -> environnement.getId().equals(1L))))).thenReturn(chainePage); when(permissionEnvironnement.canRead(eq(1L), any())).thenReturn(true); diff --git a/src/test/java/fr/icdc/ebad/web/rest/DirectoryResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/DirectoryResourceTest.java index cd7d75ba..6bab2bdc 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/DirectoryResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/DirectoryResourceTest.java @@ -16,6 +16,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.security.core.userdetails.UserDetails; @@ -100,7 +101,7 @@ public void getAllFromEnv() throws Exception { Directory directory2 = Directory.builder().id(3L).name("directory2").build(); directoryList.add(directory1); directoryList.add(directory2); - Page directoryPage = new PageImpl<>(directoryList); + Page directoryPage = new PageImpl<>(directoryList, Pageable.ofSize(directoryList.size()), directoryList.size()); when(directoryService.findDirectoryFromEnvironnement(any(), any(), eq(1L))).thenReturn(directoryPage); when(permissionEnvironnement.canRead(eq(1L), any())).thenReturn(true); diff --git a/src/test/java/fr/icdc/ebad/web/rest/EnvironnementResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/EnvironnementResourceTest.java index 8b614b47..42069eec 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/EnvironnementResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/EnvironnementResourceTest.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.security.test.context.support.WithMockUser; @@ -77,7 +78,7 @@ public void getEnvironmentsFromApp() throws Exception { List environnementList = new ArrayList<>(); environnementList.add(environnement1); environnementList.add(environnement2); - Page environnementPage = new PageImpl<>(environnementList); + Page environnementPage = new PageImpl<>(environnementList, Pageable.ofSize(environnementList.size()), environnementList.size()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/environments?applicationId=1"); when(environnementService.getEnvironmentFromApp(eq(1L), any(Predicate.class), any())).thenReturn(environnementPage); when(permissionApplication.canRead(eq(1L), any())).thenReturn(true); diff --git a/src/test/java/fr/icdc/ebad/web/rest/IdentityResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/IdentityResourceTest.java index b5836311..5b3c5e3f 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/IdentityResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/IdentityResourceTest.java @@ -126,7 +126,7 @@ public void getAllIdentities() throws Exception { identities.add(identity2); identities.add(identity3); - Page identityPage = new PageImpl<>(identities); + Page identityPage = new PageImpl<>(identities, Pageable.ofSize(identities.size()), identities.size()); when(identityService.findWithoutApp(any(Predicate.class), any(Pageable.class))).thenReturn(identityPage); restMvc.perform( @@ -162,7 +162,7 @@ public void getAllIdentitiesWithApplication() throws Exception { identities.add(identity2); identities.add(identity3); - Page identityPage = new PageImpl<>(identities); + Page identityPage = new PageImpl<>(identities, Pageable.ofSize(identities.size()), identities.size()); when(identityService.findAllByApplication(eq(1L), any(Predicate.class), any(Pageable.class))).thenReturn(identityPage); restMvc.perform( diff --git a/src/test/java/fr/icdc/ebad/web/rest/LogsResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/LogsResourceTest.java index 7e918ccb..4dc1d860 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/LogsResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/LogsResourceTest.java @@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.security.test.context.support.WithMockUser; @@ -86,7 +87,7 @@ public void getAllLog() throws Exception { logBatches.add(logBatch1); logBatches.add(logBatch2); - PageImpl logBatchPage = new PageImpl<>(logBatches); + PageImpl logBatchPage = new PageImpl<>(logBatches, Pageable.ofSize(logBatches.size()), logBatches.size()); when(logBatchService.getAllLogBatchWithPageable(any(), any())).thenReturn(logBatchPage); @@ -114,7 +115,7 @@ public void getAllLogFromEnv() throws Exception { logBatches.add(logBatch1); logBatches.add(logBatch2); - PageImpl logBatchPage = new PageImpl<>(logBatches); + PageImpl logBatchPage = new PageImpl<>(logBatches, Pageable.ofSize(logBatches.size()), logBatches.size()); when(logBatchService.getAllLogBatchWithPageable(any(), any())).thenReturn(logBatchPage); when(permissionEnvironnement.canRead(eq(1L), any())).thenReturn(true); @@ -142,7 +143,7 @@ public void getAllLogFromEnvBatch() throws Exception { logBatches.add(logBatch1); logBatches.add(logBatch2); - PageImpl logBatchPage = new PageImpl<>(logBatches); + PageImpl logBatchPage = new PageImpl<>(logBatches, Pageable.ofSize(logBatches.size()), logBatches.size()); when(logBatchService.getAllLogBatchWithPageable(any(), any())).thenReturn(logBatchPage); when(permissionEnvironnement.canRead(eq(1L), any())).thenReturn(true); diff --git a/src/test/java/fr/icdc/ebad/web/rest/NewResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/NewResourceTest.java index c5229590..b30d1cef 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/NewResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/NewResourceTest.java @@ -14,6 +14,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ActiveProfiles; @@ -76,7 +77,7 @@ public void getAll() throws Exception { Actualite actualite2 = new Actualite(); actualite2.setId(2L); actualites.add(actualite2); - Page actualitePage = new PageImpl<>(actualites); + Page actualitePage = new PageImpl<>(actualites, Pageable.ofSize(actualites.size()), actualites.size()); when(newService.getAllActualites(ArgumentMatchers.any())).thenReturn(actualitePage); restMvc.perform(builder) @@ -100,7 +101,7 @@ public void getAllNonDraft() throws Exception { Actualite actualite2 = new Actualite(); actualite2.setId(2L); actualites.add(actualite2); - Page actualitePage = new PageImpl<>(actualites); + Page actualitePage = new PageImpl<>(actualites, Pageable.ofSize(actualites.size()), actualites.size()); when(newService.getAllActualitesPubliees(ArgumentMatchers.any())).thenReturn(actualitePage); diff --git a/src/test/java/fr/icdc/ebad/web/rest/NormResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/NormResourceTest.java index ac7bed99..ae66ffd7 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/NormResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/NormResourceTest.java @@ -77,7 +77,7 @@ public void getAll() throws Exception { normeList.add(norme1); normeList.add(norme2); - Page normePage = new PageImpl<>(normeList); + Page normePage = new PageImpl<>(normeList, Pageable.ofSize(normeList.size()), normeList.size()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/norms"); when(normeService.getAllNormes(any(Predicate.class), any(Pageable.class))).thenReturn(normePage); @@ -105,7 +105,7 @@ public void getAllList() throws Exception { normeList.add(norme1); normeList.add(norme2); - Page normePage = new PageImpl<>(normeList); + Page normePage = new PageImpl<>(normeList, Pageable.ofSize(normeList.size()), normeList.size()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/norms/name"); when(normeService.getAllNormes(any(Predicate.class), any(Pageable.class))).thenReturn(normePage); diff --git a/src/test/java/fr/icdc/ebad/web/rest/SchedulingResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/SchedulingResourceTest.java index 663e7596..173eee13 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/SchedulingResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/SchedulingResourceTest.java @@ -17,6 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; @@ -140,7 +141,7 @@ public void listByEnvironment() throws Exception { schedulings.add(scheduling1); schedulings.add(scheduling2); - PageImpl page = new PageImpl<>(schedulings); + PageImpl page = new PageImpl<>(schedulings, Pageable.ofSize(schedulings.size()), schedulings.size()); when(permissionEnvironnement.canRead(eq(2L), any())).thenReturn(true); when(schedulingService.listByEnvironment(eq(2L), any())).thenReturn(page); @@ -191,7 +192,7 @@ public void listAll() throws Exception { schedulings.add(scheduling1); schedulings.add(scheduling2); - PageImpl page = new PageImpl<>(schedulings); + PageImpl page = new PageImpl<>(schedulings, Pageable.ofSize(schedulings.size()), schedulings.size()); when(schedulingService.listAll(any())).thenReturn(page); restMvc.perform(builder) diff --git a/src/test/java/fr/icdc/ebad/web/rest/TypeFichierResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/TypeFichierResourceTest.java index edfdd29c..69f9cbee 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/TypeFichierResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/TypeFichierResourceTest.java @@ -19,6 +19,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.http.MediaType; @@ -93,7 +94,7 @@ public void getAllFromEnv() throws Exception { typeFichiers.add(typeFichier1); typeFichiers.add(typeFichier2); - Page typeFichierPage = new PageImpl<>(typeFichiers); + Page typeFichierPage = new PageImpl<>(typeFichiers, Pageable.ofSize(typeFichiers.size()), typeFichiers.size()); when(typeFichierService.getTypeFichierFromApplication(any(), any(), eq(1L))).thenReturn(typeFichierPage); when(permissionApplication.canRead(eq(1L), any())).thenReturn(true); diff --git a/src/test/java/fr/icdc/ebad/web/rest/UserResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/UserResourceTest.java index f446f5a8..8fa6945a 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/UserResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/UserResourceTest.java @@ -14,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.security.test.context.support.WithMockUser; @@ -108,7 +109,7 @@ public void getAll() throws Exception { User user2 = new User(); user2.setId(2L); users.add(user2); - PageImpl userPage = new PageImpl<>(users); + PageImpl userPage = new PageImpl<>(users, Pageable.ofSize(users.size()), users.size()); when(userService.getAllUsers(any(), any())).thenReturn(userPage); diff --git a/src/test/resources/nop.sql b/src/test/resources/nop.sql index 8b2153aa..bfa23e9f 100644 --- a/src/test/resources/nop.sql +++ b/src/test/resources/nop.sql @@ -1,7 +1,7 @@ -INSERT INTO t_global_setting (key, value, description, label) VALUES ('APPLICATION_IMPORT_ENABLED', false, 'Allow to import applications from plugin', 'Application import enabled'); -INSERT INTO t_global_setting (key, value, description, label) VALUES ('ENVIRONMENT_IMPORT_ENABLED', false, 'Allow to import environments from plugin', 'Environment import enabled'); -INSERT INTO t_global_setting (key, value, description, label) VALUES ('ENVIRONMENT_CREATE_ENABLED', true, 'Allow to create new environment', 'Environment creation enabled'); -INSERT INTO t_global_setting (key, value, description, label) VALUES ('APPLICATION_CREATE_ENABLED', true, 'Allow to create new application', 'Application creation enabled'); +INSERT INTO t_global_setting (`key`, `value`, description, label) VALUES ('APPLICATION_IMPORT_ENABLED', false, 'Allow to import applications from plugin', 'Application import enabled'); +INSERT INTO t_global_setting (`key`, `value`, description, label) VALUES ('ENVIRONMENT_IMPORT_ENABLED', false, 'Allow to import environments from plugin', 'Environment import enabled'); +INSERT INTO t_global_setting (`key`, `value`, description, label) VALUES ('ENVIRONMENT_CREATE_ENABLED', true, 'Allow to create new environment', 'Environment creation enabled'); +INSERT INTO t_global_setting (`key`, `value`, description, label) VALUES ('APPLICATION_CREATE_ENABLED', true, 'Allow to create new application', 'Application creation enabled'); INSERT INTO t_authority (name) VALUES ('ROLE_USER'); INSERT INTO t_authority (name)VALUES ('ROLE_ADMIN');