Skip to content

Commit

Permalink
POST NIAD-3114 refactoring: Refactor meta security assertions (#782)
Browse files Browse the repository at this point in the history
* refactoring tests to remove duplication assertions

* class name change

* addressing comments to PR

* checkstyle

* addressing PR comments
  • Loading branch information
ole4ryb authored Aug 22, 2024
1 parent b30bde3 commit afce944
Show file tree
Hide file tree
Showing 21 changed files with 238 additions and 296 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import static uk.nhs.adaptors.common.util.CodeableConceptUtils.createCodeableConcept;

import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallFile;

import java.util.List;
Expand Down Expand Up @@ -54,7 +54,7 @@

import lombok.SneakyThrows;

import uk.nhs.adaptors.pss.translator.MetaFactory;
import uk.nhs.adaptors.pss.translator.util.MetaUtil;
import uk.nhs.adaptors.pss.translator.TestUtility;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;
import uk.nhs.adaptors.pss.translator.util.DateFormatUtil;
Expand Down Expand Up @@ -118,7 +118,7 @@ void beforeEach() {
Mockito.lenient()
.when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
any(String.class), any(Optional.class), any(Optional.class)
)).thenReturn(MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
)).thenReturn(MetaUtil.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
}

@Test
Expand Down Expand Up @@ -370,7 +370,7 @@ void testGivenMultipleAllergiesThenExpectAllToBePresent() {

@Test
void testGivenAllergyIntoleranceWithNopatConfidentialityCodePresentWithinEhrCompositionExpectMetaSecurityAdded() {
final Meta stubbedMeta = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final Meta stubbedMeta = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("allergy-structure-with-ehr-composition-nopat-confidentiality-code.xml");

Expand All @@ -392,7 +392,7 @@ void testGivenAllergyIntoleranceWithNopatConfidentialityCodePresentWithinEhrComp

@Test
void testGivenAllergyIntoleranceWithNopatConfidentialityCodePresentWithinObservationStatementExpectMetaSecurityAdded() {
final Meta stubbedMeta = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final Meta stubbedMeta = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("allergy-structure-with-observation-statement-nopat-confidentiality-code.xml");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.util.ResourceUtils.getFile;

import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallFile;

import java.math.BigDecimal;
Expand Down Expand Up @@ -41,7 +43,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import lombok.SneakyThrows;
import uk.nhs.adaptors.pss.translator.MetaFactory;
import uk.nhs.adaptors.pss.translator.util.MetaUtil;
import uk.nhs.adaptors.pss.translator.TestUtility;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;
import uk.nhs.adaptors.pss.translator.util.DateFormatUtil;
Expand Down Expand Up @@ -113,7 +115,7 @@ public void setupDefaultStubs() {
.when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
any(),
any(Optional[].class)))
.thenReturn(MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
.thenReturn(MetaUtil.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
}

@Test
Expand All @@ -128,7 +130,7 @@ public void mapBloodPressureObservationWithValidData() {
.isEqualTo(DegradedCodeableConcepts.DEGRADED_OTHER);
assertThat(bloodPressure.getComponent().getFirst().getCode().getCoding().get(1).getDisplay())
.isEqualTo(CODING_DISPLAY_MOCK);
assertThat(bloodPressure.hasSubject()).isTrue();
assertTrue(bloodPressure.hasSubject());
assertThat(bloodPressure.getIssuedElement().asStringValue()).isEqualTo(ISSUED_EXAMPLE);
assertThat(bloodPressure.getEffective().toString()).isEqualTo(DateFormatUtil.parseToDateTimeType(EFFECTIVE_EXAMPLE).toString());
assertThat(bloodPressure.getPerformer().getFirst().getReference()).isEqualTo(PPRF_PARTICIPANT_ID);
Expand Down Expand Up @@ -167,22 +169,22 @@ public void mapBloodPressureWithNoOptionalData() {
assertThat(bloodPressure.getIssuedElement().asStringValue()).isEqualTo(ISSUED_EXAMPLE);
assertThat(bloodPressure.getPerformer().getFirst().getReference()).isEqualTo(PPRF_PARTICIPANT_ID);

assertThat(bloodPressure.getEffective()).isNull();
assertThat(StringUtils.isEmpty(bloodPressure.getComment())).isTrue();
assertNull(bloodPressure.getEffective());
assertTrue(StringUtils.isEmpty(bloodPressure.getComment()));

assertThat(bloodPressure.getComponent().getFirst().getCode().getCodingFirstRep())
.isEqualTo(DegradedCodeableConcepts.DEGRADED_OTHER);
assertThat(bloodPressure.getComponent().getFirst().getCode().getCoding().get(1).getDisplay())
.isEqualTo(CODING_DISPLAY_MOCK);
assertThat(bloodPressure.getComponent().getFirst().getValueQuantity()).isNull();
assertNull(bloodPressure.getComponent().getFirst().getValueQuantity());
assertThat(bloodPressure.getComponent().getFirst().getInterpretation().getCoding()).isEmpty();
assertThat(bloodPressure.getComponent().getFirst().getReferenceRange()).isEmpty();

assertThat(bloodPressure.getComponent().get(1).getCode().getCodingFirstRep())
.isEqualTo(DegradedCodeableConcepts.DEGRADED_OTHER);
assertThat(bloodPressure.getComponent().get(1).getCode().getCoding().get(1).getDisplay())
.isEqualTo(CODING_DISPLAY_MOCK);
assertThat(bloodPressure.getComponent().get(1).getValueQuantity()).isNull();
assertNull(bloodPressure.getComponent().get(1).getValueQuantity());
assertThat(bloodPressure.getComponent().get(1).getInterpretation().getCoding()).isEmpty();
assertThat(bloodPressure.getComponent().get(1).getReferenceRange()).isEmpty();
}
Expand All @@ -195,9 +197,9 @@ public void mapBloodPressureWithNoOptionalData() {
"diastolic_observation_containing_confidentiality_code"
})
public void When_MappingBloodPressureWithConfidentialityCodes_Expect_BloodPressureObservationContainsSecurityMeta(
String inputXml
) {
final var metaFromConfidentialityService = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
String inputXml) {

final var metaFromConfidentialityService = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
when(
confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
eq(META_PROFILE),
Expand Down Expand Up @@ -248,7 +250,7 @@ public void mapBloodPressureObservationWithCompositionIdMatchingEncounter() {

var bloodPressure = bloodPressureMapper.mapResources(ehrExtract, patient, ENCOUNTER_LIST, PRACTISE_CODE).getFirst();

assertThat(bloodPressure.hasContext()).isTrue();
assertTrue(bloodPressure.hasContext());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -95,8 +97,7 @@ public void mapSnomedCodeWithConceptIdDisplayNameDescriptionIsNotPreferredTerm()
.isEqualTo("22298006");
assertThat(codeableConcept.getCoding().getFirst().getDisplay())
.isEqualTo(SNOMED_PREFERRED.getTerm());
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 2)
.isTrue();
assertTrue(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 2);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_ID);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getValue())
Expand Down Expand Up @@ -127,8 +128,7 @@ public void mapSnomedCodeWithConceptIdDisplayNameOriginalTextNoMatchedDescriptio
.isEqualTo(CONCEPT_ID);
assertThat(codeableConcept.getCoding().getFirst().getDisplay())
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1)
.isTrue();
assertTrue(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_DISPLAY);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getValue().toString())
Expand All @@ -153,8 +153,7 @@ public void mapSnomedCodeWithConceptIdDisplayNameNoOriginalTextNoMatchedDescript
.isEqualTo(CONCEPT_ID);
assertThat(codeableConcept.getCoding().getFirst().getDisplay())
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1)
.isTrue();
assertTrue(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_DISPLAY);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getValue().toString())
Expand All @@ -180,8 +179,7 @@ public void mapSnomedCodeWithConceptIdNoDisplayName() {
.isEqualTo(CONCEPT_ID);
assertThat(codeableConcept.getCoding().getFirst().getDisplay())
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1)
.isTrue();
assertTrue(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().size() == 1);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_ID);
assertThat(codeableConcept.getCoding().getFirst().getExtension().getFirst().getExtension().getFirst().getValue())
Expand All @@ -206,8 +204,7 @@ public void mapSnomedCodeWithConceptIdDisplayNameInTranslationMainCode() {
.isEqualTo(CONCEPT_ID);
assertThat(codeableConcept.getCoding().get(1).getDisplay())
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().size() == 1)
.isTrue();
assertTrue(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().size() == 1);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_DISPLAY);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().getFirst().getValue().toString())
Expand All @@ -233,8 +230,7 @@ public void mapSnomedCodeWithConceptIdDisplayNameInTranslationMainCodeNoOriginal
.isEqualTo(CONCEPT_ID);
assertThat(codeableConcept.getCoding().get(1).getDisplay())
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().size() == 1)
.isTrue();
assertTrue(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().size() == 1);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().getFirst().getUrl())
.isEqualTo(DESCRIPTION_DISPLAY);
assertThat(codeableConcept.getCoding().get(1).getExtension().getFirst().getExtension().getFirst().getValue().toString())
Expand Down Expand Up @@ -285,8 +281,7 @@ public void mapSnomedCodeWithConceptIdNoMatchingDescriptionNoOriginalText() {
.isEqualTo(DISPLAY_NAME_1);
assertThat(codeableConcept.getCoding().getFirst().getExtension())
.isNullOrEmpty();
assertThat(codeableConcept.getText())
.isNull();
assertNull(codeableConcept.getText());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITHOUT_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.MetaUtil.MetaType.META_WITH_SECURITY;
import static uk.nhs.adaptors.pss.translator.util.DateFormatUtil.parseToDateTimeType;
import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallFile;

Expand Down Expand Up @@ -52,7 +53,7 @@

import lombok.SneakyThrows;
import uk.nhs.adaptors.pss.translator.FileFactory;
import uk.nhs.adaptors.pss.translator.MetaFactory;
import uk.nhs.adaptors.pss.translator.util.MetaUtil;
import uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;
import uk.nhs.adaptors.pss.translator.util.DegradedCodeableConcepts;
Expand Down Expand Up @@ -310,15 +311,15 @@ void mapConditionWithSnomedCodeInCoding() {

@Test
void When_Condition_With_NopatConfidentialityCode_Expect_MetaFromConfidentialityServiceWithSecurity() {
final Meta metaWithSecurity = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final Meta metaWithSecurity = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("linkset_valid_nopat_confidentiality_code.xml");

when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
eq(META_PROFILE),
confidentialityCodeCaptor.capture(),
confidentialityCodeCaptor.capture()
)).thenReturn(MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE));
)).thenReturn(MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE));

