Skip to content

Commit

Permalink
Add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dulithsenanayake committed Jan 31, 2024
1 parent e84927a commit a31b2d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public class APIMIntegrationConstants {
public static final String API_RESPONSE_ELEMENT_NAME_APIS = "apis";
public static final String API_RESPONSE_ELEMENT_NAME_ID = "id";

public static final String API_NAME = "name";
public static final String API_CONTEXT = "context";
public static final String API_VERSION = "version";
public static final String ENDPOINT_TYPE = "endpoint_type";
public static final String SANDBOX_ENDPOINTS = "sandbox_endpoints";
public static final String PRODUCTION_ENDPOINTS = "production_endpoints";
public static final String ENDPOINT_CONFIG = "endpointConfig";
public static final String POLICIES = "policies";
public static final String OPERATIONS = "operations";
public static final String API_CONTEXT_MALFORMED_ERROR = "The API context is malformed";
public static final String API_PRODUCT_CONTEXT_MALFORMED_ERROR = "The API Product context is malformed";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,22 @@ public void testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext() thro
HttpResponse response = null;

ArrayList<String> policies = new ArrayList<String>();
policies.add("Unlimited");
policies.add(APIMIntegrationConstants.API_TIER.UNLIMITED);

JSONObject additionalPropertiesObj = new JSONObject();
additionalPropertiesObj.put("name", "GraphQLAPIWithInvalidContext");
additionalPropertiesObj.put("context", "invalidContext{version}");
additionalPropertiesObj.put("version", API_VERSION_1_0_0);
additionalPropertiesObj.put(APIMIntegrationConstants.API_NAME, "GraphQLAPIWithInvalidContext");
additionalPropertiesObj.put(APIMIntegrationConstants.API_CONTEXT, "invalidContext{version}");
additionalPropertiesObj.put(APIMIntegrationConstants.API_VERSION, API_VERSION_1_0_0);

JSONObject url = new JSONObject();
url.put("url", END_POINT_URL);
JSONObject endpointConfig = new JSONObject();
endpointConfig.put("endpoint_type", "http");
endpointConfig.put("sandbox_endpoints", url);
endpointConfig.put("production_endpoints", url);
additionalPropertiesObj.put("endpointConfig", endpointConfig);
additionalPropertiesObj.put("policies", policies);
additionalPropertiesObj.put("operations", operations);
endpointConfig.put(APIMIntegrationConstants.ENDPOINT_TYPE, "http");
endpointConfig.put(APIMIntegrationConstants.SANDBOX_ENDPOINTS, url);
endpointConfig.put(APIMIntegrationConstants.PRODUCTION_ENDPOINTS, url);
additionalPropertiesObj.put(APIMIntegrationConstants.ENDPOINT_CONFIG, endpointConfig);
additionalPropertiesObj.put(APIMIntegrationConstants.POLICIES, policies);
additionalPropertiesObj.put(APIMIntegrationConstants.OPERATIONS, operations);

// create Graphql API
response = restAPIPublisher.importGraphqlSchemaDefinitionWithInvalidContext(file, additionalPropertiesObj.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ public void testCreateAnAPIWithMalformedContextThroughThePublisherRest()
apiCreationRequestBean.setVersion(apiVersion);
apiCreationRequestBean.setDescription(apiDescription);
apiCreationRequestBean.setTags(apiTag);
apiCreationRequestBean.setTier("Gold");
apiCreationRequestBean.setTier(APIMIntegrationConstants.API_TIER.GOLD);

HttpResponse response = restAPIPublisher.addAPIWithMalformedContext(apiCreationRequestBean);
Assert.assertNotNull(response, "Response cannot be null");
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API");
Assert.assertEquals(response.getResponseCode(), Response.Status.BAD_REQUEST.getStatusCode(), "Response Code miss matched when creating the API");
}

@Test(groups = {"wso2.am"}, description = "Remove an API Through the Publisher Rest API",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.carbon.utils.xml.StringUtils;

import javax.ws.rs.core.Response;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -487,7 +488,7 @@ public void testCreateWebSocketAPIWithMalformedContext() throws Exception {
apiRequest.setApiTier(APIMIntegrationConstants.API_TIER.UNLIMITED);

HttpResponse response = restAPIPublisher.addAPIWithMalformedContext(apiRequest);
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API");
Assert.assertEquals(response.getResponseCode(), Response.Status.BAD_REQUEST.getStatusCode(), "Response Code miss matched when creating the API");
}

/**
Expand Down

0 comments on commit a31b2d2

Please sign in to comment.