diff --git a/build.gradle b/build.gradle index 2a4d731493..2ea6bce161 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ ext { testContainersVersion = '2.0.5' cucumber = '7.34.3' beftaFwVersion = '9.2.6' - ccdTestDefinitionVersion = '7.26.4' + ccdTestDefinitionVersion = '7.26.5-CCD-6195' limits = [ 'instruction': 90, 'branch' : 85, diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027.feature b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027.feature new file mode 100644 index 0000000000..377c822e49 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027.feature @@ -0,0 +1,18 @@ +@F-1027 +Feature: F-1027: Validate numberField accepts and displays decimals + + Background: Load test data for the scenario + Given an appropriate test context as detailed in the test data source + + @S-1027.1 + Scenario: must successfully create case with number field displaying as expected + Given a user with [an active profile in CCD] + And a case that has just been created as in [S-1027.1_Create_Case_Data] + And a successful call [to create a token for case creation] as in [F-1027_Case_Data_Create_Token_Creation] + When a request is prepared with appropriate values + And the request [is of caseType where case_data has NumberField of 12.88] + And it is submitted to call the [Submit Case Creation as Caseworker] operation of [CCD Data Store] + Then a positive response is received + And the response has all other details as expected + + diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Case_Data_Create_Token_Creation.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Case_Data_Create_Token_Creation.td.json new file mode 100644 index 0000000000..e371a2bdf3 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Case_Data_Create_Token_Creation.td.json @@ -0,0 +1,71 @@ +{ + "_guid_": "F-1027_Case_Data_Create_Token_Creation", + "_extends_": "Standard_Token_Creation_Data_For_Case_Creation", + "specs": [ + "to create a token for case creation", + "As a prerequisite" + ], + "users": { + "invokingUser": { + "username": "master.caseworker@gmail.com", + "password": "[[$CCD_CASEWORKER_AUTOTEST_PASSWORD]]" + } + }, + "request": { + "pathVariables": { + "uid": "[[DEFAULT_AUTO_VALUE]]", + "jid": "BEFTA_MASTER", + "ctid": "FT_MasterCaseType", + "etid": "createCase" + } + }, + "expectedResponse": { + "body": { + "case_details": { + "case_data": { + "DynamicList": { + "value": { + "code": "List1", + "label": " List 1" + }, + "list_items": [ + { + "code": "List1", + "label": " List 1" + }, + { + "code": "List2", + "label": " List 2" + }, + { + "code": "List3", + "label": " List 3" + }, + { + "code": "List4", + "label": " List 4" + }, + { + "code": "List5", + "label": " List 5" + }, + { + "code": "List6", + "label": " List 6" + }, + { + "code": "List7", + "label": " List 7" + } + ] + } + }, + "data_classification": { + "DynamicList": "PUBLIC" + }, + "supplementary_data": null + }, + "event_id": "createCase" + } + } +} diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Test_Data_Base.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Test_Data_Base.td.json new file mode 100644 index 0000000000..d8998ff7d2 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Test_Data_Base.td.json @@ -0,0 +1,89 @@ +{ + "title": "should create a case", + "_guid_": "F-1027_Test_Data_Base", + "productName": "CCD Data Store", + "operationName": "Submit Case Creation as Caseworker", + "method": "POST", + "uri": "/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases", + "specs": [ + "to create a full case" + ], + "users": { + "invokingUser": { + "username": "master.caseworker@gmail.com", + "password": "[[$CCD_CASEWORKER_AUTOTEST_PASSWORD]]" + } + }, + "user": { + "username": "master.caseworker@gmail.com", + "password": "[[$CCD_CASEWORKER_AUTOTEST_PASSWORD]]" + }, + + "request": { + "headers": { + "_extends_": "Common_Request_Headers" + }, + "pathVariables": { + "uid": "[[DEFAULT_AUTO_VALUE]]", + "jid": "BEFTA_MASTER", + "ctid": "FT_MasterCaseType" + }, + "body": { + "data": { + "TextField": null, + "TextAreaField": null, + "DateField": null, + "PhoneField": null, + "NumberField": 12.88, + "YesNoField": null, + "CollectionField": [], + "AddressUKField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "PostTown": null, + "County": null, + "PostCode": null, + "Country": null + }, + "MarritalStatus": null, + "MoneyField": "008", + "EmailField": null, + "MultiSelectField": [], + "OrganisationPolicyField1": { + "OrgPolicyCaseAssignedRole": "[Claimant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "OrganisationPolicyField2": { + "OrgPolicyCaseAssignedRole": "[Defendant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "CaseLinkField": { + "CaseReference": null + }, + "AddressField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "Country": null + } + }, + "event": { + "id": "createCase", + "summary": "", + "description": "" + }, + "event_token": "${[scenarioContext][childContexts][F-1027_Case_Data_Create_Token_Creation][testData][actualResponse][body][token]}", + "ignore_warning": true, + "draft_id": null + } + } +} diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Token_Creation_Base.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Token_Creation_Base.td.json new file mode 100644 index 0000000000..71af93fd7b --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/F-1027_Token_Creation_Base.td.json @@ -0,0 +1,69 @@ +{ + "_guid_" : "F-1027_Token_Creation_Base", + + + "productName": "CCD Data Store", + "operationName": "Start event creation as Case worker", + + "method": "GET", + "uri": "/cases/{caseId}/event-triggers/{etid}", + + "specs": [ + "to create a token for case creation", + "to create a token for event creation" + ], + + "users": { + "invokingUser": { + "username": "master.caseworker@gmail.com", + "password": "[[$CCD_CASEWORKER_AUTOTEST_PASSWORD]]" + } + }, + + "request": { + "headers":{ + "_extends_": "Common_Request_Headers", + "Experimental" : "true" + }, + "pathVariables": { + "etid": "createCase", + "caseId": "" + } + }, + + "expectedResponse": { + "_extends_": "Common_200_Response", + "headers" : { + "Content-Encoding" : "gzip", + "Content-Length": "[[ANYTHING_PRESENT]]" + }, + "body" : { + "token" : "[[ANYTHING_PRESENT]]", + "_links": { + "self": { + "href": "[[ANYTHING_PRESENT]]" + } + }, + "case_details" : { + "id" : "[[ANYTHING_PRESENT]]", + "jurisdiction" : "BEFTA_MASTER", + "state" : "[[ANYTHING_PRESENT]]", + "version" : "[[ANYTHING_PRESENT]]", + "case_type_id" : "FT_MasterCaseType", + "created_date" : "[[ANYTHING_PRESENT]]", + "last_modified" : "[[ANYTHING_PRESENT]]", + "last_state_modified_date" : "[[ANYTHING_PRESENT]]", + "security_classification" : "[[ANYTHING_PRESENT]]", + "case_data" : "[[ANYTHING_PRESENT]]", + "data_classification" : "[[ANYTHING_PRESENT]]", + "supplementary_data": null, + "after_submit_callback_response" : null, + "callback_response_status_code" : null, + "callback_response_status" : null, + "delete_draft_response_status_code" : null, + "delete_draft_response_status" : null + }, + "event_id" : "event2" + } + } +} diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1.td.json new file mode 100644 index 0000000000..be3740ef79 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1.td.json @@ -0,0 +1,226 @@ +{ + "title": "must successfully create case with number field displaying as expected", + "_guid_": "S-1027.1", + "_extends_": "F-1027_Test_Data_Base", + "prerequisites": [ + { + "Token_Creation": "F-1027_Case_Data_Create_Token_Creation" + } + ], + "specs": [ + "an active profile in CCD", + "contains a case with number field showing correctly", + "has 201 return code", + "contains correct values for case_data and data_classification", + "is of caseType where case_data has NumberField of 12.88" + ], + "request": { + "body": { + "data": { + "TextField": null, + "TextAreaField": null, + "DateField": null, + "PhoneField": null, + "NumberField": 12.88, + "YesNoField": null, + "CollectionField": [], + "AddressUKField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "PostTown": null, + "County": null, + "PostCode": null, + "Country": null + }, + "MarritalStatus": null, + "MoneyField": "008", + "EmailField": null, + "MultiSelectField": [], + "OrganisationPolicyField1": { + "OrgPolicyCaseAssignedRole": "[Claimant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "OrganisationPolicyField2": { + "OrgPolicyCaseAssignedRole": "[Defendant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "CaseLinkField": { + "CaseReference": null + }, + "AddressField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "Country": null + } + }, + "event": { + "id": "createCase", + "summary": "", + "description": "" + }, + "event_token": "${[scenarioContext][childContexts][Token_Creation][testData][actualResponse][body][token]}", + "ignore_warning": true, + "draft_id": null + } + }, + "expectedResponse": { + "_extends_": "Common_201_Response", + "headers": { + "Content-Length": "[[ANYTHING_PRESENT]]", + "Content-Encoding": "gzip", + "Vary": "accept-encoding", + "Keep-Alive": "[[ANYTHING_PRESENT]]", + "Transfer-Encoding": "[[ANYTHING_PRESENT]]" + }, + "body": { + "id": "[[ANYTHING_PRESENT]]", + "jurisdiction": "BEFTA_MASTER", + "state": "CaseCreated", + "version": 0, + "case_type_id": "FT_MasterCaseType", + "created_date": "[[ANYTHING_PRESENT]]", + "last_modified": "[[ANYTHING_PRESENT]]", + "last_state_modified_date": "[[ANYTHING_PRESENT]]", + "security_classification": "PUBLIC", + "case_data": { + "AddressField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "Country": null + }, + "AddressUKField": { + "AddressLine1": null, + "AddressLine2": null, + "AddressLine3": null, + "PostTown": null, + "County": null, + "PostCode": null, + "Country": null + }, + "MoneyField": "008", + "MarritalStatus": null, + "NumberField": 12.88, + "SearchCriteria": {}, + "MultiSelectField": [], + "YesNoField": null, + "EmailField": null, + "TextField": null, + "PhoneField": null, + "DateField": null, + "OrganisationPolicyField2": { + "OrgPolicyCaseAssignedRole": "[Defendant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "TextAreaField": null, + "OrganisationPolicyField1": { + "OrgPolicyCaseAssignedRole": "[Claimant]", + "OrgPolicyReference": null, + "Organisation": { + "OrganisationID": null, + "OrganisationName": null + } + }, + "CaseLinkField": { + "CaseReference": null + }, + "CollectionField": [] + }, + "data_classification": { + "AddressField": { + "classification": "PUBLIC", + "value": { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "Country": "PUBLIC" + } + }, + "AddressUKField": { + "classification": "PUBLIC", + "value": { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "PostTown": "PUBLIC", + "County": "PUBLIC", + "PostCode": "PUBLIC", + "Country": "PUBLIC" + } + }, + "MoneyField": "PUBLIC", + "MarritalStatus": "PUBLIC", + "NumberField": "PUBLIC", + "SearchCriteria": { + "classification": "PUBLIC", + "value": {} + }, + "MultiSelectField": "PUBLIC", + "YesNoField": "PUBLIC", + "EmailField": "PUBLIC", + "TextField": "PUBLIC", + "PhoneField": "PUBLIC", + "DateField": "PUBLIC", + "OrganisationPolicyField2": { + "classification": "PUBLIC", + "value": { + "OrgPolicyCaseAssignedRole": "PUBLIC", + "OrgPolicyReference": "PUBLIC", + "Organisation": { + "classification": "PUBLIC", + "value": { + "OrganisationID": "PUBLIC", + "OrganisationName": "PUBLIC" + } + } + } + }, + "TextAreaField": "PUBLIC", + "OrganisationPolicyField1": { + "classification": "PUBLIC", + "value": { + "OrgPolicyCaseAssignedRole": "PUBLIC", + "OrgPolicyReference": "PUBLIC", + "Organisation": { + "classification": "PUBLIC", + "value": { + "OrganisationID": "PUBLIC", + "OrganisationName": "PUBLIC" + } + } + } + }, + "CaseLinkField": { + "classification": "PUBLIC", + "value": { + "CaseReference": "PUBLIC" + } + }, + "CollectionField": { + "classification": "PUBLIC", + "value": [] + } + }, + "supplementary_data": null, + "after_submit_callback_response": null, + "callback_response_status_code": null, + "callback_response_status": null, + "delete_draft_response_status_code": null, + "delete_draft_response_status": null + } + } +} diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data.td.json new file mode 100644 index 0000000000..56563dcde3 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data.td.json @@ -0,0 +1,153 @@ +{ + "_guid_": "S-1027.1_Create_Case_Data", + "_extends_": "F-1027_Test_Data_Base", + "request": { + "body": { + "event_token": "${[scenarioContext][siblingContexts][S-1027.1_Create_Case_Data_Token_Creation][testData][actualResponse][body][token]}" + } + }, + + "expectedResponse": { + "_extends_": "Common_201_Response", + "body" : { + "id" : "[[ANYTHING_PRESENT]]", + "jurisdiction" : "BEFTA_MASTER", + "state" : "CaseCreated", + "version" : 0, + "case_type_id" : "FT_MasterCaseType", + "created_date" : "[[ANYTHING_PRESENT]]", + "last_modified" : "[[ANYTHING_PRESENT]]", + "last_state_modified_date" : "[[ANYTHING_PRESENT]]", + "security_classification" : "PUBLIC", + "case_data" : { + "AddressField" : { + "AddressLine1" : null, + "AddressLine2" : null, + "AddressLine3" : null, + "Country" : null + }, + "AddressUKField" : { + "AddressLine1" : null, + "AddressLine2" : null, + "AddressLine3" : null, + "PostTown" : null, + "County" : null, + "PostCode" : null, + "Country" : null + }, + "MoneyField" : "008", + "MarritalStatus" : null, + "NumberField" : 12.88, + "SearchCriteria" : { }, + "MultiSelectField" : [ ], + "YesNoField" : null, + "EmailField" : null, + "TextField" : null, + "PhoneField" : null, + "DateField" : null, + "OrganisationPolicyField2" : { + "OrgPolicyCaseAssignedRole" : "[Defendant]", + "OrgPolicyReference" : null, + "Organisation" : { + "OrganisationID" : null, + "OrganisationName" : null + } + }, + "TextAreaField" : null, + "OrganisationPolicyField1" : { + "OrgPolicyCaseAssignedRole" : "[Claimant]", + "OrgPolicyReference" : null, + "Organisation" : { + "OrganisationID" : null, + "OrganisationName" : null + } + }, + "CaseLinkField" : { + "CaseReference" : null + }, + "CollectionField" : [ ] + }, + "data_classification": { + "AddressField": { + "classification": "PUBLIC", + "value": { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "Country": "PUBLIC" + } + }, + "AddressUKField": { + "classification": "PUBLIC", + "value": { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "PostTown": "PUBLIC", + "County": "PUBLIC", + "PostCode": "PUBLIC", + "Country": "PUBLIC" + } + }, + "MoneyField": "PUBLIC", + "MarritalStatus": "PUBLIC", + "NumberField": "PUBLIC", + "SearchCriteria": { + "classification": "PUBLIC", + "value": {} + }, + "MultiSelectField": "PUBLIC", + "YesNoField": "PUBLIC", + "EmailField": "PUBLIC", + "TextField": "PUBLIC", + "PhoneField": "PUBLIC", + "DateField": "PUBLIC", + "OrganisationPolicyField2": { + "classification": "PUBLIC", + "value": { + "OrgPolicyCaseAssignedRole": "PUBLIC", + "OrgPolicyReference": "PUBLIC", + "Organisation": { + "classification": "PUBLIC", + "value": { + "OrganisationID": "PUBLIC", + "OrganisationName": "PUBLIC" + } + } + } + }, + "TextAreaField": "PUBLIC", + "OrganisationPolicyField1": { + "classification": "PUBLIC", + "value": { + "OrgPolicyCaseAssignedRole": "PUBLIC", + "OrgPolicyReference": "PUBLIC", + "Organisation": { + "classification": "PUBLIC", + "value": { + "OrganisationID": "PUBLIC", + "OrganisationName": "PUBLIC" + } + } + } + }, + "CaseLinkField": { + "classification": "PUBLIC", + "value": { + "CaseReference": "PUBLIC" + } + }, + "CollectionField": { + "classification": "PUBLIC", + "value": [] + } + }, + "supplementary_data": null, + "after_submit_callback_response" : null, + "callback_response_status_code" : null, + "callback_response_status" : null, + "delete_draft_response_status_code" : null, + "delete_draft_response_status" : null + } + } +} diff --git a/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data_Token_Creation.td.json b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data_Token_Creation.td.json new file mode 100644 index 0000000000..a4654387e2 --- /dev/null +++ b/src/aat/resources/features/F-1027 - Decimal Numbers/S-1027.1_Create_Case_Data_Token_Creation.td.json @@ -0,0 +1,4 @@ +{ + "_guid_": "S-1027.1_Create_Case_Data_Token_Creation", + "_extends_": "F-1027_Case_Data_Create_Token_Creation" +} diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGenerator.java b/src/main/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGenerator.java index fe607077d4..94b8023915 100644 --- a/src/main/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGenerator.java +++ b/src/main/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGenerator.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.DecimalNode; import com.fasterxml.jackson.databind.node.LongNode; import com.fasterxml.jackson.databind.node.NullNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -68,7 +69,7 @@ private JsonNode buildDataBlock(JsonNode originalNode, ? buildComplexNode(originalNode, fieldType) : buildComplexNode(originalNode, allSubFields, directChildrenFields); } else if (fieldType.isCollectionFieldType()) { - return buildCollectionNode(originalNode, (originalValueNode) -> + return buildCollectionNode(originalNode, originalValueNode -> fieldType.getCollectionFieldTypeDefinition().getChildren().isEmpty() ? buildSimpleNode(originalValueNode, fieldType.getCollectionFieldTypeDefinition().getType()) : buildComplexNode(originalValueNode, allSubFields, directChildrenFields)); @@ -126,7 +127,7 @@ private JsonNode buildCollectionNode(JsonNode originalNode, FieldTypeDefinition return originalNode; } - return buildCollectionNode(originalNode, (originalValueNode) -> { + return buildCollectionNode(originalNode, originalValueNode -> { ObjectNode newValueNode = MAPPER.createObjectNode(); children.forEach(caseFieldDefinition -> { String fieldId = caseFieldDefinition.getId(); @@ -157,8 +158,7 @@ private JsonNode buildSimpleNode(JsonNode node, String fieldType) { switch (fieldType) { case YES_OR_NO: return booleanNodeOf(node); - case NUMBER: - case MONEY_GBP: + case NUMBER, MONEY_GBP: return numberNodeOf(node); default: return node; @@ -173,7 +173,11 @@ private JsonNode booleanNodeOf(JsonNode node) { return node.textValue().equalsIgnoreCase("Yes") ? BooleanNode.TRUE : BooleanNode.FALSE; } - private JsonNode numberNodeOf(JsonNode node) { + private JsonNode processNumberNodeOf(JsonNode node) { return node.isNumber() ? LongNode.valueOf(node.asLong()) : LongNode.valueOf(Long.parseLong(node.textValue())); } + + private JsonNode numberNodeOf(JsonNode node) { + return node.isDouble() ? DecimalNode.valueOf(node.decimalValue()) : processNumberNodeOf(node); + } } diff --git a/src/test/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGeneratorTest.java b/src/test/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGeneratorTest.java index a4e999f5f2..54a0d7f36b 100644 --- a/src/test/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/ccd/domain/service/message/additionaldata/DataBlockGeneratorTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.DecimalNode; import com.fasterxml.jackson.databind.node.IntNode; import com.fasterxml.jackson.databind.node.NullNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -22,9 +23,11 @@ import uk.gov.hmcts.ccd.domain.model.definition.DisplayContext; import uk.gov.hmcts.ccd.domain.model.definition.FieldTypeDefinition; +import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -57,6 +60,7 @@ class DataBlockGeneratorTest { private final ObjectMapper objectMapper = new ObjectMapper(); private static final String FIELD_ID = "FieldId"; + private static final String FIELD_ID_2 = "FieldId2"; private static final String FIELD_ALIAS = "FieldAlias"; private static final String TEXT_FIELD = "TextValue"; private static final String NESTED_FIELD_1 = "NestedField1"; @@ -91,20 +95,8 @@ void shouldBuildDataForPublishableSimpleBooleanField() { caseTypeDefinition = newCaseType() .withCaseFields(List.of( - newCaseField() - .withId(FIELD_ID) - .withFieldType(aFieldType() - .withId(FieldTypeDefinition.YES_OR_NO) - .withType(FieldTypeDefinition.YES_OR_NO) - .build()) - .build(), - newCaseField() - .withId("dontPublished") - .withFieldType(aFieldType() - .withId(FieldTypeDefinition.YES_OR_NO) - .withType(FieldTypeDefinition.YES_OR_NO) - .build()) - .build() + complexField(FIELD_ID, FieldTypeDefinition.YES_OR_NO), + complexField("dontPublished", FieldTypeDefinition.YES_OR_NO) )) .build(); @@ -142,27 +134,15 @@ void shouldBuildDataForPublishableSimpleNumberField() { caseTypeDefinition = newCaseType() .withCaseFields(List.of( - newCaseField() - .withId(FIELD_ID) - .withFieldType(aFieldType() - .withId(FieldTypeDefinition.MONEY_GBP) - .withType(FieldTypeDefinition.MONEY_GBP) - .build()) - .build(), - newCaseField() - .withId("dontPublished") - .withFieldType(aFieldType() - .withId(FieldTypeDefinition.YES_OR_NO) - .withType(FieldTypeDefinition.YES_OR_NO) - .build()) - .build() + complexField(FIELD_ID, MONEY_GBP), + complexField("dontPublished", YES_OR_NO), + complexField(FIELD_ID_2, NUMBER) )) .build(); - ObjectMapper mapper = new ObjectMapper(); - Map data = new HashMap<>(); data.put(FIELD_ID, IntNode.valueOf(6080)); + data.put(FIELD_ID_2, DecimalNode.valueOf(BigDecimal.valueOf(70.10))); caseDetails = newCaseDetails().withData(data).build(); @@ -170,10 +150,13 @@ void shouldBuildDataForPublishableSimpleNumberField() { new AdditionalDataContext(caseEventDefinition, caseTypeDefinition, caseDetails); Map result = dataBlockGenerator.generateData(context); - assertAll( - () -> assertEquals(6080, result.get(FIELD_ID).intValue()), - () -> MatcherAssert.assertThat(result.size(), Matchers.is(1)) + + Optional.ofNullable(result.get(FIELD_ID_2)).ifPresentOrElse( + value -> assertEquals(BigDecimal.valueOf(70.10), value.decimalValue()), + () -> assertEquals(6080, result.get(FIELD_ID).intValue()) ); + MatcherAssert.assertThat(result.size(), Matchers.is(1)); + } @Test @@ -1180,15 +1163,7 @@ void shouldBuildDataForPublishableBooleanFieldWithNullValue() { .build(); caseTypeDefinition = newCaseType() - .withCaseFields(List.of( - newCaseField() - .withId(FIELD_ID) - .withFieldType(aFieldType() - .withId(YES_OR_NO) - .withType(YES_OR_NO) - .build()) - .build() - )) + .withCaseFields(List.of(complexField(FIELD_ID, YES_OR_NO))) .build(); Map data = new HashMap<>(); @@ -1220,15 +1195,7 @@ void shouldBuildDataForPublishableBooleanFieldWithEmptyValue() { .build(); caseTypeDefinition = newCaseType() - .withCaseFields(List.of( - newCaseField() - .withId(FIELD_ID) - .withFieldType(aFieldType() - .withId(YES_OR_NO) - .withType(YES_OR_NO) - .build()) - .build() - )) + .withCaseFields(List.of(complexField(FIELD_ID, YES_OR_NO))) .build(); Map data = new HashMap<>(); @@ -1260,16 +1227,7 @@ void shouldBuildDataForPublishableNumberFieldWithNullValue() { .build(); caseTypeDefinition = newCaseType() - .withCaseFields(List.of( - newCaseField() - .withId(FIELD_ID) - .withFieldType(aFieldType() - .withId(NUMBER) - .withType(NUMBER) - .build()) - .build() - )) - .build(); + .withCaseFields(List.of(complexField(FIELD_ID, NUMBER))).build(); Map data = new HashMap<>(); data.put(FIELD_ID, NullNode.getInstance());