From ce007d3875dd7c05268e496c8f86ccd6731587b9 Mon Sep 17 00:00:00 2001 From: Edwin Tan Date: Tue, 19 Nov 2024 15:07:44 -0800 Subject: [PATCH 1/4] MAT-7852: set activeOnly argument to false when expansion type is Latest --- .../terminology/dto/ValueSetsSearchCriteria.java | 1 + .../service/FhirTerminologyService.java | 1 + .../terminology/util/TerminologyServiceUtil.java | 9 +++++++-- .../FhirTerminologyServiceWebClient.java | 3 ++- .../service/FhirTerminologyServiceTest.java | 15 +++++++++------ .../FhirTerminologyServiceWebClientTest.java | 15 ++++++++------- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java b/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java index 2bdc1c3..43e99bc 100644 --- a/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java +++ b/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java @@ -12,6 +12,7 @@ public class ValueSetsSearchCriteria { private String profile; private String includeDraft; + private String activeOnly; private ManifestExpansion manifestExpansion; private List valueSetParams; diff --git a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java index d5c7803..f6e2441 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -64,6 +64,7 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( vsParam, valueSetsSearchCriteria.getProfile(), valueSetsSearchCriteria.getIncludeDraft(), + valueSetsSearchCriteria.getActiveOnly(), valueSetsSearchCriteria.getManifestExpansion()); ValueSet valueSetResource = parser.parseResource(ValueSet.class, resource); diff --git a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java index 35f17e2..5ae3bb9 100644 --- a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java +++ b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java @@ -116,6 +116,7 @@ public static URI buildValueSetResourceUri( ValueSetsSearchCriteria.ValueSetParams valueSetParams, String profile, String includeDraft, + String activeOnly, ManifestExpansion manifestExpansion) { MultiValueMap params = new LinkedMultiValueMap<>(); String expandValueSetUri = "/ValueSet/" + valueSetParams.getOid() + "/$expand"; @@ -134,8 +135,12 @@ public static URI buildValueSetResourceUri( } else if (manifestExpansion != null && StringUtils.isNotBlank(manifestExpansion.getFullUrl())) { params.put("manifest", List.of(manifestExpansion.getFullUrl())); - } else if (StringUtils.isNotBlank(includeDraft)) { - params.put("includeDraft", List.of("true")); + } else { + if (StringUtils.isNotBlank(includeDraft)) { + params.put("includeDraft", List.of("true")); + } + + params.put("activeOnly", List.of(activeOnly)); } return UriComponentsBuilder.fromPath(expandValueSetUri).queryParams(params).build().toUri(); diff --git a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java index 395054c..8ac2131 100644 --- a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java +++ b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java @@ -108,11 +108,12 @@ public String getValueSetResource( ValueSetsSearchCriteria.ValueSetParams valueSetParams, String profile, String includeDraft, + String activeOnly, ManifestExpansion manifestExpansion) { profile = StringUtils.isNotBlank(profile) ? defaultProfile : profile; URI uri = TerminologyServiceUtil.buildValueSetResourceUri( - valueSetParams, profile, includeDraft, manifestExpansion); + valueSetParams, profile, includeDraft, activeOnly, manifestExpansion); return fetchResourceFromVsac(uri.toString(), apiKey, "ValueSet"); } diff --git a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java index 78a012d..f3b6ca1 100644 --- a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java +++ b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java @@ -173,6 +173,7 @@ void getValueSetsExpansionsForQdm_When_ManifestExpansionIsProvided() { .build())) .profile("test-profile") .includeDraft("false") + .activeOnly("true") .manifestExpansion( ManifestExpansion.builder() .fullUrl("https://cts.nlm.nih.gov/fhir/Library/ecqm-update-2022-05-05") @@ -180,7 +181,7 @@ void getValueSetsExpansionsForQdm_When_ManifestExpansionIsProvided() { .build()) .build(); when(fhirTerminologyServiceWebClient.getValueSetResource( - anyString(), any(), anyString(), anyString(), any())) + anyString(), any(), anyString(), anyString(), anyString(), any())) .thenReturn(mockValueSetResourceWithCodes); when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); when(mappingService.getCodeSystemEntries()).thenReturn(codeSystemEntries); @@ -209,6 +210,7 @@ void getsValueSetsExpansionsForQdm_withNoCodes_When_ManifestExpansionIsProvided( .build())) .profile("test-profile") .includeDraft("false") + .activeOnly("false") .manifestExpansion( ManifestExpansion.builder() .fullUrl("https://cts.nlm.nih.gov/fhir/Library/ecqm-update-2022-05-05") @@ -217,11 +219,12 @@ void getsValueSetsExpansionsForQdm_withNoCodes_When_ManifestExpansionIsProvided( .build(); when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); when(fhirTerminologyServiceWebClient.getValueSetResource( - anyString(), - any(ValueSetsSearchCriteria.ValueSetParams.class), - anyString(), - anyString(), - any(ManifestExpansion.class))) + anyString(), + any(ValueSetsSearchCriteria.ValueSetParams.class), + anyString(), + anyString(), + anyString(), + any(ManifestExpansion.class))) .thenReturn(mockValueSetResourceWithNoCodes); when(mappingService.getCodeSystemEntries()).thenReturn(codeSystemEntries); List result = diff --git a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java index 10c84f2..6e9bef5 100644 --- a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java +++ b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java @@ -91,11 +91,11 @@ void getLatestValueSetResourceSuccessfully_when_noCustomSearchCriteriaIsProvided .addHeader("Content-Type", "application/fhir+json")); String actualResponse = fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, new ManifestExpansion()); + MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion()); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand", recordedRequest.getPath()); + assertEquals("/ValueSet/test-vs-id/$expand?activeOnly=false", recordedRequest.getPath()); } @Test @@ -108,11 +108,11 @@ void getDraftValueSetResourceSuccessfully_when_noCustomSearchCriteriaIsProvided( .addHeader("Content-Type", "application/fhir+json")); String actualResponse = fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, "yes", new ManifestExpansion()); + MOCK_API_KEY, testValueSetParams, null, "yes", "false", new ManifestExpansion()); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand?includeDraft=true", recordedRequest.getPath()); + assertEquals("/ValueSet/test-vs-id/$expand?includeDraft=true&activeOnly=false", recordedRequest.getPath()); } @Test @@ -129,6 +129,7 @@ void getValueSetResourceSuccessfully_when_manifestExpansionIsProvided() testValueSetParams, null, null, + "true", ManifestExpansion.builder() .id("test-manifest-456") .fullUrl("https://cts.nlm.nih.gov/fhir/Library/test-manifest-456") @@ -152,7 +153,7 @@ void getValueSetResourceSuccessfully_when_ValueSetVersionIsProvided() testValueSetParams.setVersion("test-value-set-version-2024"); String actualResponse = fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, new ManifestExpansion()); + MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion()); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); @@ -169,9 +170,9 @@ void getValueSetResource_ReturnsException() throws InterruptedException { WebClientResponseException.class, () -> fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, new ManifestExpansion())); + MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion())); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand", recordedRequest.getPath()); + assertEquals("/ValueSet/test-vs-id/$expand?activeOnly=false", recordedRequest.getPath()); } @Test From bbbb9adbeec520e09c5f5f829a9fd73046195bcc Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Mon, 25 Nov 2024 15:54:32 +0000 Subject: [PATCH 2/4] fix: pom.xml to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JAVA-CAUHNHAPIFHIR-8344146 - https://snyk.io/vuln/SNYK-JAVA-CAUHNHAPIFHIR-8344149 - https://snyk.io/vuln/SNYK-JAVA-CAUHNHAPIFHIR-8366323 - https://snyk.io/vuln/SNYK-JAVA-CAUHNHAPIFHIR-8366327 - https://snyk.io/vuln/SNYK-JAVA-COMMONSIO-8161190 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1ce688d..87938d1 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ ca.uhn.hapi.fhir hapi-fhir-structures-r4 - 7.4.4 + 7.6.0 From ccd894aeb9632e218332b897dcd15662193fdbb8 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Mon, 9 Dec 2024 08:33:32 -0600 Subject: [PATCH 3/4] MAT-4169 UMLS logout --- pom.xml | 4 +-- .../TerminologyServiceApplication.java | 2 +- .../controller/VsacController.java | 9 ++++++ .../repositories/UmlsUserRepository.java | 2 ++ .../terminology/service/VsacService.java | 9 ++++++ .../controller/VsacControllerTest.java | 22 ++++++++++++++ .../service/FhirTerminologyServiceTest.java | 12 ++++---- .../terminology/service/VsacServiceTest.java | 30 +++++++++++++++++++ .../FhirTerminologyServiceWebClientTest.java | 4 ++- 9 files changed, 84 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 87938d1..a776509 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent 3.2.11 - + gov.cms.madie.terminologyservice @@ -167,7 +167,7 @@ - + diff --git a/src/main/java/gov/cms/madie/terminology/TerminologyServiceApplication.java b/src/main/java/gov/cms/madie/terminology/TerminologyServiceApplication.java index 0832521..2dfad47 100644 --- a/src/main/java/gov/cms/madie/terminology/TerminologyServiceApplication.java +++ b/src/main/java/gov/cms/madie/terminology/TerminologyServiceApplication.java @@ -25,7 +25,7 @@ public WebMvcConfigurer corsConfigurer() { public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") - .allowedMethods("PUT", "POST", "GET") + .allowedMethods("PUT", "POST", "GET", "DELETE") .allowedOrigins( "http://localhost:9000", "https://dev-madie.hcqis.org", diff --git a/src/main/java/gov/cms/madie/terminology/controller/VsacController.java b/src/main/java/gov/cms/madie/terminology/controller/VsacController.java index a73fc16..19b80a8 100644 --- a/src/main/java/gov/cms/madie/terminology/controller/VsacController.java +++ b/src/main/java/gov/cms/madie/terminology/controller/VsacController.java @@ -8,6 +8,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -134,4 +135,12 @@ public ResponseEntity checkUserLogin(Principal principal) { ? ResponseEntity.ok().body(Boolean.TRUE) : new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } + + @DeleteMapping("/umls-credentials") + public ResponseEntity umlsLogout(Principal principal) { + log.info("Entering: umlsLogout(): username = " + principal.getName()); + return vsacService.logoutUMLSUser(principal.getName()) + ? ResponseEntity.ok().body(Boolean.TRUE) + : new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } } diff --git a/src/main/java/gov/cms/madie/terminology/repositories/UmlsUserRepository.java b/src/main/java/gov/cms/madie/terminology/repositories/UmlsUserRepository.java index a13a69f..eb4aaf7 100644 --- a/src/main/java/gov/cms/madie/terminology/repositories/UmlsUserRepository.java +++ b/src/main/java/gov/cms/madie/terminology/repositories/UmlsUserRepository.java @@ -10,4 +10,6 @@ public interface UmlsUserRepository extends MongoRepository { Optional findByHarpId(String harpId); Optional findByHarpIdAndApiKey(String harpId, String apiKey); + + Optional deleteByHarpId(String harpId); } diff --git a/src/main/java/gov/cms/madie/terminology/service/VsacService.java b/src/main/java/gov/cms/madie/terminology/service/VsacService.java index fa17250..084cc52 100644 --- a/src/main/java/gov/cms/madie/terminology/service/VsacService.java +++ b/src/main/java/gov/cms/madie/terminology/service/VsacService.java @@ -358,4 +358,13 @@ private List getValueSetConcepts(DescribedValueSet valueSet public Optional findByHarpId(String harpId) { return umlsUserRepository.findByHarpId(harpId); } + + public boolean logoutUMLSUser(String userName) { + UmlsUser user = verifyUmlsAccess(userName); + boolean deleted = false; + Optional deletedUser = umlsUserRepository.deleteByHarpId(userName); + deleted = deletedUser.isPresent(); + log.info("Log out UMLS User:{} : {}.", user.getHarpId(), deleted); + return deleted; + } } diff --git a/src/test/java/gov/cms/madie/terminology/controller/VsacControllerTest.java b/src/test/java/gov/cms/madie/terminology/controller/VsacControllerTest.java index a155cd1..f2d9c50 100644 --- a/src/test/java/gov/cms/madie/terminology/controller/VsacControllerTest.java +++ b/src/test/java/gov/cms/madie/terminology/controller/VsacControllerTest.java @@ -133,4 +133,26 @@ void testInvalidUserUmlsLogin() { assertEquals(response.getStatusCode(), HttpStatus.UNAUTHORIZED); } + + @Test + void testUserUmlsLogout() { + Principal principal = mock(Principal.class); + when(principal.getName()).thenReturn(TEST_USER); + + when(vsacService.logoutUMLSUser(anyString())).thenReturn(true); + ResponseEntity response = vsacController.umlsLogout(principal); + + assertEquals(response.getBody(), Boolean.TRUE); + } + + @Test + void testUserUmlsLogoutFailed() { + Principal principal = mock(Principal.class); + when(principal.getName()).thenReturn(TEST_USER); + + when(vsacService.logoutUMLSUser(anyString())).thenReturn(false); + ResponseEntity response = vsacController.umlsLogout(principal); + + assertEquals(response.getStatusCode(), HttpStatus.UNAUTHORIZED); + } } diff --git a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java index f3b6ca1..1fd0f67 100644 --- a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java +++ b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java @@ -219,12 +219,12 @@ void getsValueSetsExpansionsForQdm_withNoCodes_When_ManifestExpansionIsProvided( .build(); when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); when(fhirTerminologyServiceWebClient.getValueSetResource( - anyString(), - any(ValueSetsSearchCriteria.ValueSetParams.class), - anyString(), - anyString(), - anyString(), - any(ManifestExpansion.class))) + anyString(), + any(ValueSetsSearchCriteria.ValueSetParams.class), + anyString(), + anyString(), + anyString(), + any(ManifestExpansion.class))) .thenReturn(mockValueSetResourceWithNoCodes); when(mappingService.getCodeSystemEntries()).thenReturn(codeSystemEntries); List result = diff --git a/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java b/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java index b0148d9..e9f515c 100644 --- a/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java +++ b/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java @@ -592,4 +592,34 @@ void testGetCodeStatusIfCodeNotFoundInSvs() { CodeStatus status = vsacService.getCodeStatus(code, TEST_API_KEY); assertThat(status, is(equalTo(CodeStatus.NA))); } + + @Test + void testUserUmlsLogout() { + when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUser)); + UmlsUser user = vsacService.verifyUmlsAccess(TEST_API_KEY); + when(umlsUserRepository.deleteByHarpId(anyString())).thenReturn(Optional.of(umlsUser)); + boolean loggedOut = vsacService.logoutUMLSUser(umlsUser.getHarpId()); + assertThat(user.getHarpId(), is(equalTo(TEST_HARP_ID))); + assertThat(user.getApiKey(), is(equalTo(TEST_API_KEY))); + assertThat(loggedOut, is(equalTo(true))); + } + + @Test + void testUserUmlsLogoutUserNotFound() { + when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.empty()); + Exception exception = + assertThrows( + VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY)); + assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding"))); + } + + @Test + void testUserUmlsLogoutUserApiKeyIsMissing() { + UmlsUser umlsUserCopy = umlsUser.toBuilder().apiKey(null).build(); + when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUserCopy)); + Exception exception = + assertThrows( + VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY)); + assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding"))); + } } diff --git a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java index 6e9bef5..06cc5c2 100644 --- a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java +++ b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java @@ -112,7 +112,9 @@ void getDraftValueSetResourceSuccessfully_when_noCustomSearchCriteriaIsProvided( assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand?includeDraft=true&activeOnly=false", recordedRequest.getPath()); + assertEquals( + "/ValueSet/test-vs-id/$expand?includeDraft=true&activeOnly=false", + recordedRequest.getPath()); } @Test From 3b7e6b87a5f292243554dd157e9c6b029687a2a4 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Mon, 9 Dec 2024 13:34:14 -0600 Subject: [PATCH 4/4] MAT-4169 changed based on review --- .../terminology/service/VsacService.java | 10 ++++--- .../terminology/service/VsacServiceTest.java | 26 ++++--------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/service/VsacService.java b/src/main/java/gov/cms/madie/terminology/service/VsacService.java index 084cc52..07bab6d 100644 --- a/src/main/java/gov/cms/madie/terminology/service/VsacService.java +++ b/src/main/java/gov/cms/madie/terminology/service/VsacService.java @@ -360,11 +360,13 @@ public Optional findByHarpId(String harpId) { } public boolean logoutUMLSUser(String userName) { - UmlsUser user = verifyUmlsAccess(userName); - boolean deleted = false; Optional deletedUser = umlsUserRepository.deleteByHarpId(userName); - deleted = deletedUser.isPresent(); - log.info("Log out UMLS User:{} : {}.", user.getHarpId(), deleted); + boolean deleted = deletedUser.isPresent(); + if (deleted) { + log.info("Successfully deleted UMLS information for User Name: {}", userName); + } else { + log.error("Error while deleting UMLS information for User Name: {}", userName); + } return deleted; } } diff --git a/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java b/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java index e9f515c..45bc796 100644 --- a/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java +++ b/src/test/java/gov/cms/madie/terminology/service/VsacServiceTest.java @@ -595,31 +595,15 @@ void testGetCodeStatusIfCodeNotFoundInSvs() { @Test void testUserUmlsLogout() { - when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUser)); - UmlsUser user = vsacService.verifyUmlsAccess(TEST_API_KEY); when(umlsUserRepository.deleteByHarpId(anyString())).thenReturn(Optional.of(umlsUser)); boolean loggedOut = vsacService.logoutUMLSUser(umlsUser.getHarpId()); - assertThat(user.getHarpId(), is(equalTo(TEST_HARP_ID))); - assertThat(user.getApiKey(), is(equalTo(TEST_API_KEY))); - assertThat(loggedOut, is(equalTo(true))); + assertTrue(loggedOut); } @Test - void testUserUmlsLogoutUserNotFound() { - when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.empty()); - Exception exception = - assertThrows( - VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY)); - assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding"))); - } - - @Test - void testUserUmlsLogoutUserApiKeyIsMissing() { - UmlsUser umlsUserCopy = umlsUser.toBuilder().apiKey(null).build(); - when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUserCopy)); - Exception exception = - assertThrows( - VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY)); - assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding"))); + void testUserUmlsLogoutFailed() { + when(umlsUserRepository.deleteByHarpId(anyString())).thenReturn(Optional.empty()); + boolean loggedOut = vsacService.logoutUMLSUser(umlsUser.getHarpId()); + assertFalse(loggedOut); } }