Skip to content

Commit

Permalink
CIV-9418 test controller
Browse files Browse the repository at this point in the history
  • Loading branch information
pliao-hmcts committed Jul 14, 2023
1 parent c9965ad commit 1f6eb47
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-json'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '3.0.4'
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.1.0'

implementation 'com.github.hmcts:payments-java-client:1.6.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.RestController;

import uk.gov.hmcts.reform.civil.exceptions.Payload;
import uk.gov.hmcts.reform.civil.model.CreateSDTResponse;
import uk.gov.hmcts.reform.civil.modelsdt.CreateClaimSDT;
import uk.gov.hmcts.reform.civil.service.CreateClaimFromSdtService;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;

@Slf4j
Expand All @@ -31,5 +37,11 @@ public ResponseEntity<CreateSDTResponse> createClaimSdt(@RequestBody CreateClaim

return createClaimFromSdtService.buildResponse(createClaimSDT);
}

@PostMapping(path ="/exception/{testId}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CreateSDTResponse> welcome(@PathVariable("testId") int testId,
@RequestBody @Valid Payload payload) {
return createClaimFromSdtService.buildException(testId);
}
}

15 changes: 15 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/civil/exceptions/Payload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.gov.hmcts.reform.civil.exceptions;

import jakarta.validation.constraints.Min;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.NotBlank;

@Getter
@Setter
public class Payload {
@NotBlank
private String name;
@Min(value = 18)
private int age;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package uk.gov.hmcts.reform.civil.service;

import static uk.gov.hmcts.reform.civil.exceptions.ErrorDetails.INVALID_DATA;
import static uk.gov.hmcts.reform.civil.exceptions.ErrorDetails.INVALID_DATA_CUSTOM;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import uk.gov.hmcts.reform.civil.exceptions.ApplicationException;
import uk.gov.hmcts.reform.civil.mappings.CreateClaimCCD;
import uk.gov.hmcts.reform.civil.mappings.CreateClaimMapper;
import uk.gov.hmcts.reform.civil.model.CreateSDTResponse;
Expand All @@ -17,6 +23,7 @@ public class CreateClaimFromSdtService {

private final CreateSDTResponse createSDTResponse;
private final SubmitCreateClaim submitCreateClaim;
private final LocalValidatorFactoryBean validatorFactory;

public ResponseEntity<CreateSDTResponse> buildResponse(CreateClaimSDT createClaimSDT) {

Expand Down Expand Up @@ -114,4 +121,16 @@ public CreateClaimCCD processSdtClaim(CreateClaimSDT createClaimSDT) {
return createClaimMapper.getCreateClaimCCD();
}

public ResponseEntity<CreateSDTResponse> buildException(final int testId) {
//throw own error
if (testId == 1) {
throw new ApplicationException(INVALID_DATA, HttpStatus.BAD_REQUEST);
}
if (testId == 2) {
throw new ApplicationException(INVALID_DATA_CUSTOM, HttpStatus.BAD_REQUEST, "2333");
}
return new ResponseEntity<>(
CreateSDTResponse.builder().build(),
HttpStatus.CREATED);
}
}

0 comments on commit 1f6eb47

Please sign in to comment.