Adding more fixes to the testcases.

revert-70aa11f8
sinthuja 7 years ago
parent fd123af887
commit 3f7f68c9c3

@ -22,14 +22,21 @@ import org.testng.Assert;
import java.io.File;
import java.net.URL;
/**
* Utils class which provides utility methods for other testcases.
*/
public class TestUtils {
static final String IOT_CORE_HOST = "iot.core.wso2.com";
static final String IOT_CORE_HTTPS_PORT = "9443";
static final String IOT_KEYMANAGER_HOST = "iot.keymanager.wso2.com";
static final String IOT_KEYMANAGER_PORT = "9443";
static final String CONTENT_TYPE = "application/json";
private static final String IOT_HOST_PROPERTY = "iot.core.host";
private static final String IOT_PORT_PROPERTY = "iot.core.https.port";
private static final String IOT_KEY_MANAGER_HOST_PROPERTY = "iot.keymanager.host";
private static final String IOT_KEY_MANAGER_PORT_PROPERTY = "iot.keymanager.https.port";
static String getAbsolutePathOfConfig(String configFilePath) {
ClassLoader classLoader = TestUtils.class.getClassLoader();
URL invalidConfig = classLoader.getResource(configFilePath);
@ -39,16 +46,16 @@ public class TestUtils {
}
static void setSystemProperties() {
System.setProperty("iot.core.host", IOT_CORE_HOST);
System.setProperty("iot.core.https.port", IOT_CORE_HTTPS_PORT);
System.setProperty("iot.keymanager.host", IOT_KEYMANAGER_HOST);
System.setProperty("iot.keymanager.https.port", IOT_KEYMANAGER_PORT);
System.setProperty(IOT_HOST_PROPERTY, IOT_CORE_HOST);
System.setProperty(IOT_PORT_PROPERTY, IOT_CORE_HTTPS_PORT);
System.setProperty(IOT_KEY_MANAGER_HOST_PROPERTY, IOT_KEYMANAGER_HOST);
System.setProperty(IOT_KEY_MANAGER_PORT_PROPERTY, IOT_KEYMANAGER_PORT);
}
static void resetSystemProperties() {
System.clearProperty("iot.core.host");
System.clearProperty("iot.core.https.port");
System.clearProperty("iot.keymanager.host");
System.clearProperty("iot.keymanager.https.port");
System.clearProperty(IOT_HOST_PROPERTY);
System.clearProperty(IOT_PORT_PROPERTY);
System.clearProperty(IOT_KEY_MANAGER_HOST_PROPERTY);
System.clearProperty(IOT_KEY_MANAGER_PORT_PROPERTY);
}
}

@ -29,6 +29,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Mock implementation for CloseableHttpClient to be used in test cases.
*/
public class MockClient extends CloseableHttpClient {
private List<CloseableHttpResponse> responses = new ArrayList<>();
private int responseCount = 0;
@ -36,8 +39,12 @@ public class MockClient extends CloseableHttpClient {
@Override
protected CloseableHttpResponse doExecute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext)
throws IOException {
this.responseCount++;
return this.responses.get(this.responseCount - 1);
if (this.responseCount < this.responses.size()) {
this.responseCount++;
return this.responses.get(this.responseCount - 1);
} else {
return new MockHttpResponse();
}
}
@Override

@ -28,6 +28,10 @@ import org.apache.http.params.HttpParams;
import java.io.IOException;
import java.util.Locale;
/**
* Mock http response to be used in the test cases.
*
*/
public class MockHttpResponse implements CloseableHttpResponse {
private HttpEntity httpEntity;
private StatusLine statusLine;

Loading…
Cancel
Save