From 74bea7ba1e93ae08c8f2573383dfb72c99670a38 Mon Sep 17 00:00:00 2001 From: Greg Akins Date: Thu, 12 Dec 2024 06:42:51 -0500 Subject: [PATCH] MAT-7929: Fixing conditional that wasn't checking for model/version matches correctly --- .../service/CqlLibraryService.java | 2 +- .../services/CqlLibraryServiceTest.java | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/cms/madie/cql_elm_translator/service/CqlLibraryService.java b/src/main/java/gov/cms/madie/cql_elm_translator/service/CqlLibraryService.java index 3b2584e..d83d61a 100644 --- a/src/main/java/gov/cms/madie/cql_elm_translator/service/CqlLibraryService.java +++ b/src/main/java/gov/cms/madie/cql_elm_translator/service/CqlLibraryService.java @@ -62,7 +62,7 @@ public String getLibraryCql(String name, String version, String accessToken) { UsingProperties libraryUsing = new CqlTextParser(responseEntity.getBody()).getUsing(); if (libraryUsing.getLine().equals(MadieLibrarySourceProvider.getUsingProperties().getLine()) - || supportedLibraries.contains(libraryUsing.getLibraryType())) { + && supportedLibraries.contains(libraryUsing.getLibraryType())) { return responseEntity.getBody(); } log.error("Library model and version does not match the Measure model and version"); diff --git a/src/test/java/gov/cms/madie/cql_elm_translator/services/CqlLibraryServiceTest.java b/src/test/java/gov/cms/madie/cql_elm_translator/services/CqlLibraryServiceTest.java index 48fc226..ee74676 100644 --- a/src/test/java/gov/cms/madie/cql_elm_translator/services/CqlLibraryServiceTest.java +++ b/src/test/java/gov/cms/madie/cql_elm_translator/services/CqlLibraryServiceTest.java @@ -78,7 +78,7 @@ void getLibraryCql() { } @Test - void getLibraryCqlThrowCqlIncludeException() { + void getLibraryCqlWrongModelThrowCqlIncludeException() { String cql = "library QICoreCommon version '1.3.000'\n" + "using QICore version '4.1.1'\n" @@ -97,6 +97,46 @@ void getLibraryCqlThrowCqlIncludeException() { () -> cqlLibraryService.getLibraryCql(cqlLibraryName, cqlLibraryVersion, accessToken)); } + @Test + void getLibraryCqlWrongVersionThrowCqlIncludeException() { + String cql = + "library QICoreCommon version '1.3.000'\n" + + "using QICore version '4.1.1'\n" + + "Response Cql String"; + cqlLibraryService.setUpLibrarySourceProvider(cql, "ACCESS_TOKEN"); + + String wrongLibrarycql = + "library QICoreCommon version '1.3.000'\n" + + "using QICore version '6.0.0'\n" + + "Response Cql String"; + when(restTemplate.exchange( + libraryUri, HttpMethod.GET, new HttpEntity<>(httpHeaders), String.class)) + .thenReturn(new ResponseEntity<>(wrongLibrarycql, HttpStatus.OK)); + assertThrows( + CqlIncludeException.class, + () -> cqlLibraryService.getLibraryCql(cqlLibraryName, cqlLibraryVersion, accessToken)); + } + + @Test + void getLibraryCqlWrongModelAndVersionThrowCqlIncludeException() { + String cql = + "library QICoreCommon version '1.3.000'\n" + + "using QICore version '4.1.1'\n" + + "Response Cql String"; + cqlLibraryService.setUpLibrarySourceProvider(cql, "ACCESS_TOKEN"); + + String wrongLibrarycql = + "library QICoreCommon version '1.3.000'\n" + + "using FHIR version '4.0.1'\n" + + "Response Cql String"; + when(restTemplate.exchange( + libraryUri, HttpMethod.GET, new HttpEntity<>(httpHeaders), String.class)) + .thenReturn(new ResponseEntity<>(wrongLibrarycql, HttpStatus.OK)); + assertThrows( + CqlIncludeException.class, + () -> cqlLibraryService.getLibraryCql(cqlLibraryName, cqlLibraryVersion, accessToken)); + } + @Test void getLibraryCqlReturnsNull() { when(restTemplate.exchange(