Skip to content

Commit

Permalink
Merge pull request #2353 from anuruddhal/2.x
Browse files Browse the repository at this point in the history
Fix Intermittent test cases
  • Loading branch information
anuruddhal authored Jan 11, 2018
2 parents 29cbad8 + ce5d8b5 commit 8b0003a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.am.integration.test.utils.APIManagerIntegrationTestException;
import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants;
Expand All @@ -33,7 +32,6 @@

import javax.xml.bind.DatatypeConverter;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.rmi.RemoteException;
Expand Down Expand Up @@ -128,39 +126,43 @@ public void testInvokeGETResourceWithSecuredEndPointPasswordOnlyNumbersAndLetter
@Test(groups = {"wso2.am"}, dataProvider = "SymbolCharacters", description = "Test the API with endpoint security" +
" enabled with complex password",
dependsOnMethods = "testInvokeGETResourceWithSecuredEndPointPasswordOnlyNumbersAndLetters")
public void testInvokeGETResourceWithSecuredEndPointComplexPassword(String symbolicCharacter)
public void testInvokeGETResourceWithSecuredEndPointComplexPassword()
throws Exception {

String endpointUsername = "user";
char[] endpointPassword = {'a', 'b', 'c', 'd', symbolicCharacter.charAt(0), 'e', 'f', 'g', 'h', 'i', 'j', 'k'};
byte[] userNamePasswordByteArray = (endpointUsername + ":" + String.valueOf(endpointPassword)).getBytes();
String encodedUserNamePassword = DatatypeConverter.printBase64Binary(userNamePasswordByteArray);
APICreationRequestBean apiCreationRequestBean =
new APICreationRequestBean(API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName, new URL(apiEndPointUrl));
apiCreationRequestBean.setTags(API_TAGS);
apiCreationRequestBean.setDescription(API_DESCRIPTION);
apiCreationRequestBean.setVisibility("public");
apiCreationRequestBean.setEndpointType("secured");
apiCreationRequestBean.setEpUsername(endpointUsername);
apiCreationRequestBean.setEpPassword(URLEncoder.encode(String.valueOf(endpointPassword), "UTF-8"));
//Update API with Edited information
HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiCreationRequestBean);
assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Update APi with new Resource " +
"information fail");
assertEquals(updateAPIHTTPResponse.getData(), "{\"error\" : false}", "Update APi with new Resource information fail");
//Send GET request

waitForAPIDeployment();

HttpResponse httpResponseGet =
HttpRequestUtil.doGet(getAPIInvocationURLHttp(API_CONTEXT, API_VERSION_1_0_0) + "/sec",
requestHeadersGet);
assertEquals(httpResponseGet.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Invocation fails for GET request for " +
"endpoint type secured. username:" + endpointUsername + " password:" + String.valueOf(endpointPassword));
assertTrue(httpResponseGet.getData().contains(encodedUserNamePassword), "Response Data not match for GET" +
" request for endpoint type secured. Expected value : " + encodedUserNamePassword + " not contains in " +
"response data: " + httpResponseGet.getData() + " username:" + endpointUsername + " password:" +
String.valueOf(endpointPassword));
char[] symbolicCharacter = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=', '{', '[',
'}', ']', '|', '\\', ':', ';', '"', '\'', '<', ',', '>', '.', '?', '/'};
for (int i = 0; i < symbolicCharacter.length; i++) {
String endpointUsername = "user";
char[] endpointPassword = {'a', 'b', 'c', 'd', symbolicCharacter[i], 'e', 'f', 'g', 'h', 'i', 'j', 'k'};
byte[] userNamePasswordByteArray = (endpointUsername + ":" + String.valueOf(endpointPassword)).getBytes();
String encodedUserNamePassword = DatatypeConverter.printBase64Binary(userNamePasswordByteArray);
APICreationRequestBean apiCreationRequestBean =
new APICreationRequestBean(API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName, new URL(apiEndPointUrl));
apiCreationRequestBean.setTags(API_TAGS);
apiCreationRequestBean.setDescription(API_DESCRIPTION);
apiCreationRequestBean.setVisibility("public");
apiCreationRequestBean.setEndpointType("secured");
apiCreationRequestBean.setEpUsername(endpointUsername);
apiCreationRequestBean.setEpPassword(URLEncoder.encode(String.valueOf(endpointPassword), "UTF-8"));
//Update API with Edited information
HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiCreationRequestBean);
assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Update APi with new Resource " +
"information fail");
assertEquals(updateAPIHTTPResponse.getData(), "{\"error\" : false}", "Update APi with new Resource information fail");
//Send GET request

