Adding assertion of topology initizlization and refactoring the test classes to 
use same CRUD operations from RestClient


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/f995fb3b
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/f995fb3b
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/f995fb3b

Branch: refs/heads/data-publisher-integration
Commit: f995fb3bbd0a2b10b610c90e43369b940b9ce5ca
Parents: d5680aa
Author: reka <[email protected]>
Authored: Wed Aug 5 14:09:34 2015 +0530
Committer: reka <[email protected]>
Committed: Thu Aug 6 19:33:43 2015 +0530

----------------------------------------------------------------------
 .../tests/ApplicationPolicyTest.java            | 137 ++--------
 .../integration/tests/ApplicationTest.java      | 227 +++-------------
 .../tests/AutoscalingPolicyTest.java            | 136 ++--------
 .../integration/tests/CartridgeGroupTest.java   | 141 ++--------
 .../integration/tests/CartridgeTest.java        | 143 ++--------
 .../integration/tests/DeploymentPolicyTest.java | 141 ++--------
 .../integration/tests/NetworkPartitionTest.java | 137 ++--------
 .../tests/SampleApplicationsTest.java           | 265 +++++++++++--------
 .../tests/StratosArtifactsUtils.java            |  53 ----
 .../integration/tests/rest/RestClient.java      | 208 ++++++++++++++-
 10 files changed, 516 insertions(+), 1072 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
index 05110bb..ec5bf04 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
@@ -19,138 +19,41 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
  * Test to handle Network partition CRUD operations
  */
