Skip to content

Commit

Permalink
Unit tests for revision deployment new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GihanAyesh committed Oct 24, 2023
1 parent 154911f commit fc7885b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO;
import org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO;
import org.wso2.carbon.apimgt.impl.dto.TierPermissionDTO;
import org.wso2.carbon.apimgt.impl.dto.WorkflowDTO;
import org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder;
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
import org.wso2.carbon.apimgt.impl.notifier.Notifier;
Expand Down Expand Up @@ -1742,6 +1743,62 @@ public void testAddAPISpecificPolicyToAPI() throws Exception {
Assert.assertNull("API specific policy should delete with the API delete", policyDataAfterDelete);
}

/**
* Test for retrieveAllWorkflowFromInternalReference method
* Checks whether all the API revision deployment mapping details are retrieved correctly
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
@Test public void testRetrieveAllWorkflowFromInternalReference() throws Exception {
WorkflowStatus workflowStatus = WorkflowStatus.CREATED;
String revisionUUID = "821b9664-eeca-4173-9f56-3dc6d46bd6eb";
String wfType = "AM_REVISION_DEPLOYMENT";
List<WorkflowDTO> workflowList = apiMgtDAO.retrieveAllWorkflowFromInternalReference(
revisionUUID, wfType);
Assert.assertNotNull(workflowList);
WorkflowDTO workFlow = workflowList.get(0);
Assert.assertNotNull(workFlow);
Assert.assertEquals(workFlow.getWorkflowReference(), revisionUUID);
Assert.assertEquals(workFlow.getWorkflowType(), wfType);
Assert.assertEquals(workFlow.getStatus(),workflowStatus);
}

/**
* Test for getAPIRevisionDeploymentsByWorkflowStatusAndApiUUID method
* Checks whether the API revision deployment mapping details are retrieved correctly
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
@Test public void testGetAPIRevisionDeploymentsByWorkflowStatusAndApiUUID() throws Exception {
String workflowStatus = "CREATED";
String apiUUID = "7af95c9d-6177-4191-ab3e-d3f6c1cdc4c2";
String revisionUUID = "821b9664-eeca-4173-9f56-3dc6d46bd6eb";
String deployment = "default";
List<APIRevisionDeployment> apiRevisionDeployments = apiMgtDAO.getAPIRevisionDeploymentsByWorkflowStatusAndApiUUID(
apiUUID, workflowStatus);
Assert.assertNotNull(apiRevisionDeployments);
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeployments.get(0);
Assert.assertNotNull(apiRevisionDeployment);
Assert.assertEquals(apiRevisionDeployment.getDeployment(), deployment);
Assert.assertEquals(apiRevisionDeployment.getRevisionUUID(), revisionUUID);
}

/**
* Test for updateAPIRevisionDeploymentStatus method
* Checks whether the API revision deployment status is updated correctly
* @throws APIManagementException if an error occurs while updating revision deployment status
*/
@Test public void testUpdateAPIRevisionDeploymentStatus() throws Exception {
String workflowStatus = "APPROVED";
String revisionUUID = "821b9664-eeca-4173-9f56-3dc6d46bd6eb";
String apiId = "7af95c9d-6177-4191-ab3e-d3f6c1cdc4c2";
String deployment = "default";
apiMgtDAO.updateAPIRevisionDeploymentStatus(revisionUUID, workflowStatus, deployment);
List<APIRevisionDeployment> apiRevisionDeployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(apiId);
Assert.assertNotNull(apiRevisionDeployments);
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeployments.get(0);
Assert.assertNotNull(apiRevisionDeployment);
Assert.assertEquals(org.wso2.carbon.apimgt.api.WorkflowStatus.APPROVED,apiRevisionDeployment.getStatus());
}

private OperationPolicyData getOperationPolicyDataObject(String org, String apiUUID, String policyName) throws APIManagementException {
String jsonSpec = getPolicyJson(policyName);
String jsonDef = getPolicyDef(policyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ INSERT INTO AM_CERTIFICATE_METADATA VALUES (1001, 'ALIAS_2','EP_2',RAWTOHEX('abc
INSERT INTO AM_CERTIFICATE_METADATA VALUES (1002, 'ALIAS_3','EP_3',RAWTOHEX('abcdefghtij'));
INSERT INTO AM_CERTIFICATE_METADATA VALUES (1002, 'ALIAS_4','EP_4',RAWTOHEX('abcdefghtij'));

INSERT INTO AM_WORKFLOWS VALUES (1, '821b9664-eeca-4173-9f56-3dc6d46bd6eb', 'AM_REVISION_DEPLOYMENT', 'CREATED', '2017-01-01 00:00:00', '2017-01-01 00:00:00', 'sampleDescription', 1, 'sampleDomain', '821b9664-eeca-4173-9f56-3dc6d46bd6e5', null, null);

INSERT INTO AM_REVISION VALUES (5,'7af95c9d-6177-4191-ab3e-d3f6c1cdc4c2', '821b9664-eeca-4173-9f56-3dc6d46bd6eb', 'sampleDescription','2017-01-01 00:00:00', 'admin');
INSERT INTO AM_REVISION VALUES (5,'696430b1-c554-4d82-8ea9-ea1a61db0a60', '821b9664-eeca-4173-9f56-3dc6d46bd6e3', 'sampleDescription','2017-01-01 00:00:00', 'admin');

INSERT INTO AM_DEPLOYMENT_REVISION_MAPPING VALUES ('default','testVhost', '821b9664-eeca-4173-9f56-3dc6d46bd6eb', 'CREATED', TRUE, '2017-01-01 00:00:00');
INSERT INTO AM_DEPLOYMENT_REVISION_MAPPING VALUES ('default','testVhost', '821b9664-eeca-4173-9f56-3dc6d46bd6e3', 'APPROVED', TRUE, '2017-01-01 00:00:00');

INSERT INTO AM_POLICY_SUBSCRIPTION (NAME, DISPLAY_NAME, TENANT_ID, QUOTA_TYPE, QUOTA, UNIT_TIME, TIME_UNIT,BILLING_PLAN) VALUES ('Gold', 'Gold', -1234, 'requestCount', 2, 1, 'min', 'Free');

SELECT * FROM AM_SUBSCRIBER;
Expand Down

0 comments on commit fc7885b

Please sign in to comment.