Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integrations tests to check malformed API contexts #13234

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

dulithsenanayake
Copy link
Contributor

This PR adds integration tests to cover the following scenarios.

  • Create publisher rest API with malformed context.
  • Create graphql API using schema with malformed context.
  • Create API product with malformed context.
  • Create websocket API with malformed context.
  • WSDL import with malformed context.

@BLasan
Copy link
Contributor

BLasan commented Jul 11, 2023

Build is failed

BLasan
BLasan previously approved these changes Jul 11, 2023
@BLasan BLasan dismissed their stale review July 11, 2023 03:54

Tests are failing

@BLasan
Copy link
Contributor

BLasan commented Jul 11, 2023

2023-07-09T20:07:49.5566524Z [ERROR] Tests run: 1499, Failures: 11, Errors: 0, Skipped: 46, Time elapsed: 17,640.501 s <<< FAILURE! - in TestSuite
2023-07-09T20:07:49.5570125Z [ERROR] org.wso2.am.integration.tests.apiproduct.APIProductCreationTestCase.cleanUpArtifacts  Time elapsed: 0.772 s  <<< FAILURE!
2023-07-09T20:07:49.5571092Z org.wso2.am.integration.clients.publisher.api.ApiException: 
2023-07-09T20:07:49.5572269Z 	at org.wso2.am.integration.tests.apiproduct.APIProductCreationTestCase.cleanUpArtifacts(APIProductCreationTestCase.java:644)
2023-07-09T20:07:49.5573998Z 
2023-07-09T20:07:49.5575542Z [ERROR] org.wso2.am.integration.tests.apiproduct.APIProductCreationTestCase.cleanUpArtifacts  Time elapsed: 1.525 s  <<< FAILURE!
2023-07-09T20:07:49.5576898Z org.wso2.am.integration.clients.publisher.api.ApiException: Missing the required parameter 'apiId' when calling deleteAPI(Async)
2023-07-09T20:07:49.5577914Z 	at org.wso2.am.integration.tests.apiproduct.APIProductCreationTestCase.cleanUpArtifacts(APIProductCreationTestCase.java:644)
2023-07-09T20:07:49.5579323Z 
2023-07-09T20:07:49.5581025Z [ERROR] org.wso2.am.integration.tests.api.lifecycle.APISecurityTestCase.initialize  Time elapsed: 4.057 s  <<< FAILURE!
2023-07-09T20:07:49.5581807Z org.wso2.am.integration.clients.publisher.api.ApiException: 
2023-07-09T20:07:49.5582584Z 	at org.wso2.am.integration.tests.api.lifecycle.APISecurityTestCase.initialize(APISecurityTestCase.java:190)
2023-07-09T20:07:49.5583021Z 
2023-07-09T20:07:49.5585888Z [ERROR] org.wso2.am.integration.tests.api.lifecycle.APISecurityTestCase.cleanUpArtifacts  Time elapsed: 4.157 s  <<< FAILURE!
2023-07-09T20:07:49.5587196Z org.wso2.am.integration.clients.publisher.api.ApiException: Missing the required parameter 'apiId' when calling deleteAPI(Async)
2023-07-09T20:07:49.5587948Z 	at org.wso2.am.integration.tests.api.lifecycle.APISecurityTestCase.cleanUpArtifacts(APISecurityTestCase.java:1206)
2023-07-09T20:07:49.5589658Z 
2023-07-09T20:07:49.5591258Z [ERROR] org.wso2.am.integration.tests.other.WSDLImportTestCase.testWsdlDefinitionImportWithMalformedContext  Time elapsed: 0.113 s  <<< FAILURE!
2023-07-09T20:07:49.5592081Z java.lang.AssertionError: expected [400] but found [409]
2023-07-09T20:07:49.5593012Z 	at org.wso2.am.integration.tests.other.WSDLImportTestCase.testWsdlDefinitionImportWithMalformedContext(WSDLImportTestCase.java:292)
2023-07-09T20:07:49.5593464Z 
2023-07-09T20:07:49.5597023Z [ERROR] org.wso2.am.integration.tests.publisher.APIM18CreateAnAPIThroughThePublisherRestAPITestCase.testCreateAnAPIWithMalformedContextThroughThePublisherRest  Time elapsed: 0.231 s  <<< FAILURE!
2023-07-09T20:07:49.5598282Z java.lang.AssertionError: Response cannot be null expected object to not be null
2023-07-09T20:07:49.5599419Z 	at org.wso2.am.integration.tests.publisher.APIM18CreateAnAPIThroughThePublisherRestAPITestCase.testCreateAnAPIWithMalformedContextThroughThePublisherRest(APIM18CreateAnAPIThroughThePublisherRestAPITestCase.java:172)
2023-07-09T20:07:49.5601173Z 
2023-07-09T20:07:49.5603526Z [ERROR] org.wso2.am.integration.tests.graphql.GraphqlTestCase.testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext  Time elapsed: 0.447 s  <<< FAILURE!
2023-07-09T20:07:49.5604344Z java.lang.AssertionError: Response cannot be null expected object to not be null
2023-07-09T20:07:49.5605122Z 	at org.wso2.am.integration.tests.graphql.GraphqlTestCase.testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext(GraphqlTestCase.java:226)
2023-07-09T20:07:49.5606934Z 
2023-07-09T20:07:49.5609109Z [ERROR] org.wso2.am.integration.tests.graphql.GraphqlTestCase.testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext  Time elapsed: 0.242 s  <<< FAILURE!
2023-07-09T20:07:49.5609879Z java.lang.AssertionError: Response cannot be null expected object to not be null
2023-07-09T20:07:49.5610645Z 	at org.wso2.am.integration.tests.graphql.GraphqlTestCase.testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext(GraphqlTestCase.java:226)
2023-07-09T20:07:49.5612426Z 
2023-07-09T20:07:49.5615194Z [ERROR] org.wso2.am.integration.tests.websocket.WebSocketAPITestCase.testCreateWebSocketAPIWithMalformedContext  Time elapsed: 0.154 s  <<< FAILURE!
2023-07-09T20:07:49.5615809Z java.lang.NullPointerException
2023-07-09T20:07:49.5616478Z 	at org.wso2.am.integration.tests.websocket.WebSocketAPITestCase.testCreateWebSocketAPIWithMalformedContext(WebSocketAPITestCase.java:498)
2023-07-09T20:07:49.5618937Z 
2023-07-09T20:07:49.5691707Z [ERROR] org.wso2.am.integration.tests.websocket.WebSocketAPITestCase.testCreateWebSocketAPIWithMalformedContext  Time elapsed: 0.151 s  <<< FAILURE!
2023-07-09T20:07:49.5692599Z java.lang.NullPointerException
2023-07-09T20:07:49.5693331Z 	at org.wso2.am.integration.tests.websocket.WebSocketAPITestCase.testCreateWebSocketAPIWithMalformedContext(WebSocketAPITestCase.java:498)
2023-07-09T20:07:49.5696010Z 
2023-07-09T20:07:49.5701486Z [ERROR] org.wso2.am.integration.tests.other.MandatoryPropertiesTestWithRestart.testCreateAnAPIThroughThePublisherRestWithoutMandatoryProperties  Time elapsed: 8.476 s  <<< FAILURE!
2023-07-09T20:07:49.5702466Z java.lang.AssertionError: APIs cannot be updated without setting values to mandatory API properties.
2023-07-09T20:07:49.5703484Z 	at org.wso2.am.integration.tests.other.MandatoryPropertiesTestWithRestart.testCreateAnAPIThroughThePublisherRestWithoutMandatoryProperties(MandatoryPropertiesTestWithRestart.java:110)

