Skip to content

Commit 6597476

Browse files
committed
Add integration test for preventing on prem API Renaming
1 parent 135a37d commit 6597476

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/APIRequest.java

+4
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ public String getName() {
435435
return name;
436436
}
437437

438+
public void setName(String name) {
439+
this.name = name;
440+
}
441+
438442
public org.json.simple.JSONObject getEndpointConfig() {
439443
return endpoint;
440444
}

modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/publisher/APIM520UpdateAnAPIThroughThePublisherRestAPITestCase.java

+42
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
public class APIM520UpdateAnAPIThroughThePublisherRestAPITestCase extends APIMIntegrationBaseTest {
4848

4949
private final String apiNameTest = "APIM520PublisherTest";
50+
private final String apiUpdatedNameTest = "PublisherTestRenameAPI";
51+
private final String updatedApiName = "PublisherNewTestRenameAPI";
5052
private final String apiVersion = "1.0.0";
5153
private APIPublisherRestClient apiPublisher;
5254
private String apiProviderName;
@@ -138,6 +140,46 @@ public void testUpdateAnAPIThroughThePublisherRest() throws Exception {
138140

139141
}
140142

143+
@Test(groups = {"wso2.am"}, description = "Update an API Through the Publisher Rest API after renaming the API")
144+
public void testUpdateAnAPIThroughThePublisherRestAfterRename() throws Exception {
145+
146+
String apiContextTest = "apiRenamingContext";
147+
String apiDescription = "This is Test API Created by API Manager Integration Test for API Renaming";
148+
149+
//Create an API
150+
APIRequest apiCreationRequestBean = new APIRequest(apiUpdatedNameTest, apiContextTest,
151+
new URL(apiProductionEndPointUrl));
152+
apiCreationRequestBean.setVersion(apiVersion);
153+
apiCreationRequestBean.setProvider(apiProviderName);
154+
apiCreationRequestBean.setDescription(apiDescription);
155+
apiCreationRequestBean.setTiersCollection("Gold,Bronze");
156+
157+
HttpResponse apiCreationResponse = restAPIPublisher.addAPI(apiCreationRequestBean);
158+
id = apiCreationResponse.getData();
159+
assertEquals(apiCreationResponse.getResponseCode(), Response.Status.CREATED.getStatusCode(),
160+
"Response Code miss matched when creating the API");
161+
162+
//Check availability of the API in publisher
163+
HttpResponse apiResponsePublisher = restAPIPublisher.getAPI(id);
164+
assertTrue(apiResponsePublisher.getData().contains(apiUpdatedNameTest),
165+
apiUpdatedNameTest + " is not visible in publisher");
166+
167+
//Update API with name change
168+
apiCreationRequestBean.setName(updatedApiName);
169+
170+
HttpResponse apiUpdateResponse = restAPIPublisher.updateAPI(apiCreationRequestBean, id);
171+
assertEquals(apiUpdateResponse.getResponseCode(), Response.Status.OK.getStatusCode(),
172+
"Response Code miss matched when creating the API");
173+
waitForAPIDeployment();
174+
175+
// Check whether API is updated from the above request. This API Name should not get updated
176+
// when not in a cloud scenario
177+
HttpResponse apiUpdateResponsePublisher = restAPIPublisher.getAPI(id);
178+
179+
assertTrue(apiUpdateResponsePublisher.getData().contains(apiUpdatedNameTest),
180+
apiUpdatedNameTest + " is updated");
181+
}
182+
141183
@AfterClass(alwaysRun = true)
142184
public void destroyAPIs() throws Exception {
143185
restAPIPublisher.deleteAPI(id);

0 commit comments

Comments
 (0)