Skip to content

Commit 78b66ca

Browse files
committed
improve tests
1 parent d453d78 commit 78b66ca

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

core/src/main/java/com/sap/ai/sdk/core/AiCoreServiceKeyAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static ServiceBinding createServiceBinding(@Nonnull final String serviceKey)
8181
new AiCoreCredentialsInvalidException("Missing clientid in service key"));
8282
}
8383

84-
if (credentials.get("clientsecret") != null && credentials.get("credentials-type") == null) {
84+
if (credentials.get("clientsecret") != null && credentials.get("credential-type") == null) {
8585
// add missing "credential-type: binding-secret"
8686
credentials.put("credential-type", "binding-secret");
8787
}

core/src/test/java/com/sap/ai/sdk/core/AiCoreServiceKeyAccessorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,32 @@ void testMalformedDotenv() {
5555
assertThatThrownBy(accessor::getServiceBindings)
5656
.isInstanceOf(ServiceBindingAccessException.class);
5757
}
58+
59+
@Test
60+
void testServiceBindingCreation() {
61+
var serviceKeyWithoutCredentialType =
62+
"""
63+
{
64+
"clientid": "",
65+
"clientsecret": ""
66+
}
67+
""";
68+
var binding1 = AiCoreServiceKeyAccessor.createServiceBinding(serviceKeyWithoutCredentialType);
69+
assertThat(binding1.getCredentials().containsKey("credential-type"))
70+
.describedAs("The missing 'credential-type' should have automatically been added")
71+
.isTrue();
72+
var serviceKeyWithCredentialType =
73+
"""
74+
{
75+
"clientid": "",
76+
"clientsecret": "",
77+
"credential-type": "foo"
78+
}
79+
}
80+
""";
81+
var binding2 = AiCoreServiceKeyAccessor.createServiceBinding(serviceKeyWithCredentialType);
82+
assertThat(binding2.getCredentials().get("credential-type"))
83+
.describedAs("The 'credential-type' field should not get overwritten")
84+
.isEqualTo("foo");
85+
}
5886
}

core/src/test/java/com/sap/ai/sdk/core/DestinationResolverTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ void testGetDestinationFromBinding() {
3030
var binding = AiCoreServiceKeyAccessor.createServiceBinding(serviceKey);
3131
var resolver = new DestinationResolver(() -> List.of(binding));
3232
var result = resolver.getDestination();
33-
assertThat(binding.getCredentials().containsKey("credential-type"))
34-
.describedAs("The missing 'credential-type' should have automatically been added")
35-
.isTrue();
3633
assertThat(result.getUri())
3734
.describedAs("The destination should already contain the /v2 base path")
3835
.hasToString("https://api.ai.core/v2/");

0 commit comments

Comments
 (0)