|
49 | 49 | import java.util.concurrent.atomic.AtomicReference; |
50 | 50 | import java.util.concurrent.locks.ReentrantLock; |
51 | 51 | import java.util.function.Function; |
| 52 | +import java.util.stream.Stream; |
52 | 53 |
|
53 | 54 | import org.apache.http.HttpVersion; |
54 | 55 | import org.apache.http.client.HttpClient; |
|
62 | 63 | import org.junit.jupiter.api.Timeout; |
63 | 64 | import org.junit.jupiter.api.extension.RegisterExtension; |
64 | 65 | import org.junit.jupiter.api.parallel.Isolated; |
| 66 | +import org.junit.jupiter.params.ParameterizedTest; |
| 67 | +import org.junit.jupiter.params.provider.Arguments; |
| 68 | +import org.junit.jupiter.params.provider.MethodSource; |
65 | 69 | import org.mockito.stubbing.Answer; |
66 | 70 |
|
67 | 71 | import com.auth0.jwt.JWT; |
@@ -1944,7 +1948,7 @@ void testPrependGetAllDestinationsCall() |
1944 | 1948 | .when(destinationServiceAdapter) |
1945 | 1949 | .getConfigurationAsJson(eq("/v1/subaccountDestinations"), any()); |
1946 | 1950 |
|
1947 | | - Destination result = loader.tryGetDestination(destinationName).get(); |
| 1951 | + loader.tryGetDestination(destinationName).get(); |
1948 | 1952 |
|
1949 | 1953 | verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any()); |
1950 | 1954 | verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any()); |
@@ -2003,4 +2007,62 @@ void testPrependGetAllDestinationsCallUsesCorrectRetrievalStrategy() |
2003 | 2007 | Destination result = loader.tryGetDestination(destinationName, options).get(); |
2004 | 2008 | assertThat(result.asHttp().getUri()).isEqualTo(URI.create(providerUrl)); |
2005 | 2009 | } |
| 2010 | + |
| 2011 | + @ParameterizedTest |
| 2012 | + @MethodSource("provideTestData") |
| 2013 | + void testPrependGetAllDestinationsCallSkipped(DestinationOptions options, String expectedPath) { |
| 2014 | + // Reset Cache to re-enable the PreLookupCheck |
| 2015 | + DestinationService.Cache.reset(); |
| 2016 | + |
| 2017 | + // additional mock for cross level test case |
| 2018 | + final String responseWithCrossLevel = """ |
| 2019 | + { |
| 2020 | + "destinationConfiguration": { |
| 2021 | + "Name": "%s", |
| 2022 | + "Type": "HTTP", |
| 2023 | + "URL": "https://foo.com", |
| 2024 | + "Description": "%s level destination" |
| 2025 | + } |
| 2026 | + } |
| 2027 | + """; |
| 2028 | + doReturn(responseWithCrossLevel.formatted(destinationName, "subaccount")) |
| 2029 | + .when(destinationServiceAdapter) |
| 2030 | + .getConfigurationAsJson(eq(expectedPath), any()); |
| 2031 | + |
| 2032 | + // call single destination with options |
| 2033 | + loader.tryGetDestination(destinationName, options).get(); |
| 2034 | + |
| 2035 | + // verify that there was no call to all-destination endpoints |
| 2036 | + verify(destinationServiceAdapter, times(0)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any()); |
| 2037 | + verify(destinationServiceAdapter, times(0)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any()); |
| 2038 | + verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq(expectedPath), any()); |
| 2039 | + verifyNoMoreInteractions(destinationServiceAdapter); |
| 2040 | + } |
| 2041 | + |
| 2042 | + private static Stream<Arguments> provideTestData() { |
| 2043 | + final Header h1 = new Header("X-Custom-Header-1", "value-1"); |
| 2044 | + final DestinationOptions optionsWithHeader = |
| 2045 | + DestinationOptions.builder().augmentBuilder(augmenter().customHeaders(h1)).build(); |
| 2046 | + |
| 2047 | + final DestinationOptions optionsWithSubaccount = |
| 2048 | + DestinationOptions |
| 2049 | + .builder() |
| 2050 | + .augmentBuilder( |
| 2051 | + DestinationServiceOptionsAugmenter |
| 2052 | + .augmenter() |
| 2053 | + .crossLevelConsumption(DestinationServiceOptionsAugmenter.CrossLevelScope.SUBACCOUNT)) |
| 2054 | + .build(); |
| 2055 | + |
| 2056 | + final DestinationOptions optionsWithFragment = DestinationOptions |
| 2057 | + .builder() |
| 2058 | + .augmentBuilder(DestinationServiceOptionsAugmenter.augmenter().fragmentName("a-fragment")) |
| 2059 | + .build(); |
| 2060 | + |
| 2061 | + |
| 2062 | + return Stream.of( |
| 2063 | + Arguments.of(optionsWithHeader, "/v1/destinations/" + destinationName), |
| 2064 | + Arguments.of(optionsWithSubaccount, "/v2/destinations/" + destinationName + "@subaccount"), |
| 2065 | + Arguments.of(optionsWithFragment, "/v1/destinations/" + destinationName) |
| 2066 | + ); |
| 2067 | + } |
2006 | 2068 | } |
0 commit comments