waitForAPIDeployment();

HttpResponse httpResponseGet =
HttpRequestUtil.doGet(getAPIInvocationURLHttp(API_CONTEXT, API_VERSION_1_0_0) + "/sec",
requestHeadersGet);
assertEquals(httpResponseGet.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Invocation fails for GET request for " +
"endpoint type secured. username:" + endpointUsername + " password:" + String.valueOf(endpointPassword));
assertTrue(httpResponseGet.getData().contains(encodedUserNamePassword), "Response Data not match for GET" +
" request for endpoint type secured. Expected value : " + encodedUserNamePassword + " not contains in " +
"response data: " + httpResponseGet.getData() + " username:" + endpointUsername + " password:" +
String.valueOf(endpointPassword));
}
}

@AfterClass(alwaysRun = true)
Expand All @@ -170,13 +172,4 @@ public void cleanUpArtifacts() throws Exception {
super.cleanUp();
}


@DataProvider(name = "SymbolCharacters")
public static Object[][] getSymbolCharacters() {
return new Object[][]{
{"!"}, {"@"}, {"#"}, {"$"}, {"%"}, {"^"}, {"&"}, {"*"}, {"("}, {")"}, {"_"}, {"-"}, {"+"}, {"="},
{"{"}, {"["}, {"}"}, {"]"}, {"|"}, {"\\"}, {":"}, {";"}, {"\""}, {"'"}, {"<"}, {","}, {">"}, {"."},
{"?"}, {"/"}};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
import org.wso2.carbon.automation.engine.annotations.SetEnvironment;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;

import javax.activation.DataHandler;
import javax.ws.rs.core.Response;
import java.io.File;
import java.net.URL;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
Expand Down Expand Up @@ -103,12 +101,19 @@ public void throttlingTestCase() throws Exception {

String gatewayUrl = getAPIInvocationURLHttp("stockquote/test/");

HttpResponse response = HttpRequestUtil.sendGetRequest(gatewayUrl, null);
assertEquals(response.getResponseCode(), Response.Status.OK.getStatusCode(), "Response code mismatch " +
"did not receive 200");
int responseCode = HttpRequestUtil.sendGetRequest(gatewayUrl, null).getResponseCode();
assertTrue(validateStatusCode(responseCode), "Response code mismatch. Received "+responseCode);

}

private boolean validateStatusCode(int responseCode) {
if (responseCode == Response.Status.OK.getStatusCode() || responseCode == Response.Status.ACCEPTED
.getStatusCode()) {
return true;
}
return false;
}

@AfterClass(alwaysRun = true)
public void destroy() throws Exception {
super.cleanUp();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@
<carbon.analytics.common.version>5.1.7</carbon.analytics.common.version>

<!-- APIM Component Version -->
<carbon.apimgt.version>6.2.47</carbon.apimgt.version>
<carbon.apimgt.version>6.2.48</carbon.apimgt.version>
<carbon.apimgt.imp.pkg.version>[6.2.0, 7.0.0)</carbon.apimgt.imp.pkg.version>

<!-- Carbon Registry -->
Expand Down

0 comments on commit 8b0003a

Please sign in to comment.