|
2 | 2 |
|
3 | 3 | import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationRetrievalStrategy.withUserToken; |
4 | 4 | import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationRetrievalStrategy.withoutToken; |
| 5 | +import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.CrossLevelScope.PROVIDER_SUBACCOUNT; |
5 | 6 | import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.DESTINATION_RETRIEVAL_STRATEGY_KEY; |
6 | 7 | import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.DESTINATION_TOKEN_EXCHANGE_STRATEGY_KEY; |
7 | 8 | import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.augmenter; |
|
51 | 52 | import java.util.function.Function; |
52 | 53 | import java.util.stream.Stream; |
53 | 54 |
|
| 55 | +import io.vavr.control.Option; |
| 56 | +import lombok.val; |
54 | 57 | import org.apache.http.HttpVersion; |
55 | 58 | import org.apache.http.client.HttpClient; |
56 | 59 | import org.apache.http.message.BasicHttpResponse; |
@@ -2006,7 +2009,7 @@ void testPrependGetAllDestinationsCallUsesCorrectRetrievalStrategy() |
2006 | 2009 | } |
2007 | 2010 |
|
2008 | 2011 | @ParameterizedTest |
2009 | | - @MethodSource("testCasesUncachedDestinationLookup") |
| 2012 | + @MethodSource( "testCasesUncachedDestinationLookup" ) |
2010 | 2013 | void testPrependGetAllDestinationsCallSkipped( final DestinationOptions options, final String expectedPath ) |
2011 | 2014 | { |
2012 | 2015 | // Reset Cache to re-enable the PreLookupCheck |
@@ -2060,4 +2063,59 @@ private static Stream<Arguments> testCasesUncachedDestinationLookup() |
2060 | 2063 | Arguments.of(optionsWithSubaccount, "/v2/destinations/" + destinationName + "@subaccount"), |
2061 | 2064 | Arguments.of(optionsWithFragment, "/v1/destinations/" + destinationName)); |
2062 | 2065 | } |
| 2066 | + |
| 2067 | + @Test |
| 2068 | + void testValidateDestinationLookup() |
| 2069 | + { |
| 2070 | + val OPTIONS_EMPTY = DestinationOptions.builder().build(); |
| 2071 | + val OPTIONS_EXPER = |
| 2072 | + DestinationOptions.builder().augmentBuilder(augmenter().crossLevelConsumption(PROVIDER_SUBACCOUNT)).build(); |
| 2073 | + val OPTIONS_CURRT = |
| 2074 | + DestinationOptions.builder().augmentBuilder(augmenter().retrievalStrategy(CURRENT_TENANT)).build(); |
| 2075 | + val OPTIONS_PROVT = |
| 2076 | + DestinationOptions.builder().augmentBuilder(augmenter().retrievalStrategy(ALWAYS_PROVIDER)).build(); |
| 2077 | + |
| 2078 | + val adapter = mock(DestinationServiceAdapter.class); |
| 2079 | + val sut = spy(new DestinationService(adapter)); |
| 2080 | + |
| 2081 | + val curr = List.of(DefaultHttpDestination.builder("http://current-tenant-1").name("current-dest-1").build()); |
| 2082 | + doReturn(curr).when(sut).getAllDestinationProperties(CURRENT_TENANT); |
| 2083 | + val prov = List.of(DefaultHttpDestination.builder("http://provider-tenant-1").name("provider-dest-1").build()); |
| 2084 | + doReturn(prov).when(sut).getAllDestinationProperties(ALWAYS_PROVIDER); |
| 2085 | + |
| 2086 | + // valid case: disabled cache |
| 2087 | + DestinationService.Cache.disable(); |
| 2088 | + assertThat(sut.validateDestinationLookup("unknown-dest-1", OPTIONS_EMPTY)).isEmpty(); |
| 2089 | + |
| 2090 | + // valid case: disabled pre-lookup check |
| 2091 | + DestinationService.Cache.reset(); |
| 2092 | + DestinationService.Cache.disablePreLookupCheck(); |
| 2093 | + assertThat(sut.validateDestinationLookup("unknown-dest-1", OPTIONS_EMPTY)).isEmpty(); |
| 2094 | + |
| 2095 | + // valid case: experimental properties |
| 2096 | + DestinationService.Cache.reset(); |
| 2097 | + assertThat(sut.validateDestinationLookup("unknown-dest-1", OPTIONS_EXPER)).isEmpty(); |
| 2098 | + |
| 2099 | + // valid case: current tenant |
| 2100 | + DestinationService.Cache.reset(); |
| 2101 | + assertThat(sut.validateDestinationLookup("current-dest-1", OPTIONS_CURRT)).isEmpty(); |
| 2102 | + |
| 2103 | + // valid case: provider tenant |
| 2104 | + DestinationService.Cache.reset(); |
| 2105 | + assertThat(sut.validateDestinationLookup("provider-dest-1", OPTIONS_PROVT)).isEmpty(); |
| 2106 | + |
| 2107 | + // invalid case: current tenant |
| 2108 | + DestinationService.Cache.reset(); |
| 2109 | + assertThat(sut.validateDestinationLookup("unknown-dest-1", OPTIONS_PROVT)) |
| 2110 | + .allSatisfy( |
| 2111 | + e -> assertThat(e) |
| 2112 | + .hasMessage("Destination unknown-dest-1 was not found among the destinations for AlwaysProvider.")); |
| 2113 | + |
| 2114 | + // invalid case: provider tenant |
| 2115 | + DestinationService.Cache.reset(); |
| 2116 | + assertThat(sut.validateDestinationLookup("unknown-dest-1", OPTIONS_CURRT)) |
| 2117 | + .allSatisfy( |
| 2118 | + e -> assertThat(e) |
| 2119 | + .hasMessage("Destination unknown-dest-1 was not found among the destinations for CurrentTenant.")); |
| 2120 | + } |
2063 | 2121 | } |
0 commit comments