forked from MeasureAuthoringTool/madie-qdm-elm-translation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MeasureAuthoringTool/MAT-7294_translatorVe…
…rsion MAT-7294 translator versions
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/gov/cms/mat/cql_elm_translation/config/TranslatorVersionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gov.cms.mat.cql_elm_translation.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import lombok.Data; | ||
|
||
@Configuration | ||
@Data | ||
public class TranslatorVersionConfig { | ||
|
||
@Value("${madie.translatorVersion.currentVersion}") | ||
private String currentTranslatorVersion; | ||
|
||
@Value("${madie.translatorVersion.mostRecentVersion}") | ||
private String mostRecentTranslatorVersion; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/gov/cms/mat/cql_elm_translation/controllers/TranslatorVersionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gov.cms.mat.cql_elm_translation.controllers; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import gov.cms.mat.cql_elm_translation.config.TranslatorVersionConfig; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/translator-version") | ||
public class TranslatorVersionController { | ||
|
||
private TranslatorVersionConfig translatorVersionConfig; | ||
|
||
@GetMapping() | ||
public ResponseEntity<String> getTranslatorVersion( | ||
@RequestParam(required = true, name = "draft") boolean draft) { | ||
log.info( | ||
"Current translator version: " + translatorVersionConfig.getCurrentTranslatorVersion()); | ||
log.info( | ||
"Most recent translator version: " | ||
+ translatorVersionConfig.getMostRecentTranslatorVersion()); | ||
String result = | ||
draft | ||
? translatorVersionConfig.getMostRecentTranslatorVersion() | ||
: translatorVersionConfig.getCurrentTranslatorVersion(); | ||
return ResponseEntity.status(HttpStatus.OK).body(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...est/java/gov/cms/mat/cql_elm_translation/controllers/TranslatorVersionControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package gov.cms.mat.cql_elm_translation.controllers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.lenient; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import gov.cms.mat.cql_elm_translation.config.TranslatorVersionConfig; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class TranslatorVersionControllerTest { | ||
|
||
@Mock private TranslatorVersionConfig translatorVersionConfig; | ||
@InjectMocks private TranslatorVersionController translatorVersionController; | ||
|
||
private static final String CURRENT_VERSION = "3.3.2"; | ||
private static final String MOST_RECENT_VERSION = "3.10.0"; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
lenient() | ||
.when(translatorVersionConfig.getCurrentTranslatorVersion()) | ||
.thenReturn(CURRENT_VERSION); | ||
lenient() | ||
.when(translatorVersionConfig.getMostRecentTranslatorVersion()) | ||
.thenReturn(MOST_RECENT_VERSION); | ||
} | ||
|
||
@Test | ||
public void testGetTranslatorVersionIsDraft() { | ||
ResponseEntity<String> results = translatorVersionController.getTranslatorVersion(true); | ||
assertTrue(results.getStatusCode().equals(HttpStatus.OK)); | ||
assertEquals(results.getBody(), MOST_RECENT_VERSION); | ||
} | ||
|
||
@Test | ||
public void testGetTranslatorVersionVersioned() { | ||
ResponseEntity<String> results = translatorVersionController.getTranslatorVersion(false); | ||
assertTrue(results.getStatusCode().equals(HttpStatus.OK)); | ||
assertEquals(results.getBody(), CURRENT_VERSION); | ||
} | ||
} |