From 4e8d2ca2a61de3a97fbafa53c460e88059d9198b Mon Sep 17 00:00:00 2001 From: Antonio Lorusso Date: Mon, 9 Oct 2023 12:41:24 +0100 Subject: [PATCH 1/3] add model, and enums to be able to grab advert --- .github/workflows/feature.yml | 2 + .../dto/api/GetGrandAdvertDto.java | 24 +++ .../enums/GrantAdvertPageResponseStatus.java | 7 + .../GrantAdvertSectionResponseStatus.java | 7 + .../applybackend/enums/GrantAdvertStatus.java | 7 + .../gap/applybackend/model/GapUser.java | 35 ++++ .../gap/applybackend/model/GrantAdmin.java | 46 +++++ .../gap/applybackend/model/GrantAdvert.java | 125 ++++++++++++ .../model/GrantAdvertPageResponse.java | 32 +++ .../model/GrantAdvertQuestionResponse.java | 22 ++ .../model/GrantAdvertResponse.java | 44 ++++ .../model/GrantAdvertSectionResponse.java | 33 +++ .../repository/GrantAdvertRepository.java | 11 + .../GrantApplicationRepository.java | 7 +- .../service/GrantAdvertService.java | 52 +++++ .../service/GrantApplicationService.java | 12 ++ .../web/GrantAdvertController.java | 40 ++++ .../service/GrantAdvertServiceTest.java | 190 ++++++++++++++++++ .../service/GrantApplicationServiceTest.java | 61 +++++- .../web/GrantAdvertControllerTest.java | 29 +++ 20 files changed, 780 insertions(+), 6 deletions(-) create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetGrandAdvertDto.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertPageResponseStatus.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertSectionResponseStatus.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertStatus.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GapUser.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdmin.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvert.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertPageResponse.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertQuestionResponse.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertResponse.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertSectionResponse.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantAdvertRepository.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java create mode 100644 src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java create mode 100644 src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertServiceTest.java create mode 100644 src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertControllerTest.java diff --git a/.github/workflows/feature.yml b/.github/workflows/feature.yml index 20ca9741..43153172 100644 --- a/.github/workflows/feature.yml +++ b/.github/workflows/feature.yml @@ -8,12 +8,14 @@ on: - bug/** - GAP-** - feat/** + - TMI2-** pull_request: branches: - feature/** - AFG-** - bug/** - GAP-** + - TMI2-** jobs: build: diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetGrandAdvertDto.java b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetGrandAdvertDto.java new file mode 100644 index 00000000..2828a3a3 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetGrandAdvertDto.java @@ -0,0 +1,24 @@ +package gov.cabinetoffice.gap.applybackend.dto.api; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Data +public class GetGrandAdvertDto { + private UUID id; + private String externalSubmissionUrl; + private int version; + //need jsonProperty because Jackson removes the 'is' from 'isInternal' + @JsonProperty("isInternal") + private boolean isInternal; + private Integer grantApplicationId; + private Integer grantSchemeId; +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertPageResponseStatus.java b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertPageResponseStatus.java new file mode 100644 index 00000000..0a3f33e0 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertPageResponseStatus.java @@ -0,0 +1,7 @@ +package gov.cabinetoffice.gap.applybackend.enums; + +public enum GrantAdvertPageResponseStatus { + + NOT_STARTED, IN_PROGRESS, COMPLETED, CHANGED + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertSectionResponseStatus.java b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertSectionResponseStatus.java new file mode 100644 index 00000000..707868c5 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertSectionResponseStatus.java @@ -0,0 +1,7 @@ +package gov.cabinetoffice.gap.applybackend.enums; + +public enum GrantAdvertSectionResponseStatus { + + NOT_STARTED, IN_PROGRESS, COMPLETED, CHANGED + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertStatus.java b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertStatus.java new file mode 100644 index 00000000..9de38928 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/enums/GrantAdvertStatus.java @@ -0,0 +1,7 @@ +package gov.cabinetoffice.gap.applybackend.enums; + +public enum GrantAdvertStatus { + + DRAFT, SCHEDULED, PUBLISHED, UNPUBLISHED, UNSCHEDULED + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GapUser.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GapUser.java new file mode 100644 index 00000000..397da874 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GapUser.java @@ -0,0 +1,35 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "gap_user") +@Getter +@Setter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class GapUser { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "gap_user_id") + private Integer id; + + @Column(name = "user_sub") + private String userSub; + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdmin.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdmin.java new file mode 100644 index 00000000..18a275b9 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdmin.java @@ -0,0 +1,46 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "grant_admin") +@Getter +@Setter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class GrantAdmin { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "grant_admin_id") + private Integer id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "funder_id", referencedColumnName = "funder_id") + @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) + private FundingOrganisation funder; + + @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @JoinColumn(name = "user_id", referencedColumnName = "gap_user_id") + private GapUser gapUser; + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvert.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvert.java new file mode 100644 index 00000000..68066b2e --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvert.java @@ -0,0 +1,125 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import gov.cabinetoffice.gap.applybackend.enums.GrantAdvertStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.hibernate.Hibernate; +import org.hibernate.annotations.Type; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.time.Instant; +import java.util.Objects; +import java.util.UUID; + +@EntityListeners(AuditingEntityListener.class) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "grant_advert") +public class GrantAdvert extends BaseEntity { + + @Id + @GeneratedValue + @Column(name = "grant_advert_id") + private UUID id; + + @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY) + @JoinColumn(name = "scheme_id", nullable = false) + @ToString.Exclude + @JsonIgnoreProperties({"hibernateLazyInitializer"}) + private GrantScheme scheme; + + @Column(name = "version", nullable = false) + private Integer version; + + @CreatedDate + @Column(name = "created", nullable = false) + private Instant created; + + @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY) + @JoinColumn(name = "created_by", referencedColumnName = "grant_admin_id", nullable = false) + @ToString.Exclude + @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) + private GrantAdmin createdBy; + + @LastModifiedDate + @Column(name = "last_updated") + private Instant lastUpdated; + + @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY) + @JoinColumn(name = "last_updated_by", referencedColumnName = "grant_admin_id") + @ToString.Exclude + @JsonIgnoreProperties({"hibernateLazyInitializer"}) + private GrantAdmin lastUpdatedBy; + + @Column(name = "opening_date") + private Instant openingDate; + + @Column(name = "closing_date") + private Instant closingDate; + + @Column(name = "first_published_date") + private Instant firstPublishedDate; + + @Column(name = "last_published_date") + private Instant lastPublishedDate; + + @Column(name = "unpublished_date") + private Instant unpublishedDate; + + @Column(name = "status", nullable = false) + @Enumerated(EnumType.STRING) + private GrantAdvertStatus status; + + @Column(name = "contentful_entry_id", unique = true) + private String contentfulEntryId; + + @Column(name = "contentful_slug", unique = true) + private String contentfulSlug; + + @Column(name = "grant_advert_name") + private String grantAdvertName; + + @Type(type = "json") + @Column(name = "response", columnDefinition = "json") + private GrantAdvertResponse response; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) + return false; + GrantAdvert that = (GrantAdvert) o; + return id != null && Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return getClass().hashCode(); + } + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertPageResponse.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertPageResponse.java new file mode 100644 index 00000000..9dfb9d7a --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertPageResponse.java @@ -0,0 +1,32 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import gov.cabinetoffice.gap.applybackend.enums.GrantAdvertPageResponseStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GrantAdvertPageResponse { + + @Builder.Default + private List questions = new ArrayList<>(); + + private String id; + + private GrantAdvertPageResponseStatus status; + + public Optional getQuestionById(String questionId) { + return questions.stream().filter(page -> Objects.equals(page.getId(), questionId)).findFirst(); + + } + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertQuestionResponse.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertQuestionResponse.java new file mode 100644 index 00000000..8cdbce36 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertQuestionResponse.java @@ -0,0 +1,22 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GrantAdvertQuestionResponse { + + private String id; + + private Boolean seen; + + private String response; + + private String[] multiResponse; + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertResponse.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertResponse.java new file mode 100644 index 00000000..f072c8ac --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertResponse.java @@ -0,0 +1,44 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GrantAdvertResponse { + + @Builder.Default + private List sections = new ArrayList<>(); + + public Optional getSectionById(String sectionId) { + return sections.stream().filter(section -> Objects.equals(section.getId(), sectionId)).findFirst(); + } + + public String nullCheckSingleResponse(String sectionId, String pageId, String questionId) { + + Optional grantAdvertQuestionResponse = getSectionById(sectionId) + .flatMap(section -> section.getPageById(pageId)).flatMap(page -> page.getQuestionById(questionId)); + + return grantAdvertQuestionResponse.map(GrantAdvertQuestionResponse::getResponse).orElse(""); + + } + + public String[] nullCheckMultiResponse(String sectionId, String pageId, String questionId) { + + Optional grantAdvertQuestionResponse = getSectionById(sectionId) + .flatMap(section -> section.getPageById(pageId)).flatMap(page -> page.getQuestionById(questionId)); + + return grantAdvertQuestionResponse.map(GrantAdvertQuestionResponse::getMultiResponse).orElse(null); + + } + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertSectionResponse.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertSectionResponse.java new file mode 100644 index 00000000..80c9f2fa --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAdvertSectionResponse.java @@ -0,0 +1,33 @@ +package gov.cabinetoffice.gap.applybackend.model; + +import gov.cabinetoffice.gap.applybackend.enums.GrantAdvertSectionResponseStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GrantAdvertSectionResponse { + + @Builder.Default + private List pages = new ArrayList<>(); + + private String id; + + @Builder.Default + private GrantAdvertSectionResponseStatus status = GrantAdvertSectionResponseStatus.NOT_STARTED; + + public Optional getPageById(String pageId) { + return this.pages.stream().filter(page -> Objects.equals(page.getId(), pageId)).findFirst(); + + } + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantAdvertRepository.java b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantAdvertRepository.java new file mode 100644 index 00000000..351619e9 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantAdvertRepository.java @@ -0,0 +1,11 @@ +package gov.cabinetoffice.gap.applybackend.repository; + +import gov.cabinetoffice.gap.applybackend.model.GrantAdvert; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; +import java.util.UUID; + +public interface GrantAdvertRepository extends JpaRepository { + Optional findByContentfulSlug(String contentfulSlug); +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicationRepository.java b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicationRepository.java index 2b190dd4..b66fe928 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicationRepository.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicationRepository.java @@ -2,10 +2,13 @@ import gov.cabinetoffice.gap.applybackend.model.GrantApplication; -import gov.cabinetoffice.gap.applybackend.model.SubmissionDefinition; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; + +import java.util.Optional; public interface GrantApplicationRepository extends JpaRepository { + + Optional findByGrantScheme(GrantScheme grantScheme); } diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java new file mode 100644 index 00000000..fc6b88f0 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java @@ -0,0 +1,52 @@ +package gov.cabinetoffice.gap.applybackend.service; + + +import gov.cabinetoffice.gap.applybackend.dto.api.GetGrandAdvertDto; +import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvert; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvertQuestionResponse; +import gov.cabinetoffice.gap.applybackend.repository.GrantAdvertRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Slf4j +public class GrantAdvertService { + + @Autowired + GrantAdvertRepository grantAdvertRepository; + + @Autowired + GrantApplicationService grantApplicationService; + + protected static String getExternalSubmissionUrl(GrantAdvert advert) { + return advert.getResponse().getSections().stream() + .filter(section -> section.getId().equals("howToApply")) + .flatMap(section -> section.getPages().stream()) + .flatMap(page -> page.getQuestions().stream()) + .filter(question -> question.getId().equals("grantWebpageUrl")) + .map(GrantAdvertQuestionResponse::getResponse) + .findFirst().orElse(""); + } + + public GetGrandAdvertDto getAdvertByContentfulSlug(String contentfulSlug) { + + final GrantAdvert advert = grantAdvertRepository.findByContentfulSlug(contentfulSlug) + .orElseThrow(() -> new NotFoundException("Advert with slug " + contentfulSlug + " not found")); + log.debug("Advert with slug {} found", contentfulSlug); + final boolean isInternal = grantApplicationService.doesSchemeHaveApplication(advert.getScheme()); + final Integer grantApplicationId = grantApplicationService.getGrantApplicationId(advert.getScheme()); + return GetGrandAdvertDto.builder() + .id(advert.getId()) + .version(advert.getVersion()) + .externalSubmissionUrl(getExternalSubmissionUrl(advert)) + .isInternal(isInternal) + .grantApplicationId(grantApplicationId) + .grantSchemeId(advert.getScheme().getId()) + .build(); + } + +} diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationService.java index fd3e0e13..2ece5e7f 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationService.java @@ -3,10 +3,13 @@ import gov.cabinetoffice.gap.applybackend.enums.GrantApplicantStatus; import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; import gov.cabinetoffice.gap.applybackend.repository.GrantApplicationRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @RequiredArgsConstructor @Service public class GrantApplicationService { @@ -21,4 +24,13 @@ public GrantApplication getGrantApplicationById(final int applicationId) { public boolean isGrantApplicationPublished(final int applicationId) { return getGrantApplicationById(applicationId).getApplicationStatus().equals(GrantApplicantStatus.PUBLISHED); } + + public boolean doesSchemeHaveApplication(final GrantScheme grantScheme) { + return grantApplicationRepository.findByGrantScheme(grantScheme).isPresent(); + } + + public Integer getGrantApplicationId(final GrantScheme grantScheme) { + final Optional grantApplication = grantApplicationRepository.findByGrantScheme(grantScheme); + return grantApplication.map(GrantApplication::getId).orElse(null); + } } diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java new file mode 100644 index 00000000..3d24b508 --- /dev/null +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java @@ -0,0 +1,40 @@ +package gov.cabinetoffice.gap.applybackend.web; + +import gov.cabinetoffice.gap.applybackend.dto.api.GetGrandAdvertDto; +import gov.cabinetoffice.gap.applybackend.service.GrantAdvertService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.constraints.NotBlank; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/grant-adverts") +public class GrantAdvertController { + + @Autowired + GrantAdvertService grantAdvertService; + @GetMapping + @Operation(summary = "Get the grant advert with the given contentful slug") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Successfully got grant advert with contentful slug provided"), + @ApiResponse(responseCode = "400", description = "Required path variable not provided in expected format", + content = @Content(mediaType = "application/json")), + @ApiResponse(responseCode = "404", description = "Unable to find grant advert with contentful slug provided", + content = @Content(mediaType = "application/json")) }) + public ResponseEntity generateGetGrantAdvertDtoFromAdvertSlug(@RequestParam @NotBlank String contentfulSlug) { + + final GetGrandAdvertDto grantAdvert = grantAdvertService.getAdvertByContentfulSlug(contentfulSlug); + + return ResponseEntity.ok(grantAdvert); + } +} diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertServiceTest.java new file mode 100644 index 00000000..698a065b --- /dev/null +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertServiceTest.java @@ -0,0 +1,190 @@ +package gov.cabinetoffice.gap.applybackend.service; + +import gov.cabinetoffice.gap.applybackend.dto.api.GetGrandAdvertDto; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvert; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvertPageResponse; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvertQuestionResponse; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvertResponse; +import gov.cabinetoffice.gap.applybackend.model.GrantAdvertSectionResponse; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; +import gov.cabinetoffice.gap.applybackend.repository.GrantAdvertRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class GrantAdvertServiceTest { + + @Mock + GrantAdvertRepository grantAdvertRepository; + @Mock + GrantApplicationService grantApplicationService; + + @InjectMocks + GrantAdvertService grantAdvertService; + private final UUID ADVERT_ID = UUID.fromString("75ab5fbd-0682-4d3d-a467-01c7a447f07c"); + + @Test + void getAdvertByContentfulSlug_createDtoForInternalApplicationAndVersion1() { + final GrantAdvertResponse response = generateResponseWithNoHowToApplySection(); + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantAdvert advert = GrantAdvert.builder() + .contentfulSlug("slug") + .id(ADVERT_ID) + .version(1) + .scheme(scheme) + .response(response) + .build(); + + when(grantAdvertRepository.findByContentfulSlug("slug")).thenReturn(Optional.of(advert)); + when(grantApplicationService.doesSchemeHaveApplication(scheme)).thenReturn(true); + when(grantApplicationService.getGrantApplicationId(scheme)).thenReturn(1); + + final GetGrandAdvertDto methodResponse = grantAdvertService.getAdvertByContentfulSlug("slug"); + + assertThat(methodResponse.getId()).isEqualTo(ADVERT_ID); + assertThat(methodResponse.getVersion()).isEqualTo(1); + assertThat(methodResponse.getExternalSubmissionUrl()).isEmpty(); + assertThat(methodResponse.isInternal()).isTrue(); + assertThat(methodResponse.getGrantApplicationId()).isEqualTo(1); + assertThat(methodResponse.getGrantSchemeId()).isEqualTo(1); + } + + @Test + void getAdvertByContentfulSlug_createDtoForInternalApplicationAndVersion2() { + final GrantAdvertResponse response = generateResponseWithNoHowToApplySection(); + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantAdvert advert = GrantAdvert.builder() + .contentfulSlug("slug") + .id(ADVERT_ID) + .version(2) + .scheme(scheme) + .response(response) + .build(); + + when(grantAdvertRepository.findByContentfulSlug("slug")).thenReturn(Optional.of(advert)); + when(grantApplicationService.doesSchemeHaveApplication(scheme)).thenReturn(true); + when(grantApplicationService.getGrantApplicationId(scheme)).thenReturn(1); + + final GetGrandAdvertDto methodResponse = grantAdvertService.getAdvertByContentfulSlug("slug"); + + assertThat(methodResponse.getId()).isEqualTo(ADVERT_ID); + assertThat(methodResponse.getVersion()).isEqualTo(2); + assertThat(methodResponse.getExternalSubmissionUrl()).isEmpty(); + assertThat(methodResponse.isInternal()).isTrue(); + assertThat(methodResponse.getGrantApplicationId()).isEqualTo(1); + assertThat(methodResponse.getGrantSchemeId()).isEqualTo(1); + } + + @Test + void getAdvertByContentfulSlug_createDtoForExternalApplicationAndVersion2() { + final GrantAdvertResponse response = genereteResponseWithHowToApplySection(); + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantAdvert advert = GrantAdvert.builder() + .contentfulSlug("slug") + .id(ADVERT_ID) + .version(2) + .scheme(scheme) + .response(response) + .build(); + + when(grantAdvertRepository.findByContentfulSlug("slug")).thenReturn(Optional.of(advert)); + when(grantApplicationService.doesSchemeHaveApplication(scheme)).thenReturn(false); + when(grantApplicationService.getGrantApplicationId(scheme)).thenReturn(null); + + final GetGrandAdvertDto methodResponse = grantAdvertService.getAdvertByContentfulSlug("slug"); + + assertThat(methodResponse.getId()).isEqualTo(ADVERT_ID); + assertThat(methodResponse.getVersion()).isEqualTo(2); + assertThat(methodResponse.getExternalSubmissionUrl()).isEqualTo("responseUrl"); + assertThat(methodResponse.isInternal()).isFalse(); + assertThat(methodResponse.getGrantApplicationId()).isNull(); + assertThat(methodResponse.getGrantSchemeId()).isEqualTo(1); + } + + @Test + void getAdvertByContentfulSlug_createDtoForExternalApplicationAndVersion1() { + final GrantAdvertResponse response = genereteResponseWithHowToApplySection(); + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantAdvert advert = GrantAdvert.builder() + .contentfulSlug("slug") + .id(ADVERT_ID) + .version(1) + .scheme(scheme) + .response(response) + .build(); + + when(grantAdvertRepository.findByContentfulSlug("slug")).thenReturn(Optional.of(advert)); + when(grantApplicationService.doesSchemeHaveApplication(scheme)).thenReturn(false); + when(grantApplicationService.getGrantApplicationId(scheme)).thenReturn(null); + + final GetGrandAdvertDto methodResponse = grantAdvertService.getAdvertByContentfulSlug("slug"); + + assertThat(methodResponse.getId()).isEqualTo(ADVERT_ID); + assertThat(methodResponse.getVersion()).isEqualTo(1); + assertThat(methodResponse.getExternalSubmissionUrl()).isEqualTo("responseUrl"); + assertThat(methodResponse.isInternal()).isFalse(); + assertThat(methodResponse.getGrantApplicationId()).isNull(); + assertThat(methodResponse.getGrantSchemeId()).isEqualTo(1); + } + + @Test + void getExternalSubmissionUrl() { + final GrantAdvertResponse response = genereteResponseWithHowToApplySection(); + final GrantAdvert advert = GrantAdvert.builder() + .response(response) + .build(); + + final String methodResponse = GrantAdvertService.getExternalSubmissionUrl(advert); + + assertThat(methodResponse).isEqualTo("responseUrl"); + } + @Test + void getExternalSubmissionUrl_returnEmptyString() { + final GrantAdvertResponse response = generateResponseWithNoHowToApplySection(); + final GrantAdvert advert = GrantAdvert.builder() + .response(response) + .build(); + + final String methodResponse = GrantAdvertService.getExternalSubmissionUrl(advert); + + assertThat(methodResponse).isEmpty(); + } + + private static GrantAdvertResponse genereteResponseWithHowToApplySection() { + final GrantAdvertQuestionResponse questionResponse = GrantAdvertQuestionResponse.builder() + .id("grantWebpageUrl") + .response("responseUrl") + .build(); + final GrantAdvertPageResponse pageResponse = GrantAdvertPageResponse.builder() + .id("pageId") + .questions(List.of(questionResponse)) + .build(); + final GrantAdvertSectionResponse sectionResponse = GrantAdvertSectionResponse.builder() + .id("howToApply") + .pages(List.of(pageResponse)) + .build(); + final GrantAdvertResponse response = GrantAdvertResponse.builder() + .sections(List.of(sectionResponse)) + .build(); + return response; + } + private static GrantAdvertResponse generateResponseWithNoHowToApplySection() { + final GrantAdvertSectionResponse sectionResponse = GrantAdvertSectionResponse.builder() + .id("") + .build(); + final GrantAdvertResponse response = GrantAdvertResponse.builder() + .sections(List.of(sectionResponse)) + .build(); + return response; + } +} \ No newline at end of file diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java index 1e328a6b..c938fdd2 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java @@ -2,6 +2,7 @@ import gov.cabinetoffice.gap.applybackend.enums.GrantApplicantStatus; import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; import gov.cabinetoffice.gap.applybackend.repository.GrantApplicationRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,6 +13,7 @@ import java.util.Optional; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -19,7 +21,6 @@ @ExtendWith(MockitoExtension.class) class GrantApplicationServiceTest { - private final UUID APPLICANT_ID = UUID.fromString("75ab5fbd-0682-4d3d-a467-01c7a447f07c"); @Mock private GrantApplicationRepository grantApplicationRepository; @InjectMocks @@ -33,7 +34,7 @@ void getGrantApplicationById__Success() { when(grantApplicationRepository.findById(1)).thenReturn(Optional.of(application)); - GrantApplication methodResponse = serviceUnderTest.getGrantApplicationById(1); + final GrantApplication methodResponse = serviceUnderTest.getGrantApplicationById(1); verify(grantApplicationRepository).findById(1); assertEquals(methodResponse, application); @@ -49,7 +50,7 @@ void isGrantApplicationPublished__True() { when(grantApplicationRepository.findById(1)).thenReturn(Optional.of(application)); - boolean response = serviceUnderTest.isGrantApplicationPublished(1); + final boolean response = serviceUnderTest.isGrantApplicationPublished(1); verify(grantApplicationRepository).findById(1); assertTrue(response); @@ -64,9 +65,61 @@ void isGrantApplicationPublished__False() { when(grantApplicationRepository.findById(1)).thenReturn(Optional.of(application)); - boolean response = serviceUnderTest.isGrantApplicationPublished(1); + final boolean response = serviceUnderTest.isGrantApplicationPublished(1); verify(grantApplicationRepository).findById(1); assertFalse(response); } + + @Test + void doesSchemeHaveApplication__True() { + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantApplication application = GrantApplication.builder().grantScheme(scheme) + .build(); + + when(grantApplicationRepository.findByGrantScheme(scheme)).thenReturn(Optional.of(application)); + + final boolean response = serviceUnderTest.doesSchemeHaveApplication(scheme); + + verify(grantApplicationRepository).findByGrantScheme(scheme); + assertTrue(response); + } + + @Test + void doesSchemeHaveApplication__False() { + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + + when(grantApplicationRepository.findByGrantScheme(scheme)).thenReturn(Optional.empty()); + + final boolean response = serviceUnderTest.doesSchemeHaveApplication(scheme); + + verify(grantApplicationRepository).findByGrantScheme(scheme); + assertFalse(response); + } + + @Test + void getGrantApplicationId__returnsId() { + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + final GrantApplication application = GrantApplication.builder().id(1).grantScheme(scheme) + .build(); + + when(grantApplicationRepository.findByGrantScheme(scheme)).thenReturn(Optional.of(application)); + + final Integer response = serviceUnderTest.getGrantApplicationId(scheme); + + verify(grantApplicationRepository).findByGrantScheme(scheme); + assertThat(response).isEqualTo(1); + } + + @Test + void getGrantApplicationId__returnsNull() { + final GrantScheme scheme = GrantScheme.builder().id(1).build(); + + when(grantApplicationRepository.findByGrantScheme(scheme)).thenReturn(Optional.empty()); + + final Integer response = serviceUnderTest.getGrantApplicationId(scheme); + + verify(grantApplicationRepository).findByGrantScheme(scheme); + assertNull(response); + } } diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertControllerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertControllerTest.java new file mode 100644 index 00000000..23044d39 --- /dev/null +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertControllerTest.java @@ -0,0 +1,29 @@ +package gov.cabinetoffice.gap.applybackend.web; + +import gov.cabinetoffice.gap.applybackend.dto.api.GetGrandAdvertDto; +import gov.cabinetoffice.gap.applybackend.service.GrantAdvertService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class GrantAdvertControllerTest { + @Mock + GrantAdvertService grantAdvertService; + @InjectMocks + GrantAdvertController grantAdvertController; + + @Test + void generateGetGrantAdvertDtoFromAdvertSlug() { + final GetGrandAdvertDto getGrandAdvertDto = GetGrandAdvertDto.builder() + .build(); + when(grantAdvertService.getAdvertByContentfulSlug("slug")).thenReturn(getGrandAdvertDto); + final GetGrandAdvertDto result = grantAdvertController.generateGetGrantAdvertDtoFromAdvertSlug("slug").getBody(); + assertThat(result).isEqualTo(getGrandAdvertDto); + } +} \ No newline at end of file From 22a7273febab8fb1ecea7f4b92e50363b09c4fca Mon Sep 17 00:00:00 2001 From: Antonio Lorusso Date: Tue, 10 Oct 2023 21:05:57 +0100 Subject: [PATCH 2/3] removes autowired --- .../gap/applybackend/service/GrantAdvertService.java | 6 ++---- .../gap/applybackend/web/GrantAdvertController.java | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java index fc6b88f0..7a4c8e7e 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java @@ -16,11 +16,9 @@ @Slf4j public class GrantAdvertService { - @Autowired - GrantAdvertRepository grantAdvertRepository; + private final GrantAdvertRepository grantAdvertRepository; - @Autowired - GrantApplicationService grantApplicationService; + private final GrantApplicationService grantApplicationService; protected static String getExternalSubmissionUrl(GrantAdvert advert) { return advert.getResponse().getSections().stream() diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java index 3d24b508..470c8fd7 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java @@ -21,8 +21,7 @@ @RequestMapping("/grant-adverts") public class GrantAdvertController { - @Autowired - GrantAdvertService grantAdvertService; + private final GrantAdvertService grantAdvertService; @GetMapping @Operation(summary = "Get the grant advert with the given contentful slug") @ApiResponses(value = { From 9fd791b6c19d527a83983bf3be3388d1cfcee184 Mon Sep 17 00:00:00 2001 From: Antonio Lorusso Date: Wed, 11 Oct 2023 11:53:58 +0100 Subject: [PATCH 3/3] tidy up --- .../applybackend/dto/api/GetQuestionDto.java | 9 +++- .../dto/api/UpdateAttachmentDto.java | 3 -- .../model/ApplicationFormSection.java | 1 - .../applybackend/model/DiligenceCheck.java | 7 ++- .../model/FundingOrganisation.java | 7 ++- .../applybackend/model/GrantApplicant.java | 16 ++++-- .../GrantApplicantOrganisationProfile.java | 12 ++++- .../applybackend/model/GrantApplication.java | 13 +++-- .../applybackend/model/GrantAttachment.java | 18 ++++++- .../applybackend/model/GrantBeneficiary.java | 14 +++++- .../gap/applybackend/model/GrantScheme.java | 8 ++- .../applybackend/model/RegisterApplicant.java | 4 +- .../gap/applybackend/model/Submission.java | 13 ++++- .../model/SubmissionDefinition.java | 3 -- .../repository/DiligenceCheckRepository.java | 1 + .../repository/GrantApplicantRepository.java | 1 - .../service/GrantAdvertService.java | 1 - ...ntApplicantOrganisationProfileService.java | 2 - .../service/GrantApplicantService.java | 2 - .../gap/applybackend/service/JwtService.java | 4 +- .../service/SubmissionService.java | 11 +++- .../utils/SecurityContextHelper.java | 2 - .../validators/QuestionResponseValidator.java | 1 - .../web/GrantAdvertController.java | 1 - .../web/GrantApplicantController.java | 7 +-- ...pplicantOrganisationProfileController.java | 9 +++- .../web/GrantBeneficiaryController.java | 8 ++- .../gap/applybackend/web/JwtController.java | 6 ++- .../web/SubmissionController.java | 50 ++++++++++++++++--- .../ControllerExceptionHandler.java | 6 ++- .../client/GovNotifyClientTest.java | 8 +-- .../applybackend/models/TestDecodedJwt.java | 1 - .../FundingOrganisationtServiceTest.java | 4 +- ...plicantOrganisationProfileServiceTest.java | 5 +- .../service/GrantApplicantServiceTest.java | 5 +- .../service/GrantApplicationServiceTest.java | 6 ++- .../service/GrantSchemeServiceTest.java | 6 +-- .../applybackend/service/JwtServiceTest.java | 8 ++- .../service/SubmissionServiceTest.java | 39 ++++++++++++--- .../EmailAddressMatchValidatorTest.java | 5 +- .../QuestionResponseValidatorTest.java | 8 ++- .../AlphaCharacterValidatorTest.java | 2 - .../web/GrantApplicantControllerTest.java | 14 +++--- ...cantOrganisationProfileControllerTest.java | 6 +-- .../web/HealthControllerTest.java | 3 +- .../web/SubmissionControllerTest.java | 48 +++++++++++++++--- .../ControllerExceptionHandlerTest.java | 6 ++- 47 files changed, 313 insertions(+), 101 deletions(-) diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetQuestionDto.java b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetQuestionDto.java index f0ecde71..4671a69e 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetQuestionDto.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/GetQuestionDto.java @@ -1,7 +1,14 @@ package gov.cabinetoffice.gap.applybackend.dto.api; import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import java.util.UUID; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/UpdateAttachmentDto.java b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/UpdateAttachmentDto.java index 35b98e04..483fa016 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/UpdateAttachmentDto.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/dto/api/UpdateAttachmentDto.java @@ -1,13 +1,10 @@ package gov.cabinetoffice.gap.applybackend.dto.api; -import gov.cabinetoffice.gap.applybackend.enums.GrantAttachmentStatus; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.UUID; - @NoArgsConstructor @AllArgsConstructor @Builder diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/ApplicationFormSection.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/ApplicationFormSection.java index 1a013546..82e4a44b 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/ApplicationFormSection.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/ApplicationFormSection.java @@ -1,7 +1,6 @@ package gov.cabinetoffice.gap.applybackend.model; import com.fasterxml.jackson.annotation.JsonInclude; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/DiligenceCheck.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/DiligenceCheck.java index b78819de..6c9c9966 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/DiligenceCheck.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/DiligenceCheck.java @@ -7,7 +7,12 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; import java.time.LocalDateTime; import java.util.UUID; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/FundingOrganisation.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/FundingOrganisation.java index e2ffb30a..5160f95d 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/FundingOrganisation.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/FundingOrganisation.java @@ -7,7 +7,12 @@ import lombok.Setter; import lombok.ToString; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; @Entity @Table(name = "grant_funding_organisation") diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicant.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicant.java index 829b5e69..b8f106df 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicant.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicant.java @@ -1,12 +1,22 @@ package gov.cabinetoffice.gap.applybackend.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; import java.util.ArrayList; import java.util.List; -import java.util.UUID; @NoArgsConstructor diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicantOrganisationProfile.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicantOrganisationProfile.java index 774fb2b1..4f815a31 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicantOrganisationProfile.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplicantOrganisationProfile.java @@ -6,7 +6,17 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; @Data @NoArgsConstructor diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplication.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplication.java index 7eef0894..14792974 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplication.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantApplication.java @@ -7,11 +7,18 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; - -import javax.persistence.*; - import org.hibernate.annotations.Type; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; import java.time.Instant; @Entity diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAttachment.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAttachment.java index d4ca57d0..1243fe6b 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAttachment.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantAttachment.java @@ -1,9 +1,23 @@ package gov.cabinetoffice.gap.applybackend.model; import gov.cabinetoffice.gap.applybackend.enums.GrantAttachmentStatus; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; import java.time.Instant; import java.util.UUID; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantBeneficiary.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantBeneficiary.java index 45e7f74f..1e2fa956 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantBeneficiary.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantBeneficiary.java @@ -1,11 +1,21 @@ package gov.cabinetoffice.gap.applybackend.model; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import org.hibernate.Hibernate; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; import java.time.LocalDateTime; import java.util.Objects; import java.util.UUID; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantScheme.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantScheme.java index bac24e0c..798b51fa 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantScheme.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/GrantScheme.java @@ -7,8 +7,12 @@ import lombok.Setter; import lombok.ToString; -import javax.persistence.*; - +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; import java.time.Instant; @Entity diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/RegisterApplicant.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/RegisterApplicant.java index ab574641..2857d42a 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/RegisterApplicant.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/RegisterApplicant.java @@ -6,7 +6,9 @@ import lombok.Builder; import lombok.Data; -import javax.validation.constraints.*; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; @Data @Builder diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/Submission.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/Submission.java index 3fcca974..32375b84 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/Submission.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/Submission.java @@ -12,7 +12,18 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZonedDateTime; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/model/SubmissionDefinition.java b/src/main/java/gov/cabinetoffice/gap/applybackend/model/SubmissionDefinition.java index 0696685b..1ade7e39 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/model/SubmissionDefinition.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/model/SubmissionDefinition.java @@ -3,8 +3,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import gov.cabinetoffice.gap.applybackend.enums.SubmissionSectionStatus; -import gov.cabinetoffice.gap.applybackend.enums.SubmissionStatus; -import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -12,7 +10,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Optional; @Data @NoArgsConstructor diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/DiligenceCheckRepository.java b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/DiligenceCheckRepository.java index 5ba968ff..9eaf7793 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/DiligenceCheckRepository.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/DiligenceCheckRepository.java @@ -3,6 +3,7 @@ import gov.cabinetoffice.gap.applybackend.model.DiligenceCheck; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; + import java.util.UUID; public interface DiligenceCheckRepository extends JpaRepository { diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicantRepository.java b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicantRepository.java index f28b4695..081802bd 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicantRepository.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/repository/GrantApplicantRepository.java @@ -4,7 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; -import java.util.UUID; public interface GrantApplicantRepository extends JpaRepository { Optional findByUserId(String userid); diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java index 7a4c8e7e..340d308b 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantAdvertService.java @@ -8,7 +8,6 @@ import gov.cabinetoffice.gap.applybackend.repository.GrantAdvertRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileService.java index 2a73c33c..bc837c04 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileService.java @@ -7,8 +7,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.UUID; - @RequiredArgsConstructor @Service public class GrantApplicantOrganisationProfileService { diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantService.java index 5590f08b..e1d61dd9 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantService.java @@ -8,8 +8,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; -import java.util.UUID; - @RequiredArgsConstructor @Service public class GrantApplicantService { diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/JwtService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/JwtService.java index 1b358309..9ec34ca8 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/JwtService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/JwtService.java @@ -4,8 +4,6 @@ import com.auth0.jwt.interfaces.DecodedJWT; import gov.cabinetoffice.gap.applybackend.config.UserServiceConfig; import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload; - -import static java.lang.Boolean.TRUE; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; @@ -20,6 +18,8 @@ import java.util.Calendar; +import static java.lang.Boolean.TRUE; + @Slf4j @RequiredArgsConstructor @Service diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/service/SubmissionService.java b/src/main/java/gov/cabinetoffice/gap/applybackend/service/SubmissionService.java index dafb5dd7..45ba03b5 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/service/SubmissionService.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/service/SubmissionService.java @@ -13,7 +13,16 @@ import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadySubmittedException; import gov.cabinetoffice.gap.applybackend.exception.SubmissionNotReadyException; -import gov.cabinetoffice.gap.applybackend.model.*; +import gov.cabinetoffice.gap.applybackend.model.DiligenceCheck; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicant; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicantOrganisationProfile; +import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantBeneficiary; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; +import gov.cabinetoffice.gap.applybackend.model.Submission; +import gov.cabinetoffice.gap.applybackend.model.SubmissionDefinition; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; +import gov.cabinetoffice.gap.applybackend.model.SubmissionSection; import gov.cabinetoffice.gap.applybackend.repository.DiligenceCheckRepository; import gov.cabinetoffice.gap.applybackend.repository.GrantBeneficiaryRepository; import gov.cabinetoffice.gap.applybackend.repository.SubmissionRepository; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/utils/SecurityContextHelper.java b/src/main/java/gov/cabinetoffice/gap/applybackend/utils/SecurityContextHelper.java index 6b57f821..5253b107 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/utils/SecurityContextHelper.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/utils/SecurityContextHelper.java @@ -3,8 +3,6 @@ import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload; import org.springframework.security.core.context.SecurityContextHolder; -import java.util.UUID; - public class SecurityContextHelper { public static String getUserIdFromSecurityContext() { final JwtPayload jwtPayload = (JwtPayload) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/validation/validators/QuestionResponseValidator.java b/src/main/java/gov/cabinetoffice/gap/applybackend/validation/validators/QuestionResponseValidator.java index 90b3cda7..9cff4df6 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/validation/validators/QuestionResponseValidator.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/validation/validators/QuestionResponseValidator.java @@ -19,7 +19,6 @@ import java.time.Month; import java.time.Year; import java.util.Map; -import java.util.UUID; import java.util.stream.Stream; import static gov.cabinetoffice.gap.applybackend.utils.SecurityContextHelper.getUserIdFromSecurityContext; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java index 470c8fd7..52ff2370 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantAdvertController.java @@ -7,7 +7,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantController.java index 484d887c..bef6edea 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantController.java @@ -16,9 +16,10 @@ import org.modelmapper.ModelMapper; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.*; - -import java.util.UUID; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileController.java index a319bf7c..3bbf88d4 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileController.java @@ -15,10 +15,15 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; -import java.util.UUID; @RequiredArgsConstructor @RestController diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantBeneficiaryController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantBeneficiaryController.java index db015920..808ab029 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantBeneficiaryController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/GrantBeneficiaryController.java @@ -7,7 +7,13 @@ import lombok.RequiredArgsConstructor; import org.modelmapper.ModelMapper; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.util.UUID; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/JwtController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/JwtController.java index b35e1606..e5a2912c 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/JwtController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/JwtController.java @@ -10,7 +10,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @Slf4j @RequiredArgsConstructor diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/SubmissionController.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/SubmissionController.java index ccf31e73..b647cb09 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/SubmissionController.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/SubmissionController.java @@ -2,27 +2,63 @@ import com.fasterxml.jackson.core.JsonProcessingException; import gov.cabinetoffice.gap.applybackend.constants.APIConstants; -import gov.cabinetoffice.gap.applybackend.dto.api.*; +import gov.cabinetoffice.gap.applybackend.dto.api.CreateQuestionResponseDto; +import gov.cabinetoffice.gap.applybackend.dto.api.CreateSubmissionResponseDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetNavigationParamsDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetQuestionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetQuestionNavigationDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetSectionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetSubmissionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload; +import gov.cabinetoffice.gap.applybackend.dto.api.SubmissionReviewBodyDto; +import gov.cabinetoffice.gap.applybackend.dto.api.SubmitApplicationDto; +import gov.cabinetoffice.gap.applybackend.dto.api.UpdateAttachmentDto; import gov.cabinetoffice.gap.applybackend.enums.GrantAttachmentStatus; import gov.cabinetoffice.gap.applybackend.enums.SubmissionSectionStatus; -import gov.cabinetoffice.gap.applybackend.exception.*; -import gov.cabinetoffice.gap.applybackend.model.*; -import gov.cabinetoffice.gap.applybackend.service.*; +import gov.cabinetoffice.gap.applybackend.exception.AttachmentException; +import gov.cabinetoffice.gap.applybackend.exception.GrantApplicationNotPublishedException; +import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadyCreatedException; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicant; +import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantAttachment; +import gov.cabinetoffice.gap.applybackend.model.Submission; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; +import gov.cabinetoffice.gap.applybackend.model.SubmissionSection; +import gov.cabinetoffice.gap.applybackend.service.AttachmentService; +import gov.cabinetoffice.gap.applybackend.service.GrantApplicantService; +import gov.cabinetoffice.gap.applybackend.service.GrantApplicationService; +import gov.cabinetoffice.gap.applybackend.service.GrantAttachmentService; +import gov.cabinetoffice.gap.applybackend.service.SecretAuthService; +import gov.cabinetoffice.gap.applybackend.service.SubmissionService; import lombok.RequiredArgsConstructor; import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.time.Clock; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; import static gov.cabinetoffice.gap.applybackend.utils.SecurityContextHelper.getUserIdFromSecurityContext; diff --git a/src/main/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandler.java b/src/main/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandler.java index 82b85bbe..4cf09e71 100644 --- a/src/main/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandler.java +++ b/src/main/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandler.java @@ -1,6 +1,10 @@ package gov.cabinetoffice.gap.applybackend.web.controlleradvice; -import gov.cabinetoffice.gap.applybackend.exception.*; +import gov.cabinetoffice.gap.applybackend.exception.AttachmentException; +import gov.cabinetoffice.gap.applybackend.exception.GrantApplicationNotPublishedException; +import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadyCreatedException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionNotReadyException; import lombok.RequiredArgsConstructor; import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException; import org.springframework.http.HttpStatus; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/client/GovNotifyClientTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/client/GovNotifyClientTest.java index da6a192b..338b8901 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/client/GovNotifyClientTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/client/GovNotifyClientTest.java @@ -2,20 +2,16 @@ import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; import ch.qos.logback.core.read.ListAppender; import gov.cabinetoffice.gap.applybackend.config.properties.EnvironmentProperties; import gov.cabinetoffice.gap.applybackend.config.properties.GovNotifyProperties; import gov.cabinetoffice.gap.applybackend.model.Submission; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.LoggerFactory; import uk.gov.service.notify.NotificationClient; @@ -24,6 +20,10 @@ import java.util.Map; import java.util.UUID; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + @ExtendWith(MockitoExtension.class) class GovNotifyClientTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/models/TestDecodedJwt.java b/src/test/java/gov/cabinetoffice/gap/applybackend/models/TestDecodedJwt.java index 5c89dab6..e4e07321 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/models/TestDecodedJwt.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/models/TestDecodedJwt.java @@ -2,7 +2,6 @@ import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; -import lombok.Setter; import lombok.ToString; import java.util.Date; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/FundingOrganisationtServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/FundingOrganisationtServiceTest.java index eff05986..5c8822f3 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/FundingOrganisationtServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/FundingOrganisationtServiceTest.java @@ -11,7 +11,9 @@ import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileServiceTest.java index 7942d05f..34d3b954 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantOrganisationProfileServiceTest.java @@ -11,9 +11,10 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; -import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantServiceTest.java index b39c6d63..f3341ec0 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicantServiceTest.java @@ -11,10 +11,11 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; -import java.util.UUID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java index c938fdd2..ffec6e1c 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantApplicationServiceTest.java @@ -11,10 +11,12 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; -import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantSchemeServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantSchemeServiceTest.java index b3ce9dec..823d2d15 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantSchemeServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/GrantSchemeServiceTest.java @@ -10,11 +10,11 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.time.Instant; -import java.time.LocalDateTime; import java.util.Optional; -import java.time.ZonedDateTime; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/JwtServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/JwtServiceTest.java index 13ca4f04..b06a9b28 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/JwtServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/JwtServiceTest.java @@ -20,8 +20,12 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/service/SubmissionServiceTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/service/SubmissionServiceTest.java index e586dcad..a71953e1 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/service/SubmissionServiceTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/service/SubmissionServiceTest.java @@ -1,6 +1,5 @@ package gov.cabinetoffice.gap.applybackend.service; -import com.amazonaws.services.s3.model.Grant; import com.fasterxml.jackson.core.JsonProcessingException; import gov.cabinetoffice.gap.applybackend.client.GovNotifyClient; import gov.cabinetoffice.gap.applybackend.config.properties.EnvironmentProperties; @@ -14,12 +13,20 @@ import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadySubmittedException; import gov.cabinetoffice.gap.applybackend.exception.SubmissionNotReadyException; -import gov.cabinetoffice.gap.applybackend.model.*; +import gov.cabinetoffice.gap.applybackend.model.ApplicationDefinition; +import gov.cabinetoffice.gap.applybackend.model.DiligenceCheck; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicant; +import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantBeneficiary; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; +import gov.cabinetoffice.gap.applybackend.model.Submission; +import gov.cabinetoffice.gap.applybackend.model.SubmissionDefinition; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestionValidation; +import gov.cabinetoffice.gap.applybackend.model.SubmissionSection; import gov.cabinetoffice.gap.applybackend.repository.DiligenceCheckRepository; import gov.cabinetoffice.gap.applybackend.repository.GrantBeneficiaryRepository; import gov.cabinetoffice.gap.applybackend.repository.SubmissionRepository; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,13 +36,31 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; -import static org.mockito.Mockito.*; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.*; -import java.util.*; +import java.time.Clock; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + @ExtendWith(MockitoExtension.class) class SubmissionServiceTest { private final String CHRISTMAS_2022_MIDDAY = "2022-12-25T12:00:00.00z"; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/EmailAddressMatchValidatorTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/EmailAddressMatchValidatorTest.java index b4ab9d54..7be455e6 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/EmailAddressMatchValidatorTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/EmailAddressMatchValidatorTest.java @@ -18,7 +18,10 @@ import java.util.stream.Stream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/annotations/QuestionResponseValidatorTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/annotations/QuestionResponseValidatorTest.java index 412f94dc..d95e5539 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/annotations/QuestionResponseValidatorTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/annotations/QuestionResponseValidatorTest.java @@ -2,11 +2,11 @@ import gov.cabinetoffice.gap.applybackend.dto.api.CreateQuestionResponseDto; import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload; +import gov.cabinetoffice.gap.applybackend.enums.SubmissionQuestionResponseType; import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestionValidation; import gov.cabinetoffice.gap.applybackend.service.SubmissionService; -import gov.cabinetoffice.gap.applybackend.enums.SubmissionQuestionResponseType; import gov.cabinetoffice.gap.applybackend.validation.validators.QuestionResponseValidator; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,7 +30,11 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class QuestionResponseValidatorTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/validators/AlphaCharacterValidatorTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/validators/AlphaCharacterValidatorTest.java index 01573262..f9991b28 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/validation/validators/AlphaCharacterValidatorTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/validation/validators/AlphaCharacterValidatorTest.java @@ -1,7 +1,6 @@ package gov.cabinetoffice.gap.applybackend.validation.validators; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -10,7 +9,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import javax.validation.ConstraintValidatorContext; - import java.util.stream.Stream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantControllerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantControllerTest.java index 08564a9b..9124ae5f 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantControllerTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantControllerTest.java @@ -6,19 +6,13 @@ import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; import gov.cabinetoffice.gap.applybackend.model.GrantApplicant; import gov.cabinetoffice.gap.applybackend.model.GrantApplicantOrganisationProfile; -import gov.cabinetoffice.gap.applybackend.model.RegisterApplicant; import gov.cabinetoffice.gap.applybackend.service.GrantApplicantOrganisationProfileService; import gov.cabinetoffice.gap.applybackend.service.GrantApplicantService; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import org.mockito.InjectMocks; import org.mockito.Mock; -import static org.mockito.Mockito.*; import org.mockito.junit.jupiter.MockitoExtension; import org.modelmapper.ModelMapper; import org.springframework.http.HttpStatus; @@ -27,7 +21,13 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import java.util.UUID; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class GrantApplicantControllerTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileControllerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileControllerTest.java index 4128a1ee..b426604f 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileControllerTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/GrantApplicantOrganisationProfileControllerTest.java @@ -18,11 +18,11 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import java.util.UUID; - import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class GrantApplicantOrganisationProfileControllerTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/HealthControllerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/HealthControllerTest.java index 4b8d2891..d358f68e 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/web/HealthControllerTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/HealthControllerTest.java @@ -1,6 +1,5 @@ package gov.cabinetoffice.gap.applybackend.web; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -8,6 +7,8 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + @ExtendWith(MockitoExtension.class) class HealthControllerTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/SubmissionControllerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/SubmissionControllerTest.java index 7d32a635..a4602bcd 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/web/SubmissionControllerTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/SubmissionControllerTest.java @@ -2,14 +2,43 @@ import com.fasterxml.jackson.core.JsonProcessingException; import gov.cabinetoffice.gap.applybackend.constants.APIConstants; -import gov.cabinetoffice.gap.applybackend.dto.api.*; +import gov.cabinetoffice.gap.applybackend.dto.api.CreateQuestionResponseDto; +import gov.cabinetoffice.gap.applybackend.dto.api.CreateSubmissionResponseDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetNavigationParamsDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetQuestionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetQuestionNavigationDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetSectionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.GetSubmissionDto; +import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload; +import gov.cabinetoffice.gap.applybackend.dto.api.SubmissionReviewBodyDto; +import gov.cabinetoffice.gap.applybackend.dto.api.SubmitApplicationDto; +import gov.cabinetoffice.gap.applybackend.dto.api.UpdateAttachmentDto; import gov.cabinetoffice.gap.applybackend.enums.GrantAttachmentStatus; import gov.cabinetoffice.gap.applybackend.enums.SubmissionQuestionResponseType; import gov.cabinetoffice.gap.applybackend.enums.SubmissionSectionStatus; import gov.cabinetoffice.gap.applybackend.enums.SubmissionStatus; -import gov.cabinetoffice.gap.applybackend.exception.*; -import gov.cabinetoffice.gap.applybackend.model.*; -import gov.cabinetoffice.gap.applybackend.service.*; +import gov.cabinetoffice.gap.applybackend.exception.AttachmentException; +import gov.cabinetoffice.gap.applybackend.exception.GrantApplicationNotPublishedException; +import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadyCreatedException; +import gov.cabinetoffice.gap.applybackend.exception.UnauthorizedException; +import gov.cabinetoffice.gap.applybackend.model.ApplicationDefinition; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicant; +import gov.cabinetoffice.gap.applybackend.model.GrantApplicantOrganisationProfile; +import gov.cabinetoffice.gap.applybackend.model.GrantApplication; +import gov.cabinetoffice.gap.applybackend.model.GrantAttachment; +import gov.cabinetoffice.gap.applybackend.model.GrantScheme; +import gov.cabinetoffice.gap.applybackend.model.Submission; +import gov.cabinetoffice.gap.applybackend.model.SubmissionDefinition; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestion; +import gov.cabinetoffice.gap.applybackend.model.SubmissionQuestionValidation; +import gov.cabinetoffice.gap.applybackend.model.SubmissionSection; +import gov.cabinetoffice.gap.applybackend.service.AttachmentService; +import gov.cabinetoffice.gap.applybackend.service.GrantApplicantService; +import gov.cabinetoffice.gap.applybackend.service.GrantApplicationService; +import gov.cabinetoffice.gap.applybackend.service.GrantAttachmentService; +import gov.cabinetoffice.gap.applybackend.service.SecretAuthService; +import gov.cabinetoffice.gap.applybackend.service.SubmissionService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,9 +67,14 @@ import java.util.stream.Stream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SubmissionControllerTest { diff --git a/src/test/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandlerTest.java b/src/test/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandlerTest.java index 5245b023..42fdf551 100644 --- a/src/test/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandlerTest.java +++ b/src/test/java/gov/cabinetoffice/gap/applybackend/web/controlleradvice/ControllerExceptionHandlerTest.java @@ -1,6 +1,10 @@ package gov.cabinetoffice.gap.applybackend.web.controlleradvice; -import gov.cabinetoffice.gap.applybackend.exception.*; +import gov.cabinetoffice.gap.applybackend.exception.AttachmentException; +import gov.cabinetoffice.gap.applybackend.exception.GrantApplicationNotPublishedException; +import gov.cabinetoffice.gap.applybackend.exception.NotFoundException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionAlreadySubmittedException; +import gov.cabinetoffice.gap.applybackend.exception.SubmissionNotReadyException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith;