Skip to content

Commit

Permalink
Revert "Revert 594 dtsrd 3528" - Actual Change - Creatign PR for QA t…
Browse files Browse the repository at this point in the history
…esting (#597)

* Revert "Revert 594 dtsrd 3528 (#596)"

This reverts commit 9bad652.

* DTSRD-3528 . fixing review comments

* DTSRD-3528 . fixing review comments

* DTSRD-3528 . fixing review comments
  • Loading branch information
SabinaHMCTS authored Nov 28, 2024
1 parent 9bad652 commit 469f492
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import jxl.common.Assert;
import net.thucydides.core.annotations.Description;
import net.thucydides.core.annotations.WithTag;
import net.thucydides.core.annotations.WithTags;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -15,6 +16,8 @@
import uk.gov.hmcts.reform.cdapi.controllers.response.Category;
import uk.gov.hmcts.reform.cdapi.exception.ErrorResponse;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -30,6 +33,115 @@ public class RetrieveCategoriesIntegrationTest extends CdAuthorizationEnabledInt

private static final String path = "/lov/categories/{category-id}";


@Test
@DisplayName("Retrieve categories with Parent and child nodes externalReference ")
void shouldRetrieveParentAndChildNodesWithExternalReferenceStatusCode200()
throws JsonProcessingException {

final var response = (Categories)
commonDataApiClient.retrieveCaseFlagsByServiceId("panelCategory?isChildRequired=Y&serviceId=BBA3",
Categories.class, path
);
assertNotNull(response);
assertEquals(1, response.getListOfCategory().size());
assertEquals(3, response.getListOfCategory().get(0).getChildNodes().size());

/// Parent
assertThat(response.getListOfCategory().get(0).getKey()).isEqualTo("BBA3-panelCategory-001");
assertThat(response.getListOfCategory().get(0).getCategoryKey()).isEqualTo("panelCategory");
assertThat(response.getListOfCategory().get(0).getExternalReference()).isNull();
assertThat(response.getListOfCategory().get(0).getExternalReferenceType()).isNull();

//child nodes
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getKey()).isEqualTo("PC1-01-94");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getValueEn())
.isEqualTo("Financial office holder");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getParentCategory())
.isEqualTo("panelCategory");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getParentKey())
.isEqualTo("BBA3-panelCategory-001");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getExternalReference())
.isEqualTo("94");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(0).getExternalReferenceType())
.isEqualTo("FinancialRole");

assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getKey()).isEqualTo("PC1-01-84");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getValueEn())
.isEqualTo("Judicial office holder");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getParentCategory())
.isEqualTo("panelCategory");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getParentKey())
.isEqualTo("BBA3-panelCategory-001");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getExternalReference())
.isEqualTo("84");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(1).getExternalReferenceType())
.isEqualTo("JudicialRole");

assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getKey()).isEqualTo("PC1-01-74");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getValueEn())
.isEqualTo("Medical office holder");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getParentCategory())
.isEqualTo("panelCategory");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getParentKey())
.isEqualTo("BBA3-panelCategory-001");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getExternalReference())
.isEqualTo("74");
assertThat(response.getListOfCategory().get(0).getChildNodes().get(2).getExternalReferenceType())
.isEqualTo("MedicalRole");
}


