Skip to content

Commit

Permalink
#382 - Change display and translations structure for criteria and con…
Browse files Browse the repository at this point in the history
…cepts

- adapt tests to the new structure
  • Loading branch information
michael-82 committed Oct 21, 2024
1 parent 40ab779 commit cd2a5b0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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<Translation> translations = List.of(createDummyTranslation(), createDummyTranslation(), createDummyTranslation());
Collection<Relative> parents = List.of(createDummyRelative(), createDummyRelative());
Collection<Relative> children = List.of(createDummyRelative(), createDummyRelative(), createDummyRelative(), createDummyRelative());
Collection<Relative> 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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand All @@ -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()))
Expand All @@ -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()))
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit cd2a5b0

Please sign in to comment.