@@ -336,6 +336,7 @@ public void testUnsecuredAIApiInvocation() throws Exception {
336
336
// Invoke API
337
337
Map <String , String > requestHeaders = new HashMap <>();
338
338
requestHeaders .put ("ApiKey" , apiKey );
339
+ requestHeaders .put ("Content-Type" , "application/json" );
339
340
String invokeURL = getAPIInvocationURLHttp (unsecuredAPIContext , unsecuredAPIVersion ) + mistralAPIResource ;
340
341
HttpResponse serviceResponse = HTTPSClientUtils .doPost (invokeURL , requestHeaders , mistralPayload );
341
342
@@ -430,6 +431,7 @@ public void testSecuredAIApiInvocation() throws Exception {
430
431
// Invoke API
431
432
Map <String , String > requestHeaders = new HashMap <>();
432
433
requestHeaders .put ("ApiKey" , apiKey );
434
+ requestHeaders .put ("Content-Type" , "application/json" );
433
435
String invokeURL = getAPIInvocationURLHttp (mistralAPIContext , mistralAPIVersion ) + mistralAPIResource ;
434
436
HttpResponse serviceResponse = HTTPSClientUtils .doPost (invokeURL , requestHeaders , mistralPayload );
435
437
@@ -686,48 +688,45 @@ public void testGetAllEndpointsFinal() throws Exception {
686
688
}
687
689
Assert .assertFalse (foundSandboxEndpoint , "Sandbox endpoint should be completely removed from the final list" );
688
690
}
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
+ }
725
724
726
725
/**
727
726
* Test Mistral AI API invocation after adding model round-robin policy
728
727
*/
729
728
@ Test (groups = {"wso2.am" }, description = "Test AI API invocation after adding model round-robin policy" ,
730
- dependsOnMethods = "testGetAllEndpointsFinal " )
729
+ dependsOnMethods = "testGetAIServiceProviderModels " )
731
730
public void testAIApiInvocationAfterAddingApiLevelModelRoundRobinPolicy () throws Exception {
732
731
733
732
HttpResponse getAPIResponse = restAPIPublisher .getAPI (mistralAPIId );
@@ -790,6 +789,7 @@ public void testAIApiInvocationAfterAddingApiLevelModelRoundRobinPolicy() throws
790
789
// Invoke API
791
790
Map <String , String > requestHeaders = new HashMap <>();
792
791
requestHeaders .put ("ApiKey" , apiKey );
792
+ requestHeaders .put ("Content-Type" , "application/json" );
793
793
String invokeURL = getAPIInvocationURLHttp (mistralAPIContext , mistralAPIVersion ) + mistralAPIResource ;
794
794
HttpResponse serviceResponse = HTTPSClientUtils .doPost (invokeURL , requestHeaders , mistralPayload );
795
795
@@ -917,14 +917,10 @@ public void testCreateNewVersionWithFailoverPolicy() throws Exception {
917
917
waitForAPIDeploymentSync (newVersionApiDto .getProvider (), newVersionApiDto .getName (),
918
918
newVersionApiDto .getVersion (), APIMIntegrationConstants .IS_API_EXISTS );
919
919
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
-
925
920
// Invoke the new version API to test failover
926
921
Map <String , String > requestHeaders = new HashMap <>();
927
922
requestHeaders .put ("ApiKey" , apiKey );
923
+ requestHeaders .put ("Content-Type" , "application/json" );
928
924
String invokeURL = getAPIInvocationURLHttp (mistralAPIContext , newVersion ) + mistralAPIResource ;
929
925
HttpResponse serviceResponse = HTTPSClientUtils .doPost (invokeURL , requestHeaders , mistralPayload );
930
926
@@ -939,8 +935,6 @@ public void testCreateNewVersionWithFailoverPolicy() throws Exception {
939
935
"Response should match fallback model (model3) after failover" );
940
936
}
941
937
942
- // testCreateNewVersionAfterAddingModelRoundRobinPolicy
943
-
944
938
/**
945
939
* Deletes a specified AI service provider after removing API subscriptions and applications.
946
940
* Verifies that the provider is successfully deleted and no longer listed.
@@ -998,60 +992,10 @@ private void startWiremockServer() {
998
992
.port (endpointPort )
999
993
.extensions (new ResponseTemplateTransformer (true )));
1000
994
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
- //
1050
995
// Stub for secured AI API (with Authorization header value of Bearer 123)
1051
996
wireMockServer .stubFor (WireMock .post (urlEqualTo (mistralAPIEndpoint + mistralAPIResource ))
1052
997
.withHeader ("Authorization" , WireMock .matching ("Bearer 123" ))
1053
998
.withRequestBody (matchingJsonPath ("$.model" , equalTo (model1 )))
1054
- // .withRequestBody(equalTo(model1))
1055
999
.willReturn (aResponse ()
1056
1000
.withStatus (200 )
1057
1001
.withHeader ("Content-Type" , "application/json" )
@@ -1076,28 +1020,6 @@ private void startWiremockServer() {
1076
1020
.withHeader ("Content-Type" , "application/json" )
1077
1021
.withBody (model3Response )));
1078
1022
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
-
1101
1023
// Stub for /mistral endpoint with Bearer 123 and model3
1102
1024
// Using flexible matching to handle JSON formatting issues
1103
1025
wireMockServer .stubFor (WireMock .post (urlEqualTo (mistralAPIEndpoint + mistralAPIResource ))
0 commit comments