|
| 1 | +// package gov.cms.bfd.server.war; |
| 2 | +// |
| 3 | +// import static org.junit.Assert.*; |
| 4 | +// import static org.mockito.Mockito.*; |
| 5 | +// |
| 6 | +// import ca.uhn.fhir.rest.api.server.RequestDetails; |
| 7 | +// import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; |
| 8 | +// import ca.uhn.fhir.rest.server.interceptor.consent.ConsentOutcome; |
| 9 | +// import java.util.Collections; |
| 10 | +// import org.hl7.fhir.instance.model.api.IBaseResource; |
| 11 | +// import org.hl7.fhir.r4.model.Bundle; |
| 12 | +// import org.hl7.fhir.r4.model.Claim; |
| 13 | +// import org.hl7.fhir.r4.model.Meta; |
| 14 | +// import org.junit.Before; |
| 15 | +// import org.junit.Test; |
| 16 | +// import org.mockito.*; |
| 17 | +// |
| 18 | +// public class V2SamhsaConsentInterceptorTest { |
| 19 | +// |
| 20 | +// @Mock private RequestDetails requestDetails; |
| 21 | +// |
| 22 | +// @Mock private IConsentContextServices contextServices; |
| 23 | +// |
| 24 | +// @Mock private IBaseResource claimResource; |
| 25 | +// |
| 26 | +// @Mock private Bundle bundle; |
| 27 | +// |
| 28 | +// @Mock private V2SamhsaConsentInterceptor v2SamhsaConsentInterceptor; |
| 29 | +// |
| 30 | +// @Before |
| 31 | +// public void setUp() { |
| 32 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(false); |
| 33 | +// MockitoAnnotations.openMocks(this); |
| 34 | +// } |
| 35 | +// |
| 36 | +// @Test |
| 37 | +// public void testWillSeeResource_whenSamhsaV2EnabledAndExcludeSAMHSAFalse() { |
| 38 | +// // Test with SAMHSA filtering enabled and "excludeSAMHSA" flag set to false |
| 39 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(true); |
| 40 | +// |
| 41 | +// when(requestDetails.getParameters()).thenReturn(Collections.emptyMap()); |
| 42 | +// when(claimResource.getMeta()).thenReturn(new Meta()); |
| 43 | +// |
| 44 | +// ConsentOutcome outcome = |
| 45 | +// v2SamhsaConsentInterceptor.willSeeResource(requestDetails, claimResource, |
| 46 | +// contextServices); |
| 47 | +// |
| 48 | +// assertEquals(ConsentOutcome.PROCEED, outcome); |
| 49 | +// } |
| 50 | +// |
| 51 | +// @Test |
| 52 | +// public void testWillSeeResource_whenSamhsaV2Disabled() { |
| 53 | +// // Test with SAMHSA filtering disabled |
| 54 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(false); |
| 55 | +// |
| 56 | +// when(requestDetails.getParameters()).thenReturn(Collections.emptyMap()); |
| 57 | +// |
| 58 | +// ConsentOutcome outcome = |
| 59 | +// v2SamhsaConsentInterceptor.willSeeResource(requestDetails, claimResource, |
| 60 | +// contextServices); |
| 61 | +// |
| 62 | +// assertEquals(ConsentOutcome.PROCEED, outcome); |
| 63 | +// } |
| 64 | +// |
| 65 | +// @Test |
| 66 | +// public void testWillSeeResource_whenSamhsaV2EnabledAndMatchingSAMHSA() { |
| 67 | +// // Test with SAMHSA filtering enabled and a resource having matching SAMHSA tag |
| 68 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(true); |
| 69 | +// |
| 70 | +// // Setup request with "excludeSAMHSA" set to true |
| 71 | +// when(requestDetails.getParameters()) |
| 72 | +// .thenReturn(Collections.singletonMap("excludeSAMHSA", new String[] {"true"})); |
| 73 | +// |
| 74 | +// // Mock a Claim resource with a SAMHSA tag |
| 75 | +// Claim claim = new Claim(); |
| 76 | +// Meta meta = new Meta(); |
| 77 | +// claim.setMeta(meta); |
| 78 | +// |
| 79 | +// // Add SAMHSA tag ("42CFRPart2") |
| 80 | +// meta.addSecurity().setCode("42CFRPart2"); |
| 81 | +// |
| 82 | +// // Mock the Bundle entry to contain this claim resource |
| 83 | +// Bundle.BundleEntryComponent entry = mock(Bundle.BundleEntryComponent.class); |
| 84 | +// when(entry.getResource()).thenReturn(claim); |
| 85 | +// |
| 86 | +// // Mock the Bundle to contain the entry |
| 87 | +// when(bundle.getEntry()).thenReturn(Collections.singletonList(entry)); |
| 88 | +// |
| 89 | +// // Call willSeeResource with the Bundle containing the claim |
| 90 | +// ConsentOutcome outcome = |
| 91 | +// v2SamhsaConsentInterceptor.willSeeResource(requestDetails, bundle, contextServices); |
| 92 | +// |
| 93 | +// // Assert that the outcome is PROCEED (or any other expected outcome) |
| 94 | +// assertEquals(ConsentOutcome.PROCEED, outcome); |
| 95 | +// } |
| 96 | +// |
| 97 | +// // @Test |
| 98 | +// // public void testRedactSensitiveData() { |
| 99 | +// // // Test the redactSensitiveData method by mocking a resource |
| 100 | +// // Bundle.BundleEntryComponent entryComponent = mock(Bundle.BundleEntryComponent.class); |
| 101 | +// // Claim claim = mock(Claim.class); |
| 102 | +// // |
| 103 | +// // when(entryComponent.getResource()).thenReturn(claim); |
| 104 | +// // |
| 105 | +// // // Test that redaction happens |
| 106 | +// // v2SamhsaConsentInterceptor.redactSensitiveData(entryComponent); |
| 107 | +// // |
| 108 | +// // verify(v2SamhsaConsentInterceptor, times(1)).redactSensitiveData(any()); |
| 109 | +// // } |
| 110 | +// |
| 111 | +// @Test |
| 112 | +// public void testStartOperation() { |
| 113 | +// // Test startOperation method |
| 114 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(true); |
| 115 | +// |
| 116 | +// ConsentOutcome outcome = |
| 117 | +// v2SamhsaConsentInterceptor.startOperation(requestDetails, contextServices); |
| 118 | +// |
| 119 | +// assertEquals(ConsentOutcome.PROCEED, outcome); |
| 120 | +// } |
| 121 | +// |
| 122 | +// @Test |
| 123 | +// public void testCompleteOperationSuccess() { |
| 124 | +// // Test completeOperationSuccess method |
| 125 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(true); |
| 126 | +// |
| 127 | +// v2SamhsaConsentInterceptor.completeOperationSuccess(requestDetails, contextServices); |
| 128 | +// |
| 129 | +// // Ensure no exceptions, logging, or errors happen |
| 130 | +// } |
| 131 | +// |
| 132 | +// @Test |
| 133 | +// public void testCompleteOperationFailure() { |
| 134 | +// // Test completeOperationFailure method |
| 135 | +// v2SamhsaConsentInterceptor = new V2SamhsaConsentInterceptor(true); |
| 136 | +// |
| 137 | +// BaseServerResponseException exception = mock(BaseServerResponseException.class); |
| 138 | +// |
| 139 | +// v2SamhsaConsentInterceptor.completeOperationFailure(requestDetails, exception, |
| 140 | +// contextServices); |
| 141 | +// |
| 142 | +// // Ensure no exceptions, logging, or errors happen |
| 143 | +// } |
| 144 | +// } |
0 commit comments