@Test
@DisplayName("Retrieve categories with externalReference ")
void shouldRetrieveCategoriesWithExternalReferenceStatusCode200()
throws JsonProcessingException {

final var response = (Categories)
commonDataApiClient.retrieveCaseFlagsByServiceId("panelCategoryMember?serviceId=BBA3",
Categories.class, path
);
assertNotNull(response);
assertEquals(3, response.getListOfCategory().size());
assertThat(response.getListOfCategory().get(0).getKey()).isEqualTo("PC1-01-94");
assertThat(response.getListOfCategory().get(0).getValueEn()).isEqualTo("Financial office holder");
assertThat(response.getListOfCategory().get(0).getExternalReference()).isEqualTo("94");
assertThat(response.getListOfCategory().get(0).getExternalReferenceType()).isEqualTo("FinancialRole");

assertThat(response.getListOfCategory().get(1).getKey()).isEqualTo("PC1-01-84");
assertThat(response.getListOfCategory().get(1).getValueEn()).isEqualTo("Judicial office holder");
assertThat(response.getListOfCategory().get(1).getExternalReference()).isEqualTo("84");
assertThat(response.getListOfCategory().get(1).getExternalReferenceType()).isEqualTo("JudicialRole");

assertThat(response.getListOfCategory().get(2).getKey()).isEqualTo("PC1-01-74");
assertThat(response.getListOfCategory().get(2).getValueEn()).isEqualTo("Medical office holder");
assertThat(response.getListOfCategory().get(2).getExternalReference()).isEqualTo("74");
assertThat(response.getListOfCategory().get(2).getExternalReferenceType()).isEqualTo("MedicalRole");
}

@Test
@DisplayName("Retrieve categories without externalReference ")
@Description("test to show that Json ignore did not pick up fields external_reference "
+ "and external_reference_type when they were empty")
void shouldRetrieveCategoriesWithOutExternalReferenceStatusCode200()
throws JsonProcessingException {
final String response = (String)
commonDataApiClient.retrieveCategoriesWithOutExternalReference("HearingChannel?serviceId=BBA3",
Categories.class, path);
List<String> listofValues = Arrays.asList(response.split("},"));
assertNotNull(listofValues);
assertEquals(4, listofValues.size());
assertThat(listofValues.get(0)).doesNotContain("external_reference");
assertThat(listofValues.get(0)).doesNotContain("external_reference_type");
assertThat(listofValues.get(1)).doesNotContain("external_reference");
assertThat(listofValues.get(1)).doesNotContain("external_reference_type");
assertThat(listofValues.get(2)).doesNotContain("external_reference");
assertThat(listofValues.get(2)).doesNotContain("external_reference_type");
assertThat(listofValues.get(3)).doesNotContain("external_reference");
assertThat(listofValues.get(3)).doesNotContain("external_reference_type");

}

@Test
@DisplayName("Retrieve categories for Child ")
void shouldRetrieveCategoriesForCategoryIdWithStatusCode200()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.reform.cdapi.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Jwts;
Expand All @@ -13,10 +14,12 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -58,6 +61,13 @@ public Object retrieveCaseFlagsByServiceId(String queryParam,
return mapCaseFlagsByServiceIdResponse(responseEntity, clazz);
}

public Object retrieveCategoriesWithOutExternalReference(String queryParam,
Class<?> clazz,
String path) throws JsonProcessingException {
ResponseEntity<Object> responseEntity = getRequest(APP_BASE_PATH + path + queryParam, clazz, "");
return mapCaseFlagsByServiceId(responseEntity, clazz);
}