-public class ApplicationPolicyTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String applicationPolicies = "/application-policies/";
-    String applicationPoliciesUpdate = "/application-policies/update/";
-
+public class ApplicationPolicyTest {
+    private static final Log log = 
LogFactory.getLog(ApplicationPolicyTest.class);
+    private static final String applicationPolicies = "/application-policies/";
+    private static final String applicationPoliciesUpdate = 
"/application-policies/update/";
+    private static final String entityName = "applicationPolicy";
 
-    public boolean addApplicationPolicy(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(applicationPolicies + 
networkPartitionId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATION_POLICIES).build();
 
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the 
application policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add application policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean addApplicationPolicy(String applicationPolicyId, RestClient 
restClient) {
+        return restClient.addEntity(applicationPolicies + "/" + 
applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES, entityName);
     }
 
-    public ApplicationPolicyBean getApplicationPolicy(String 
networkPartitionId, String endpoint,
-                                                    RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATION_POLICIES + "/" +
-                    networkPartitionId).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
ApplicationPolicyBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
application policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get application policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public ApplicationPolicyBean getApplicationPolicy(String 
applicationPolicyId, RestClient restClient) {
+
+        ApplicationPolicyBean bean = (ApplicationPolicyBean) restClient.
+                getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                        ApplicationPolicyBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateApplicationPolicy(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(applicationPoliciesUpdate + 
networkPartitionId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATION_POLICIES).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
application policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update application policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateApplicationPolicy(String applicationPolicyId, 
RestClient restClient) {
+        return restClient.updateEntity(applicationPoliciesUpdate + "/" + 
applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES, entityName);
+
     }
 
-    public boolean removeApplicationPolicy(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATION_POLICIES + "/" +
-                    networkPartitionId).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("it is used")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
application policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove application policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeApplicationPolicy(String applicationPolicyId, 
RestClient restClient) {
+        return restClient.removeEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId, entityName);
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java
index d4f77a6..af18163 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java
@@ -19,224 +19,59 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.application.ApplicationBean;
-import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
- * Test to handle autoscaling policy CRUD operations
+ * Test to handle application CRUD operations, deploy and undeploy
  */
-public class ApplicationTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
+public class ApplicationTest {
+    private static final Log log = LogFactory.getLog(ApplicationTest.class);
     String applications = "/applications/simple/single-cartridge-app/";
     String applicationsUpdate = 
"/applications/simple/single-cartridge-app/update/";
+    private static final String entityName = "application";
 
-
-    public boolean addApplication(String applicationId, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(applications + 
applicationId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATIONS).build();
-
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean addApplication(String applicationId, RestClient restClient) 
{
+        return restClient.addEntity(applications + "/" + applicationId,
+                RestConstants.APPLICATIONS, entityName);
     }
 
-    public boolean deployApplication(String applicationId, String 
applicationPolicyId,
-                                     String endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATIONS + 
"/" + applicationId +
-            RestConstants.APPLICATIONS_DEPLOY + "/" + 
applicationPolicyId).build();
-
-            HttpResponse response = restClient.doPost(uri, "");
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while deploying the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not deploy application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public ApplicationBean getApplication(String applicationId,
+                                          RestClient restClient) {
+        ApplicationBean bean = (ApplicationBean) restClient.
+                getEntity(RestConstants.APPLICATIONS, applicationId,
+                        ApplicationBean.class, entityName);
+        return bean;
     }
 
-    public boolean undeployApplication(String applicationId,
-                                     String endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATIONS + 
"/" + applicationId +
-                    RestConstants.APPLICATIONS_UNDEPLOY).build();
-
-            HttpResponse response = restClient.doPost(uri, "");
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while undeploying the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not undeploy application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateApplication(String applicationId, RestClient 
restClient) {
+        return restClient.updateEntity(applicationsUpdate + "/" + 
applicationId,
+                RestConstants.APPLICATIONS, entityName);
     }
 
-    public boolean forceUndeployApplication(String applicationId,
-                                       String endpoint, RestClient restClient) 
{
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATIONS + 
"/" + applicationId +
-                    RestConstants.APPLICATIONS_UNDEPLOY + 
"?force=true").build();
+    public boolean removeApplication(String applicationId, RestClient 
restClient) {
+        return restClient.removeEntity(RestConstants.APPLICATIONS, 
applicationId, entityName);
 
-            HttpResponse response = restClient.doPost(uri, "");
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while force undeploying 
the application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not forcefully undeploy application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
     }
 
-    public ApplicationBean getApplication(String applicationId, String 
endpoint,
-                                                    RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATIONS + 
"/" +
-                    applicationId).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
ApplicationBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean deployApplication(String applicationId, String 
applicationPolicyId,
+                                     RestClient restClient) {
+        return restClient.deployEntity(RestConstants.APPLICATIONS + "/" + 
applicationId +
+                RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId, 
entityName);
     }
 
-    public boolean updateApplication(String applicationId, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(applicationsUpdate + 
applicationId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.APPLICATIONS).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean undeployApplication(String applicationId,
+                                       RestClient restClient) {
+        return restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
applicationId +
+                RestConstants.APPLICATIONS_UNDEPLOY, entityName);
     }
 
-    public boolean removeApplication(String applicationId, String endpoint, 
RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATIONS + 
"/" +
-                    applicationId).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
application";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove application";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean forceUndeployApplication(String applicationId,
+                                            RestClient restClient) {
+        return restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
applicationId +
+                RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
entityName);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
index c76c0ef..7c04d92 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
@@ -18,137 +18,41 @@
  */
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
  * Test to handle autoscaling policy CRUD operations
  */
-public class AutoscalingPolicyTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String autoscalingPolicy = "/autoscaling-policies/";
-    String autoscalingPolicyUpdate = "/autoscaling-policies/update/";
-
+public class AutoscalingPolicyTest {
+    private static final Log log = 
LogFactory.getLog(AutoscalingPolicyTest.class);
+    private static final String autoscalingPolicy = "/autoscaling-policies/";
+    private static final String autoscalingPolicyUpdate = 
"/autoscaling-policies/update/";
+    private static final String entityName = "autoscalingPolicy";
 
-    public boolean addAutoscalingPolicy(String autoscalingPolicyName, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(autoscalingPolicy + 
autoscalingPolicyName);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.AUTOSCALING_POLICIES).build();
+    public boolean addAutoscalingPolicy(String autoscalingPolicyName, 
RestClient restClient) {
+        return restClient.addEntity(autoscalingPolicy + "/" + 
autoscalingPolicyName,
+                RestConstants.AUTOSCALING_POLICIES, entityName);
 
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            log.error("An unknown error occurred while trying to add 
autoscaling policy....");
-            throw new RuntimeException("An unknown error occurred while trying 
to add autoscaling policy");
-        } catch (Exception e) {
-            String message = "Could not add Autoscaling policy....";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
     }
 
-    public AutoscalePolicyBean getAutoscalingPolicy(String 
autoscalingPolicyName, String endpoint,
-                                                    RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.AUTOSCALING_POLICIES + "/" +
-                    autoscalingPolicyName).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
AutoscalePolicyBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
autosclaing policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get autoscaling policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public AutoscalePolicyBean getAutoscalingPolicy(String 
autoscalingPolicyName, RestClient restClient) {
+        AutoscalePolicyBean bean = (AutoscalePolicyBean) restClient.
+                getEntity(RestConstants.AUTOSCALING_POLICIES, 
autoscalingPolicyName,
+                        AutoscalePolicyBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateAutoscalingPolicy(String autoscalingPolicyName, 
String endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(autoscalingPolicyUpdate + 
autoscalingPolicyName);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.AUTOSCALING_POLICIES).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
autosclaing policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not updating autoscaling policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateAutoscalingPolicy(String autoscalingPolicyName, 
RestClient restClient) {
+        return restClient.updateEntity(autoscalingPolicyUpdate + "/" + 
autoscalingPolicyName,
+                RestConstants.AUTOSCALING_POLICIES, entityName);
+
     }
 
-    public boolean removeAutoscalingPolicy(String autoscalingPolicyName, 
String endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.AUTOSCALING_POLICIES + "/" +
-                    autoscalingPolicyName).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("is in use")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
autosclaing policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove autoscaling policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeAutoscalingPolicy(String autoscalingPolicyName, 
RestClient restClient) {
+        return restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, 
autoscalingPolicyName, entityName);
+
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java
index 4da1185..caf2838 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java
@@ -19,138 +19,39 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
- * Test to handle Network partition CRUD operations
+ * Test to handle Cartridge group CRUD operations
  */
-public class CartridgeGroupTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String cartridgeGroups = "/cartridges-groups/";
-    String cartridgeGroupsUpdate = "/cartridges-groups/update/";
-
-
-    public boolean addCartridgeGroup(String groupName, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(cartridgeGroups + 
groupName);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.CARTRIDGE_GROUPS).build();
-
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the cartridge 
group";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add cartridge group";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+public class CartridgeGroupTest {
+    private static final Log log = LogFactory.getLog(CartridgeGroupTest.class);
+    private static final String cartridgeGroups = "/cartridges-groups/";
+    private static final String cartridgeGroupsUpdate = 
"/cartridges-groups/update/";
+    private static final String entityName = "cartridgeGroup";
+
+    public boolean addCartridgeGroup(String groupName, RestClient restClient) {
+        return restClient.addEntity(cartridgeGroups + "/" + groupName,
+                RestConstants.CARTRIDGE_GROUPS, entityName);
     }
 
-    public CartridgeGroupBean getCartridgeGroup(String groupName, String 
endpoint,
-                                                    RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGE_GROUPS 
+ "/" +
-                    groupName).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
CartridgeGroupBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
cartridge group";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get cartridge group";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public CartridgeGroupBean getCartridgeGroup(String groupName, RestClient 
restClient) {
+        CartridgeGroupBean bean = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, groupName,
+                        CartridgeGroupBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateCartridgeGroup(String groupName, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(cartridgeGroupsUpdate + 
groupName);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.CARTRIDGE_GROUPS).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
cartridge group";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update cartridge group";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateCartridgeGroup(String groupName, RestClient 
restClient) {
+        return restClient.updateEntity(cartridgeGroupsUpdate + "/" + groupName,
+                RestConstants.CARTRIDGE_GROUPS, entityName);
     }
 
-    public boolean removeCartridgeGroup(String groupName, String endpoint, 
RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGE_GROUPS 
+ "/" +
-                    groupName).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("it is used")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
cartridge group";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove cartridge group";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeCartridgeGroup(String groupName, RestClient 
restClient) {
+        return restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
groupName, entityName);
+
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
index 680d8a7..fc5cfa0 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
@@ -19,138 +19,41 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.cartridge.CartridgeBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
- * Test to handle Network partition CRUD operations
+ * Test to handle Cartridge CRUD operations
  */
-public class CartridgeTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String cartridges = "/cartridges/mock/";
-    String cartridgesUpdate = "/cartridges/mock/update/";
-
-
-    public boolean addCartridge(String cartridgeType, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(cartridges + cartridgeType);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.CARTRIDGES).build();
-
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the 
cartridge";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add cartridge";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+public class CartridgeTest {
+    private static final Log log = LogFactory.getLog(CartridgeTest.class);
+    private static final String cartridges = "/cartridges/mock/";
+    private static final String cartridgesUpdate = "/cartridges/mock/update/";
+    private static final String entityName = "cartridge";
+    
+
+    public boolean addCartridge(String cartridgeType, RestClient restClient) {
+        return restClient.addEntity(cartridges + "/" + cartridgeType,
+                RestConstants.CARTRIDGES, entityName);
     }
 
-    public CartridgeBean getCartridge(String cartridgeType, String endpoint,
-                                                    RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES + "/" 
+
-                    cartridgeType).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
CartridgeBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
cartridge";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get cartridge";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public CartridgeBean getCartridge(String cartridgeType,
+                                      RestClient restClient) {
+        CartridgeBean bean = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                        CartridgeBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateCartridge(String cartridgeType, String endpoint, 
RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(cartridgesUpdate + 
cartridgeType);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.CARTRIDGES).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
cartridge";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update cartridge";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateCartridge(String cartridgeType, RestClient 
restClient) {
+        return restClient.updateEntity(cartridgesUpdate + "/" + cartridgeType,
+                RestConstants.CARTRIDGES, entityName);
     }
 
-    public boolean removeCartridge(String cartridgeType, String endpoint, 
RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES + "/" 
+
-                    cartridgeType).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if (response.getContent().contains("it is used")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
cartridge";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove cartridge";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeCartridge(String cartridgeType, RestClient 
restClient) {
+        return restClient.removeEntity(RestConstants.CARTRIDGES, 
cartridgeType, entityName);
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
index d7d4dd4..707f750 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
@@ -19,140 +19,39 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
- * Test to handle Network partition CRUD operations
+ * Test to handle Deployment policy CRUD operations
  */
-public class DeploymentPolicyTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String deploymentPolicies = "/deployment-policies/";
-    String deploymentPoliciesUpdate = "/deployment-policies/update/";
-
-
-    public boolean addDeploymentPolicy(String deploymentPolicyId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(deploymentPolicies + 
deploymentPolicyId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.DEPLOYMENT_POLICIES).build();
-
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the 
deployment policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add deployment policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+public class DeploymentPolicyTest {
+    private static final Log log = 
LogFactory.getLog(DeploymentPolicyTest.class);
+    private static final String deploymentPolicies = "/deployment-policies/";
+    private static final String deploymentPoliciesUpdate = 
"/deployment-policies/update/";
+    private static final String entityName = "deploymentPolicy";
+
+    public boolean addDeploymentPolicy(String deploymentPolicyId, RestClient 
restClient) {
+        return restClient.addEntity(deploymentPolicies + "/" + 
deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES, entityName);
     }
 
-    public DeploymentPolicyBean getDeploymentPolicy(String deploymentPolicyId, 
String endpoint,
+    public DeploymentPolicyBean getDeploymentPolicy(String deploymentPolicyId,
                                                     RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.DEPLOYMENT_POLICIES + "/" +
-                    deploymentPolicyId).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
DeploymentPolicyBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
deployment policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get deployment policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+        DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient.
+                getEntity(RestConstants.DEPLOYMENT_POLICIES, 
deploymentPolicyId,
+                        DeploymentPolicyBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateDeploymentPolicy(String deploymentPolicyId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(deploymentPoliciesUpdate + 
deploymentPolicyId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.DEPLOYMENT_POLICIES).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("it is used")) {
-                    return false;
-                } else {
-                        GsonBuilder gsonBuilder = new GsonBuilder();
-                        Gson gson = gsonBuilder.create();
-                        ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                        if (errorResponse != null) {
-                            throw new 
RuntimeException(errorResponse.getErrorMessage());
-                        }
-                    }
-                }
-            String msg = "An unknown error occurred while updating the 
deployment policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update deployment policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateDeploymentPolicy(String deploymentPolicyId, 
RestClient restClient) {
+        return restClient.updateEntity(deploymentPoliciesUpdate + "/" + 
deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES, entityName);
     }
 
-    public boolean removeDeploymentPolicy(String deploymentPolicyId, String 
endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.DEPLOYMENT_POLICIES + "/" +
-                    deploymentPolicyId).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("is in use")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
deployment policy";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove deployment policy";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeDeploymentPolicy(String deploymentPolicyId, 
RestClient restClient) {
+        return restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, 
deploymentPolicyId, entityName);
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f995fb3b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
index 42dff0a..ff27ea6 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
@@ -19,138 +19,39 @@
 
 package org.apache.stratos.integration.tests;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.stratos.common.beans.partition.NetworkPartitionBean;
-import org.apache.stratos.integration.tests.rest.ErrorResponse;
-import org.apache.stratos.integration.tests.rest.HttpResponse;
 import org.apache.stratos.integration.tests.rest.RestClient;
 
-import java.net.URI;
-
 /**
  * Test to handle Network partition CRUD operations
  */
-public class NetworkPartitionTest extends StratosArtifactsUtils {
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-    String networkPartitions = "/network-partitions/mock/";
-    String networkPartitionsUpdate = "/network-partitions/mock/update/";
-
-
-    public boolean addNetworkPartition(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(networkPartitions + 
networkPartitionId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.NETWORK_PARTITIONS).build();
-
-            HttpResponse response = restClient.doPost(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while adding the 
networkpartition";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not add networkpartition";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+public class NetworkPartitionTest {
+    private static final Log log = 
LogFactory.getLog(NetworkPartitionTest.class);
+    private static final String networkPartitions = 
"/network-partitions/mock/";
+    private static final String networkPartitionsUpdate = 
"/network-partitions/mock/update/";
+    private static final String entityName = "networkPartition";
+
+    public boolean addNetworkPartition(String networkPartitionId, RestClient 
restClient) {
+        return restClient.addEntity(networkPartitions + "/" + 
networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS, entityName);
     }
 
-    public NetworkPartitionBean getNetworkPartition(String networkPartitionId, 
String endpoint,
+    public NetworkPartitionBean getNetworkPartition(String networkPartitionId,
                                                     RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.NETWORK_PARTITIONS + "/" +
-                    networkPartitionId).build();
-            HttpResponse response = restClient.doGet(uri);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return gson.fromJson(response.getContent(), 
NetworkPartitionBean.class);
-                } else if (response.getStatusCode() == 404) {
-                    return null;
-                } else {
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while getting the 
networkpartition";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not get networkpartition";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+        NetworkPartitionBean bean = (NetworkPartitionBean) restClient.
+                getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                        NetworkPartitionBean.class, entityName);
+        return bean;
     }
 
-    public boolean updateNetworkPartition(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            String content = getJsonStringFromFile(networkPartitionsUpdate + 
networkPartitionId);
-            URI uri = new URIBuilder(endpoint + 
RestConstants.NETWORK_PARTITIONS).build();
-            HttpResponse response = restClient.doPut(uri, content);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while updating the 
networkpartition";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not update networkpartition";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean updateNetworkPartition(String networkPartitionId, 
RestClient restClient) {
+        return restClient.updateEntity(networkPartitionsUpdate + "/" + 
networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS, entityName);
     }
 
-    public boolean removeNetworkPartition(String networkPartitionId, String 
endpoint, RestClient restClient) {
-        try {
-            URI uri = new URIBuilder(endpoint + 
RestConstants.NETWORK_PARTITIONS + "/" +
-                    networkPartitionId).build();
-            HttpResponse response = restClient.doDelete(uri);
-            if (response != null) {
-                if ((response.getStatusCode() >= 200) && 
(response.getStatusCode() < 300)) {
-                    return true;
-                } else if(response.getContent().contains("it is used")) {
-                    return false;
-                } else {
-                    GsonBuilder gsonBuilder = new GsonBuilder();
-                    Gson gson = gsonBuilder.create();
-                    ErrorResponse errorResponse = 
gson.fromJson(response.getContent(), ErrorResponse.class);
-                    if (errorResponse != null) {
-                        throw new 
RuntimeException(errorResponse.getErrorMessage());
-                    }
-                }
-            }
-            String msg = "An unknown error occurred while removing the 
networkpartition";
-            log.error(msg);
-            throw new RuntimeException(msg);
-        } catch (Exception e) {
-            String message = "Could not remove networkpartition";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
+    public boolean removeNetworkPartition(String networkPartitionId, 
RestClient restClient) {
+        return restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, 
networkPartitionId, entityName);
     }
 }

Reply via email to