Skip to content

Commit

Permalink
Add integration test for preventing on prem API Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
tharikaGitHub committed Oct 8, 2021
1 parent 135a37d commit 6597476
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public org.json.simple.JSONObject getEndpointConfig() {
return endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
public class APIM520UpdateAnAPIThroughThePublisherRestAPITestCase extends APIMIntegrationBaseTest {

private final String apiNameTest = "APIM520PublisherTest";
private final String apiUpdatedNameTest = "PublisherTestRenameAPI";
private final String updatedApiName = "PublisherNewTestRenameAPI";
private final String apiVersion = "1.0.0";
private APIPublisherRestClient apiPublisher;
private String apiProviderName;
Expand Down Expand Up @@ -138,6 +140,46 @@ public void testUpdateAnAPIThroughThePublisherRest() throws Exception {

}

@Test(groups = {"wso2.am"}, description = "Update an API Through the Publisher Rest API after renaming the API")
public void testUpdateAnAPIThroughThePublisherRestAfterRename() throws Exception {

String apiContextTest = "apiRenamingContext";
String apiDescription = "This is Test API Created by API Manager Integration Test for API Renaming";

//Create an API
APIRequest apiCreationRequestBean = new APIRequest(apiUpdatedNameTest, apiContextTest,
new URL(apiProductionEndPointUrl));
apiCreationRequestBean.setVersion(apiVersion);
apiCreationRequestBean.setProvider(apiProviderName);
apiCreationRequestBean.setDescription(apiDescription);
apiCreationRequestBean.setTiersCollection("Gold,Bronze");

HttpResponse apiCreationResponse = restAPIPublisher.addAPI(apiCreationRequestBean);
id = apiCreationResponse.getData();
assertEquals(apiCreationResponse.getResponseCode(), Response.Status.CREATED.getStatusCode(),
"Response Code miss matched when creating the API");

//Check availability of the API in publisher
HttpResponse apiResponsePublisher = restAPIPublisher.getAPI(id);
assertTrue(apiResponsePublisher.getData().contains(apiUpdatedNameTest),
apiUpdatedNameTest + " is not visible in publisher");

//Update API with name change
apiCreationRequestBean.setName(updatedApiName);

HttpResponse apiUpdateResponse = restAPIPublisher.updateAPI(apiCreationRequestBean, id);
assertEquals(apiUpdateResponse.getResponseCode(), Response.Status.OK.getStatusCode(),
"Response Code miss matched when creating the API");
waitForAPIDeployment();

// Check whether API is updated from the above request. This API Name should not get updated
// when not in a cloud scenario
HttpResponse apiUpdateResponsePublisher = restAPIPublisher.getAPI(id);

assertTrue(apiUpdateResponsePublisher.getData().contains(apiUpdatedNameTest),
apiUpdatedNameTest + " is updated");
}

@AfterClass(alwaysRun = true)
public void destroyAPIs() throws Exception {
restAPIPublisher.deleteAPI(id);
Expand Down

0 comments on commit 6597476

Please sign in to comment.