public Object retrieveCaseFlagsByServiceIdJsonFormat(String queryParam, Class<?> clazz,
String path) {
ResponseEntity<Object> responseEntity = getRequest(APP_BASE_PATH + path + queryParam, String.class, "");
Expand All @@ -82,6 +92,27 @@ private Object mapCaseFlagsByServiceIdResponse(ResponseEntity<Object> responseEn

}

//to Test Json include only not empty values property
private Object mapCaseFlagsByServiceId(ResponseEntity<Object> responseEntity,
Class<?> clazz) throws JsonProcessingException {
HttpStatusCode status = responseEntity.getStatusCode();

if (status.is2xxSuccessful()) {
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
return objectMapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(responseEntity.getBody());
} else {
Map<String, Object> errorResponseMap = new HashMap<>();
errorResponseMap.put(
"response_body",
objectMapper.readValue(responseEntity.getBody().toString(), clazz)
);
errorResponseMap.put("http_status", status);
return errorResponseMap;
}

}

@SuppressWarnings({"rawtypes", "unchecked"})
private ResponseEntity<Object> getRequest(String uriPath, Class clasz, Object... params) {

Expand All @@ -105,6 +136,7 @@ private HttpHeaders getMultipleAuthHeaders() {

HttpHeaders headers = new HttpHeaders();
headers.setContentType(APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.ALL));
if (StringUtils.isBlank(JWT_TOKEN)) {

JWT_TOKEN = generateDummyS2SToken(serviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ CREATE TABLE List_Of_Values (
lov_order bigint,
parentcategory varchar(64),
parentkey varchar(64),
active varchar(1)
active varchar(1),
external_reference varchar(200),
external_reference_type varchar(200)
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ DROP CONSTRAINT list_of_values_key_key;
ALTER TABLE List_Of_Values
ADD CONSTRAINT compKey UNIQUE (categorykey,key,serviceid);

INSERT INTO List_Of_Values (CategoryKey,ServiceID,Key,Value_EN,Value_CY,HintText_EN,HintText_CY,Lov_Order,ParentCategory,ParentKey,Active)
VALUES ('HearingChannel','BBA3','telephone','Telephone',null,null,null,2,null,null,'Y'),
('HearingChannel','BBA3','video','Video',null,null,null,3,null,null,'Y'),
('HearingChannel','BBA3','faceToFace','Face To Face',null,null,null,1,null,null,'Y'),
('HearingChannel','BBA3','notAttending','Not Attending',null,null,null,4,null,null,'Y'),
('HearingChannel','','notAttending','Not Attending',null,null,null,5,null,null,'Y'),
('HearingChannel','','telephone','telephone',null,null,null,6,null,null,'Y'),
('HearingSubChannel','BBA3','telephone-btMeetMe','Telephone - BTMeetme',null,null,null,null,'HearingChannel','telephone','Y'),
('HearingSubChannel','','telephone-btMeetMe','Telephone - BTMeetme',null,null,null,null,'HearingChannel','telephone','Y'),
('CaseLinkingReasonCode','ABA3','CLRC002','Related proceedings',null,null,null,null,null,null,'Y'),
('CaseLinkingReasonCode','ABA3','CLRC017','Linked for a hearing',null,null,null,null,null,null,'Y'),
('CaseLinkingReasonCode','','CLRC006','Guardian',null,null,null,null,null,null,'Y'),
('CaseLinkingReasonCode','','CLRC004','Guardian',null,null,null,null,null,null,'Y'),
('CaseLinkingReasonCode','','CLRC003','Guardian',null,null,null,null,null,null,'Y'),
('caseSubType','BHA1','BHA1-EMT','Employment',null,null,null,null,'caseType','BFA1-EAD','Y'),
('caseSubType','','CLRC017','Linked for a hearing',null,null,null,null,null,null,'Y'),
('ListingStatus','','test','test',null,null,null,null,null,null,'Y'),
('EmptySubCategory','','test','test',null,null,null,null,null,null,'Y'),
('ListingStatusSubChannel','','test','test',null,null,null,null,'ListingStatus','test','Y'),
('InterpreterLanguage','BBA1','test2','test2','test2',null,null,null,'HearingChannel','test','Y'),
('SignLanguage','BBA1','test4','test4','test4',null,null,null,'HearingChannel','test','Y');
INSERT INTO List_Of_Values (CategoryKey,ServiceID,Key,Value_EN,Value_CY,HintText_EN,HintText_CY,Lov_Order,ParentCategory,ParentKey,Active,external_reference,external_reference_type)
VALUES ('HearingChannel','BBA3','telephone','Telephone',null,null,null,2,null,null,'Y','',''),
('HearingChannel','BBA3','video','Video',null,null,null,3,null,null,'Y','',''),
('HearingChannel','BBA3','faceToFace','Face To Face',null,null,null,1,null,null,'Y','',''),
('HearingChannel','BBA3','notAttending','Not Attending',null,null,null,4,null,null,'Y','',''),
('HearingChannel','','notAttending','Not Attending',null,null,null,5,null,null,'Y','',''),
('HearingChannel','','telephone','telephone',null,null,null,6,null,null,'Y','',''),
('HearingSubChannel','BBA3','telephone-btMeetMe','Telephone - BTMeetme',null,null,null,null,'HearingChannel','telephone','Y','',''),
('HearingSubChannel','','telephone-btMeetMe','Telephone - BTMeetme',null,null,null,null,'HearingChannel','telephone','Y','',''),
('CaseLinkingReasonCode','ABA3','CLRC002','Related proceedings',null,null,null,null,null,null,'Y','',''),
('CaseLinkingReasonCode','ABA3','CLRC017','Linked for a hearing',null,null,null,null,null,null,'Y','',''),
('CaseLinkingReasonCode','','CLRC006','Guardian',null,null,null,null,null,null,'Y','',''),
('CaseLinkingReasonCode','','CLRC004','Guardian',null,null,null,null,null,null,'Y','',''),
('CaseLinkingReasonCode','','CLRC003','Guardian',null,null,null,null,null,null,'Y','',''),
('caseSubType','BHA1','BHA1-EMT','Employment',null,null,null,null,'caseType','BFA1-EAD','Y','',''),
('caseSubType','','CLRC017','Linked for a hearing',null,null,null,null,null,null,'Y','',''),
('ListingStatus','','test','test',null,null,null,null,null,null,'Y','',''),
('EmptySubCategory','','test','test',null,null,null,null,null,null,'Y','',''),
('ListingStatusSubChannel','','test','test',null,null,null,null,'ListingStatus','test','Y','',''),
('InterpreterLanguage','BBA1','test2','test2','test2',null,null,null,'HearingChannel','test','Y','',''),
('SignLanguage','BBA1','test4','test4','test4',null,null,null,'HearingChannel','test','Y','',''),
('caseSubType','BBA3','BBA3-088OC','OVERPAYMENT',null,null,null,null,'caseType','BBA3-088','Y','',''),
('panelCategory','BBA3','BBA3-panelCategory-001','Panel Category description',null,null,null,null,null,null,'Y','',''),
('panelCategoryMember','BBA3','PC1-01-94','Financial office holder',null,null,null,null,'panelCategory','BBA3-panelCategory-001','Y','94','FinancialRole'),
('panelCategoryMember','BBA3','PC1-01-84','Judicial office holder',null,null,null,null,'panelCategory','BBA3-panelCategory-001','Y','84','JudicialRole'),
('panelCategoryMember','BBA3','PC1-01-74','Medical office holder',null,null,null,null,'panelCategory','BBA3-panelCategory-001','Y','74','MedicalRole');
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ public class CategoryRequest {

@Parameter(name = "isChildRequired", description = "Any Valid String is allowed")
String isChildRequired;

@Parameter(name = "externalReferenceType", description = "Any Valid String is allowed")
String externalReferenceType;

@Parameter(name = "externalReference", description = "Any Valid String is allowed")
String externalReference;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.reform.cdapi.controllers.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -40,6 +41,12 @@ public class Category {

private String activeFlag;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String externalReferenceType;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String externalReference;

@Setter
private List<Category> childNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class ListOfValueDto {
private String parentKey;

private String active;


@Column(name = "external_reference_type")
private String externalReferenceType;
@Column(name = "external_reference")
private String externalReference;
}


Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public List<Category> convertCategoryList(List<ListOfValueDto> listOfValueDtos)
.valueEn(dto.getValueEn())
.parentCategory(dto.getParentCategory())
.parentKey(dto.getParentKey())
.externalReference(dto.getExternalReference())
.externalReferenceType(dto.getExternalReferenceType())
.build())
.sorted((c1, c2) -> {
if (c1.getLovOrder() != null && c2.getLovOrder() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ALTER TABLE List_Of_Values
((external_reference_type is null and external_reference is null)
or (external_reference_type is not null and external_reference is not null))


0 comments on commit 469f492

Please sign in to comment.