Skip to content

Commit b444fec

Browse files
committed
Add low-level test method
1 parent 11d0c66 commit b444fec

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceTest.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationRetrievalStrategy.withUserToken;
44
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationRetrievalStrategy.withoutToken;
5+
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.CrossLevelScope.PROVIDER_SUBACCOUNT;
56
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.DESTINATION_RETRIEVAL_STRATEGY_KEY;
67
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.DESTINATION_TOKEN_EXCHANGE_STRATEGY_KEY;
78
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.augmenter;
@@ -51,6 +52,8 @@
5152
import java.util.function.Function;
5253
import java.util.stream.Stream;
5354

55+
import io.vavr.control.Option;
56+
import lombok.val;
5457
import org.apache.http.HttpVersion;
5558
import org.apache.http.client.HttpClient;
5659
import org.apache.http.message.BasicHttpResponse;
@@ -2006,7 +2009,7 @@ void testPrependGetAllDestinationsCallUsesCorrectRetrievalStrategy()
20062009
}
20072010

20082011
@ParameterizedTest
2009-
@MethodSource("testCasesUncachedDestinationLookup")
2012+
@MethodSource( "testCasesUncachedDestinationLookup" )
20102013
void testPrependGetAllDestinationsCallSkipped( final DestinationOptions options, final String expectedPath )
20112014
{
20122015
// Reset Cache to re-enable the PreLookupCheck
@@ -2060,4 +2063,59 @@ private static Stream<Arguments> testCasesUncachedDestinationLookup()
20602063
Arguments.of(optionsWithSubaccount, "/v2/destinations/" + destinationName + "@subaccount"),
20612064
Arguments.of(optionsWithFragment, "/v1/destinations/" + destinationName));
20622065
}
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+
}
20632121
}

0 commit comments

Comments
 (0)