Skip to content

Commit 962718f

Browse files
committed
Fix weighted round-robin test failure
1 parent 8c7c5cf commit 962718f

File tree

1 file changed

+38
-116
lines changed
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi

1 file changed

+38
-116
lines changed

all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/aiapi/AIAPITestCase.java

Lines changed: 38 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public void testUnsecuredAIApiInvocation() throws Exception {
336336
// Invoke API
337337
Map<String, String> requestHeaders = new HashMap<>();
338338
requestHeaders.put("ApiKey", apiKey);
339+
requestHeaders.put("Content-Type", "application/json");
339340
String invokeURL = getAPIInvocationURLHttp(unsecuredAPIContext, unsecuredAPIVersion) + mistralAPIResource;
340341
HttpResponse serviceResponse = HTTPSClientUtils.doPost(invokeURL, requestHeaders, mistralPayload);
341342

@@ -430,6 +431,7 @@ public void testSecuredAIApiInvocation() throws Exception {
430431
// Invoke API
431432
Map<String, String> requestHeaders = new HashMap<>();
432433
requestHeaders.put("ApiKey", apiKey);
434+
requestHeaders.put("Content-Type", "application/json");
433435
String invokeURL = getAPIInvocationURLHttp(mistralAPIContext, mistralAPIVersion) + mistralAPIResource;
434436
HttpResponse serviceResponse = HTTPSClientUtils.doPost(invokeURL, requestHeaders, mistralPayload);
435437

@@ -686,48 +688,45 @@ public void testGetAllEndpointsFinal() throws Exception {
686688
}
687689
Assert.assertFalse(foundSandboxEndpoint, "Sandbox endpoint should be completely removed from the final list");
688690
}
689-
//
690-
// /**
691-
// * Test retrieving AI service provider models from the publisher portal
692-
// */
693-
// @Test(groups = {"wso2.am"}, description = "Test retrieving AI service provider models",
694-
// dependsOnMethods = "testGetAllEndpointsFinal")
695-
// public void testGetAIServiceProviderModels() throws Exception {
696-
// // Retrieve model list
697-
// HttpResponse getModelListResponse = restAPIPublisher.getAIServiceProviderModels(aiServiceProviderId);
698-
// Assert.assertEquals(HttpStatus.SC_OK, getModelListResponse.getResponseCode(),
699-
// "Failed to retrieve model list of AI Service Provider: " + aiServiceProviderId);
700-
//
701-
// // Parse the model provider response to extract the models list
702-
// List<Map<String, Object>> modelProviderList = new Gson().fromJson(getModelListResponse.getData(), List.class);
703-
// List<String> modelList = new ArrayList<>();
704-
//
705-
// if (!modelProviderList.isEmpty()) {
706-
// Map<String, Object> firstProvider = modelProviderList.get(0);
707-
// if (firstProvider.containsKey("models")) {
708-
// List<String> models = (List<String>) firstProvider.get("models");
709-
// modelList.addAll(models);
710-
// }
711-
// }
712-
//
713-
// // Verify that the retrieved model list contains the expected 3 models
714-
// Assert.assertNotNull(modelList, "Model list should not be null");
715-
// Assert.assertEquals(modelList.size(), 3, "Expected 3 models but found: " + modelList.size());
716-
//
717-
// // Verify presence of specific models
718-
// Assert.assertTrue(modelList.contains(model1), "Model list should contain " + model1);
719-
// Assert.assertTrue(modelList.contains(model2), "Model list should contain " + model2);
720-
// Assert.assertTrue(modelList.contains(model3), "Model list should contain " + model3);
721-
//
722-
// // Log the retrieved models for debugging
723-
// log.info("Retrieved models from AI Service Provider: " + modelList.toString());
724-
// }
691+
692+
/**
693+
* Test retrieving AI service provider models from the publisher portal
694+
*/
695+
@Test(groups = {"wso2.am"}, description = "Test retrieving AI service provider models",
696+
dependsOnMethods = "testGetAllEndpointsFinal")
697+
public void testGetAIServiceProviderModels() throws Exception {
698+
// Retrieve model list
699+
HttpResponse getModelListResponse = restAPIPublisher.getAIServiceProviderModels(aiServiceProviderId);
700+
Assert.assertEquals(HttpStatus.SC_OK, getModelListResponse.getResponseCode(),
701+
"Failed to retrieve model list of AI Service Provider: " + aiServiceProviderId);
702+
703+
// Parse the model provider response to extract the models list
704+
List<Map<String, Object>> modelProviderList = new Gson().fromJson(getModelListResponse.getData(), List.class);
705+
List<String> modelList = new ArrayList<>();
706+
707+
if (!modelProviderList.isEmpty()) {
708+
Map<String, Object> firstProvider = modelProviderList.get(0);
709+
if (firstProvider.containsKey("models")) {
710+
List<String> models = (List<String>) firstProvider.get("models");
711+
modelList.addAll(models);
712+
}
713+
}
714+
715+
// Verify that the retrieved model list contains the expected 3 models
716+
Assert.assertNotNull(modelList, "Model list should not be null");
717+
Assert.assertEquals(modelList.size(), 3, "Expected 3 models but found: " + modelList.size());
718+
719+
// Verify presence of specific models
720+
Assert.assertTrue(modelList.contains(model1), "Model list should contain " + model1);
721+
Assert.assertTrue(modelList.contains(model2), "Model list should contain " + model2);
722+
Assert.assertTrue(modelList.contains(model3), "Model list should contain " + model3);
723+
}
725724

726725
/**
727726
* Test Mistral AI API invocation after adding model round-robin policy
728727
*/
729728
@Test(groups = {"wso2.am"}, description = "Test AI API invocation after adding model round-robin policy",
730-
dependsOnMethods = "testGetAllEndpointsFinal")
729+
dependsOnMethods = "testGetAIServiceProviderModels")
731730
public void testAIApiInvocationAfterAddingApiLevelModelRoundRobinPolicy() throws Exception {
732731

733732
HttpResponse getAPIResponse = restAPIPublisher.getAPI(mistralAPIId);
@@ -790,6 +789,7 @@ public void testAIApiInvocationAfterAddingApiLevelModelRoundRobinPolicy() throws
790789
// Invoke API
791790
Map<String, String> requestHeaders = new HashMap<>();
792791
requestHeaders.put("ApiKey", apiKey);
792+
requestHeaders.put("Content-Type", "application/json");
793793
String invokeURL = getAPIInvocationURLHttp(mistralAPIContext, mistralAPIVersion) + mistralAPIResource;
794794
HttpResponse serviceResponse = HTTPSClientUtils.doPost(invokeURL, requestHeaders, mistralPayload);
795795

@@ -917,14 +917,10 @@ public void testCreateNewVersionWithFailoverPolicy() throws Exception {
917917
waitForAPIDeploymentSync(newVersionApiDto.getProvider(), newVersionApiDto.getName(),
918918
newVersionApiDto.getVersion(), APIMIntegrationConstants.IS_API_EXISTS);
919919

920-
// Subscribe to the new version API
921-
// SubscriptionDTO subscriptionDTO = restAPIStore.subscribeToAPI(newVersionApiId, applicationId,
922-
// APIMIntegrationConstants.API_TIER.UNLIMITED);
923-
// Assert.assertNotNull(subscriptionDTO, "New version API subscription failed");
924-
925920
// Invoke the new version API to test failover
926921
Map<String, String> requestHeaders = new HashMap<>();
927922
requestHeaders.put("ApiKey", apiKey);
923+
requestHeaders.put("Content-Type", "application/json");
928924
String invokeURL = getAPIInvocationURLHttp(mistralAPIContext, newVersion) + mistralAPIResource;
929925
HttpResponse serviceResponse = HTTPSClientUtils.doPost(invokeURL, requestHeaders, mistralPayload);
930926

@@ -939,8 +935,6 @@ public void testCreateNewVersionWithFailoverPolicy() throws Exception {
939935
"Response should match fallback model (model3) after failover");
940936
}
941937

942-
// testCreateNewVersionAfterAddingModelRoundRobinPolicy
943-
944938
/**
945939
* Deletes a specified AI service provider after removing API subscriptions and applications.
946940
* Verifies that the provider is successfully deleted and no longer listed.
@@ -998,60 +992,10 @@ private void startWiremockServer() {
998992
.port(endpointPort)
999993
.extensions(new ResponseTemplateTransformer(true)));
1000994

1001-
// // Stub for secured AI API (with Authorization header value of Bearer 123)
1002-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint + mistralAPIResource))
1003-
// .withHeader("Authorization", WireMock.matching("Bearer 123"))
1004-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model1)))
1005-
// .willReturn(aResponse()
1006-
// .withStatus(200)
1007-
// .withHeader("Content-Type", "application/json")
1008-
// .withBody(mistralResponse)
1009-
// .withTransformers("response-template")));
1010-
//
1011-
// // Stub for secured AI API (with Authorization header value of Bearer 456)
1012-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint2 + mistralAPIResource))
1013-
// .withHeader("Authorization", WireMock.matching("Bearer 456"))
1014-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model1)))
1015-
// .willReturn(aResponse()
1016-
// .withStatus(200)
1017-
// .withHeader("Content-Type", "application/json")
1018-
// .withBody(mistralResponse)
1019-
// .withTransformers("response-template")));
1020-
//
1021-
// // More specific matching for model2 with additional JSON path validation
1022-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint2 + mistralAPIResource))
1023-
// .withHeader("Authorization", WireMock.matching("Bearer 456"))
1024-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model2)))
1025-
// .willReturn(aResponse()
1026-
// .withStatus(200)
1027-
// .withHeader("Content-Type", "application/json")
1028-
// .withBody(mistralResponse)
1029-
// .withTransformers("response-template")));
1030-
//
1031-
// // Stub for model3 (mistral-large-latest) with Bearer 123
1032-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint + mistralAPIResource))
1033-
// .withHeader("Authorization", WireMock.matching("Bearer 123"))
1034-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model3)))
1035-
// .willReturn(aResponse()
1036-
// .withStatus(200)
1037-
// .withHeader("Content-Type", "application/json")
1038-
// .withBody(mistralResponse)
1039-
// .withTransformers("response-template")));
1040-
//
1041-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint2 + mistralAPIResource))
1042-
// .withHeader("Authorization", WireMock.matching("Bearer 456"))
1043-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model3)))
1044-
// .willReturn(aResponse()
1045-
// .withStatus(200)
1046-
// .withHeader("Content-Type", "application/json")
1047-
// .withBody(mistralResponse)
1048-
// .withTransformers("response-template")));
1049-
//
1050995
// Stub for secured AI API (with Authorization header value of Bearer 123)
1051996
wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint + mistralAPIResource))
1052997
.withHeader("Authorization", WireMock.matching("Bearer 123"))
1053998
.withRequestBody(matchingJsonPath("$.model", equalTo(model1)))
1054-
// .withRequestBody(equalTo(model1))
1055999
.willReturn(aResponse()
10561000
.withStatus(200)
10571001
.withHeader("Content-Type", "application/json")
@@ -1076,28 +1020,6 @@ private void startWiremockServer() {
10761020
.withHeader("Content-Type", "application/json")
10771021
.withBody(model3Response)));
10781022

1079-
// Stub for model3 (mistral-large-latest)
1080-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint2 + mistralAPIResource))
1081-
// .withHeader("Authorization", WireMock.matching("Bearer 456"))
1082-
// .withRequestBody(matchingJsonPath("$.model", equalTo(model3)))
1083-
// .willReturn(aResponse()
1084-
// .withStatus(200)
1085-
// .withHeader("Content-Type", "application/json")
1086-
// .withBody(model3Response)));
1087-
1088-
// // Generic stub for model round-robin policy, matching either model2 or model3
1089-
// wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint2 + mistralAPIResource))
1090-
// .withHeader("Authorization", WireMock.matching("Bearer 456"))
1091-
// .withRequestBody(WireMock.or(
1092-
// equalTo(model2), // Match the plain string "mistral-medium-latest"
1093-
// equalTo(model3) // Match the plain string "mistral-large-latest"
1094-
// ))
1095-
// .willReturn(aResponse()
1096-
// .withStatus(200)
1097-
// .withHeader("Content-Type", "application/json")
1098-
// .withBody(mistralResponse) // Use the template response
1099-
// .withTransformers("response-template")));
1100-
11011023
// Stub for /mistral endpoint with Bearer 123 and model3
11021024
// Using flexible matching to handle JSON formatting issues
11031025
wireMockServer.stubFor(WireMock.post(urlEqualTo(mistralAPIEndpoint + mistralAPIResource))

0 commit comments

Comments
 (0)