From cd2a5b065efa9b7bb77e939855e87401df792603 Mon Sep 17 00:00:00 2001 From: Michael Folz Date: Mon, 21 Oct 2024 13:54:31 +0200 Subject: [PATCH] #382 - Change display and translations structure for criteria and concepts - adapt tests to the new structure --- .../es/CodeableConceptServiceIT.java | 10 +++--- .../es/TerminologyEsServiceTest.java | 25 +++++++------ .../v4/CodeableConceptRestControllerIT.java | 36 ++++++++++++++++--- .../v4/TerminologyRestControllerIT.java | 32 ++++++++++------- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptServiceIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptServiceIT.java index f09a2683..5a93ce15 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptServiceIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptServiceIT.java @@ -85,7 +85,7 @@ void testPerformCodeableConceptSearchWithRepoAndPaging_findsOne() { assertNotNull(page); assertThat(page.getTotalHits()).isOne(); - Assertions.assertEquals("A1.0", page.getResults().get(0).code()); + Assertions.assertEquals("A1.0", page.getResults().get(0).termCode().code()); } @Test @@ -120,10 +120,10 @@ void testGetSearchResultEntryByCode_succeeds() { var result = assertDoesNotThrow(() -> codeableConceptService.getSearchResultEntryByCode("A1.1")); assertNotNull(result); - Assertions.assertEquals("bar", result.display()); - Assertions.assertEquals("A1.1", result.code()); - Assertions.assertEquals("2012", result.version()); - Assertions.assertEquals("another-system", result.system()); + Assertions.assertEquals("bar", result.termCode().display()); + Assertions.assertEquals("A1.1", result.termCode().code()); + Assertions.assertEquals("2012", result.termCode().version()); + Assertions.assertEquals("another-system", result.termCode().system()); } @Test diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java index b71ed0ec..0046feba 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java @@ -77,7 +77,7 @@ void testGetSearchResultEntryByHash() { assertThat(searchResultEntry).isNotNull(); assertThat(searchResultEntry.id()).isEqualTo(id); assertThat(searchResultEntry.terminology()).isEqualTo(dummyOntologyListItem.terminology()); - assertThat(searchResultEntry.name()).isEqualTo(dummyOntologyListItem.name()); + assertThat(searchResultEntry.display().original()).isEqualTo(dummyOntologyListItem.display().original()); assertThat(searchResultEntry.kdsModule()).isEqualTo(dummyOntologyListItem.kdsModule()); assertThat(searchResultEntry.availability()).isEqualTo(dummyOntologyListItem.availability()); assertThat(searchResultEntry.context()).isEqualTo(dummyOntologyListItem.context().code()); @@ -185,7 +185,7 @@ void testGetOntologyItemRelationsByHash_succeeds() { assertThat(ontologyItemRelationsDocument.relatedTerms()).isEqualTo(dummyOntologyItem.relatedTerms()); assertThat(ontologyItemRelationsDocument.children()).isEqualTo(dummyOntologyItem.children()); assertThat(ontologyItemRelationsDocument.parents()).isEqualTo(dummyOntologyItem.parents()); - assertThat(ontologyItemRelationsDocument.translations()).isEqualTo(dummyOntologyItem.translations()); + assertThat(ontologyItemRelationsDocument.display()).isEqualTo(dummyOntologyItem.display()); } @Test @@ -200,7 +200,7 @@ private OntologyListItemDocument createDummyOntologyListItem(String id) { return OntologyListItemDocument.builder() .id(id) - .name("Some Name") + .display(createDummyDisplay()) .availability(1) .context(termCode) .terminology("Some Terminology") @@ -209,35 +209,34 @@ private OntologyListItemDocument createDummyOntologyListItem(String id) { .build(); } + private Display createDummyDisplay() { + return Display.builder() + .original("Some Name") + .deDe("Some German Name") + .enUs("Some English Name") + .build(); + } + private OntologyItemDocument createDummyOntologyItem(String id) { TermCode termCode = createDummyTermCode(); - Collection translations = List.of(createDummyTranslation(), createDummyTranslation(), createDummyTranslation()); Collection parents = List.of(createDummyRelative(), createDummyRelative()); Collection children = List.of(createDummyRelative(), createDummyRelative(), createDummyRelative(), createDummyRelative()); Collection relatedTerms = List.of(createDummyRelative(), createDummyRelative()); return OntologyItemDocument.builder() .id(id) - .name("Some Name") + .display(createDummyDisplay()) .availability(1) .context(termCode) .terminology("Some Terminology") .termcode("Some Termcode") .kdsModule("Some KDS Module") - .translations(translations) .parents(parents) .children(children) .relatedTerms(relatedTerms) .build(); } - private Translation createDummyTranslation() { - return Translation.builder() - .lang("de") - .value("Lorem Ipsum") - .build(); - } - private Relative createDummyRelative() { return Relative.builder() .contextualizedTermcodeHash(UUID.randomUUID().toString()) diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestControllerIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestControllerIT.java index 9811a359..8b656e90 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestControllerIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestControllerIT.java @@ -1,10 +1,13 @@ package de.numcodex.feasibility_gui_backend.terminology.v4; import com.fasterxml.jackson.databind.ObjectMapper; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import de.numcodex.feasibility_gui_backend.common.api.TermCode; +import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue; import de.numcodex.feasibility_gui_backend.query.ratelimiting.RateLimitingInterceptor; import de.numcodex.feasibility_gui_backend.query.ratelimiting.RateLimitingServiceSpringConfig; import de.numcodex.feasibility_gui_backend.terminology.api.CcSearchResult; +import de.numcodex.feasibility_gui_backend.terminology.api.CodeableConceptEntry; import de.numcodex.feasibility_gui_backend.terminology.es.CodeableConceptService; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -63,10 +66,10 @@ void testSearchOntologyItemsCriteriaQuery_succeedsWith200() throws Exception { .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.totalHits").value(dummyCcSearchResult.getTotalHits())) .andExpect(jsonPath("$.results.length()").value(dummyCcSearchResult.getResults().size())) - .andExpect(jsonPath("$.results[0].code").value(dummyCcSearchResult.getResults().get(0).code())) - .andExpect(jsonPath("$.results[0].system").value(dummyCcSearchResult.getResults().get(0).system())) - .andExpect(jsonPath("$.results[0].version").value(dummyCcSearchResult.getResults().get(0).version())) - .andExpect(jsonPath("$.results[0].display").value(dummyCcSearchResult.getResults().get(0).display())); + .andExpect(jsonPath("$.results[0].code").value(dummyCcSearchResult.getResults().get(0).termCode().code())) + .andExpect(jsonPath("$.results[0].system").value(dummyCcSearchResult.getResults().get(0).termCode().system())) + .andExpect(jsonPath("$.results[0].version").value(dummyCcSearchResult.getResults().get(0).termCode().version())) + .andExpect(jsonPath("$.results[0].display").value(dummyCcSearchResult.getResults().get(0).termCode().display())); } @Test @@ -87,7 +90,30 @@ void testGetCodeableConceptByCode_succeedsWith200() throws Exception { private CcSearchResult createDummyCcSearchResult() { return CcSearchResult.builder() .totalHits(1) - .results(List.of(createDummyTermcode())) + .results(List.of(createDummyCodeableConceptEntry())) + .build(); + } + + private CodeableConceptEntry createDummyCodeableConceptEntry() { + return CodeableConceptEntry.builder() + .termCode(createDummyTermcode()) + .display(createDummyDisplayEntry()) + .build(); + } + + private DisplayEntry createDummyDisplayEntry() { + return DisplayEntry.builder() + .original("Code 1") + .translations(List.of( + LocalizedValue.builder() + .value("code 1") + .language("de-DE") + .build(), + LocalizedValue.builder() + .value("code 1") + .language("en-US") + .build() + )) .build(); } diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java index 8717c808..9d60026e 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.numcodex.feasibility_gui_backend.common.api.Comparator; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import de.numcodex.feasibility_gui_backend.common.api.TermCode; +import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue; import de.numcodex.feasibility_gui_backend.query.ratelimiting.RateLimitingInterceptor; import de.numcodex.feasibility_gui_backend.query.ratelimiting.RateLimitingServiceSpringConfig; import de.numcodex.feasibility_gui_backend.terminology.TerminologyService; @@ -132,7 +134,7 @@ public void testSearchOntologyItemsCriteriaQuery_succeeds() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.totalHits").value(dummyEsSearchResult.totalHits())) .andExpect(jsonPath("$.results[0].id").value(dummyEsSearchResult.results().get(0).id())) - .andExpect(jsonPath("$.results[0].name").value(dummyEsSearchResult.results().get(0).name())) + .andExpect(jsonPath("$.results[0].display.original").value(dummyEsSearchResult.results().get(0).display().original())) .andExpect(jsonPath("$.results[0].terminology").value(dummyEsSearchResult.results().get(0).terminology())) .andExpect(jsonPath("$.results[0].selectable").value(dummyEsSearchResult.results().get(0).selectable())) .andExpect(jsonPath("$.results[0].kdsModule").value(dummyEsSearchResult.results().get(0).kdsModule())) @@ -157,8 +159,6 @@ public void testGetOntologyItemRelationsByHash_succeeds() throws Exception { mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc/relations")).with(csrf())) .andExpect(status().isOk()) - .andExpect(jsonPath("$.translations[0].lang").value(dummyOntologyItemRelations.translations().stream().toList().get(0).lang())) - .andExpect(jsonPath("$.translations[0].value").value(dummyOntologyItemRelations.translations().stream().toList().get(0).value())) .andExpect(jsonPath("$.children[0].contextualizedTermcodeHash").value(dummyOntologyItemRelations.children().stream().toList().get(0).contextualizedTermcodeHash())) .andExpect(jsonPath("$.children[0].name").value(dummyOntologyItemRelations.children().stream().toList().get(0).name())) .andExpect(jsonPath("$.parents[0].contextualizedTermcodeHash").value(dummyOntologyItemRelations.parents().stream().toList().get(0).contextualizedTermcodeHash())) @@ -185,7 +185,7 @@ public void testGetOntologyItemByHash_succeeds() throws Exception { mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc")).with(csrf())) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").value(dummySearchResultEntry.id())) - .andExpect(jsonPath("$.name").value(dummySearchResultEntry.name())) + .andExpect(jsonPath("$.display.original").value(dummySearchResultEntry.display().original())) .andExpect(jsonPath("$.availability").value(dummySearchResultEntry.availability())) .andExpect(jsonPath("$.context").value(dummySearchResultEntry.context())) .andExpect(jsonPath("$.terminology").value(dummySearchResultEntry.terminology())) @@ -266,27 +266,33 @@ private EsSearchResultEntry createDummyEsSearchResultEntry() { .context("some-context") .id("abc-123") .kdsModule("some-module") - .name("some-name") + .display(createDummyDisplayEntry()) .selectable(true) .build(); } + private DisplayEntry createDummyDisplayEntry() { + return DisplayEntry.builder() + .original("some-name") + .translations(List.of(createDummyLocalizedValue())) + .build(); + } + + private LocalizedValue createDummyLocalizedValue() { + return LocalizedValue.builder() + .language("de-DE") + .value("some-name") + .build(); + } + private OntologyItemRelationsDocument createDummyOntologyItemRelations() { return OntologyItemRelationsDocument.builder() .relatedTerms(List.of(createDummyRelative())) - .translations(List.of(createDummyTranslation())) .parents(List.of(createDummyRelative())) .children(List.of(createDummyRelative())) .build(); } - private Translation createDummyTranslation() { - return Translation.builder() - .lang("de") - .value("Lorem Ipsum") - .build(); - } - private Relative createDummyRelative() { return Relative.builder() .contextualizedTermcodeHash(UUID.randomUUID().toString())