final List<Condition> conditions = conditionMapper
.mapResources(ehrExtract, patient, Collections.emptyList(), PRACTISE_CODE);
Expand All @@ -337,15 +338,15 @@ void When_Condition_With_NopatConfidentialityCode_Expect_MetaFromConfidentiality

@Test
void When_Condition_With_NopatConfidentialityCodeInEhrComposition_Expect_MetaFromConfidentialityServiceWithSecurity() {
final Meta metaWithSecurity = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final Meta metaWithSecurity = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("linkset_valid_ehr_composition_nopat_confidentiality_code.xml");

when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
eq(META_PROFILE),
confidentialityCodeCaptor.capture(),
confidentialityCodeCaptor.capture()
)).thenReturn(MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE));
)).thenReturn(MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE));

final List<Condition> conditions = conditionMapper
.mapResources(ehrExtract, patient, Collections.emptyList(), PRACTISE_CODE);
Expand Down Expand Up @@ -421,7 +422,7 @@ private void assertRelatedClinicalContentExtension(Condition condition) {
}

private void assertGeneratedComponentsAreCorrect(Condition condition) {
assertThat(condition.getMeta().getProfile().getFirst()).isNotNull();
assertNotNull(condition.getMeta().getProfile().getFirst());
assertThat(condition.getIdentifierFirstRep().getValue()).isEqualTo(LINKSET_ID);
assertThat(condition.getCategoryFirstRep().getCodingFirstRep().getDisplay()).isEqualTo("Problem List Item");
}
Expand Down Expand Up @@ -461,6 +462,6 @@ private void configureCommonStubs() {
eq(META_PROFILE),
confidentialityCodeCaptor.capture(),
confidentialityCodeCaptor.capture()
)).thenReturn(MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
)).thenReturn(MetaUtil.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
}
}
Loading

0 comments on commit afce944

Please sign in to comment.