HttpResponse response = null;

ArrayList<String> policies = new ArrayList<String>();
policies.add("Unlimited");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use APIMIntegrationConstants.API_TIER.UNLIMITED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2

JSONObject additionalPropertiesObj = new JSONObject();
additionalPropertiesObj.put("name", "GraphQLAPIWithInvalidContext");
additionalPropertiesObj.put("context", "invalidContext{version}");
additionalPropertiesObj.put("version", API_VERSION_1_0_0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the name, context, version words to constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2

endpointConfig.put("production_endpoints", url);
additionalPropertiesObj.put("endpointConfig", endpointConfig);
additionalPropertiesObj.put("policies", policies);
additionalPropertiesObj.put("operations", operations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can move the property names to constants, as there are multiple usages in the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2

apiCreationRequestBean.setVersion(apiVersion);
apiCreationRequestBean.setDescription(apiDescription);
apiCreationRequestBean.setTags(apiTag);
apiCreationRequestBean.setTier("Gold");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use APIMIntegrationConstants.API_TIER.GOLD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2


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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Response.Status.NOT_FOUND.getStatusCode() for 400

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2

apiRequest.setApiTier(APIMIntegrationConstants.API_TIER.UNLIMITED);

HttpResponse response = restAPIPublisher.addAPIWithMalformedContext(apiRequest);
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Response.Status.NOT_FOUND.getStatusCode() for 400

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed from a31b2d2

@npamudika npamudika merged commit 61b1e1d into wso2:master Jan 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants