Integrate RM Community REST API Automation into RM UI Automation

This commit is contained in:
Tuna Aksoy
2016-11-17 12:21:52 +00:00
parent 3406a078f7
commit b2ee0adb7e
4 changed files with 34 additions and 19 deletions

View File

@@ -33,11 +33,14 @@ import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT; import static org.springframework.http.HttpMethod.PUT;
import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestAPI;
import org.alfresco.rest.rm.model.site.RMSite; import org.alfresco.rest.rm.model.site.RMSite;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -52,6 +55,9 @@ import org.springframework.stereotype.Component;
@Scope (value = "prototype") @Scope (value = "prototype")
public class RMSiteAPI extends RestAPI<RMSiteAPI> public class RMSiteAPI extends RestAPI<RMSiteAPI>
{ {
@Autowired
private DataUser dataUser;
/** /**
* Get the RM site * Get the RM site
* *
@@ -139,4 +145,22 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
"ig-sites/rm" "ig-sites/rm"
)); ));
} }
/**
* Checks if the RM site exists or not
*
* @return <code>true</code> if the RM site exists, <code>false</code> otherwise.
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: GET request is supported only for the RM site</li>
* <li>Api Response code 401 If authentication failed</li>
* <li>Api Response code 409 If RM Site does not exist</li>
* <li>Api Response code default Unexpected error</li>
*/
public boolean existsRMSite() throws Exception
{
usingRestWrapper().authenticateUser(dataUser.getAdminUser());
getSite();
return usingRestWrapper().getStatusCode().equals(OK.toString());
}
} }

View File

@@ -42,7 +42,6 @@ import static org.alfresco.rest.rm.model.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.rest.rm.model.site.RMSiteFields.TITLE; import static org.alfresco.rest.rm.model.site.RMSiteFields.TITLE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured; import com.jayway.restassured.RestAssured;
@@ -123,7 +122,7 @@ public class BaseRestTest extends RestTest
public void createRMSiteIfNotExists() throws Exception public void createRMSiteIfNotExists() throws Exception
{ {
// Check RM site doesn't exist // Check RM site doesn't exist
if (!siteRMExists()) if (!rmSiteAPI.existsRMSite())
{ {
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
@@ -142,16 +141,6 @@ public class BaseRestTest extends RestTest
} }
} }
/**
* Check if the RM site exists via the GET request
*/
public boolean siteRMExists() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.getSite();
return restWrapper.getStatusCode().equals(OK.toString());
}
/** /**
* Helper method to create child category * Helper method to create child category
* *

View File

@@ -94,7 +94,7 @@ public class FilePlanTests extends BaseRestTest
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception
{ {
// Check RM Site Exist // Check RM Site Exist
if (siteRMExists()) if (rmSiteAPI.existsRMSite())
{ {
// Delete RM Site // Delete RM Site
rmSiteAPI.deleteRMSite(); rmSiteAPI.deleteRMSite();

View File

@@ -94,7 +94,7 @@ public class RMSiteTests extends BaseRestTest
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists // Check if the RM site exists
if (siteRMExists()) if (rmSiteAPI.existsRMSite())
{ {
// Delete the RM site // Delete the RM site
rmSiteAPI.deleteRMSite(); rmSiteAPI.deleteRMSite();
@@ -192,16 +192,18 @@ public class RMSiteTests extends BaseRestTest
// Authenticate with admin user // Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site // Check if RM Site exists
RMSite rmSite = rmSiteAPI.getSite(); if (!rmSiteAPI.existsRMSite())
if (!siteRMExists())
{ {
// Verify the status code when RM site doesn't exist // Verify the status code when RM site doesn't exist
restWrapper.assertStatusCodeIs(NOT_FOUND); restWrapper.assertStatusCodeIs(NOT_FOUND);
createRMSiteIfNotExists(); createRMSiteIfNotExists();
} }
else else
{ {
// Get the RM site
RMSite rmSite = rmSiteAPI.getSite();
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(OK); restWrapper.assertStatusCodeIs(OK);
assertEquals(rmSite.getId(), RM_ID); assertEquals(rmSite.getId(), RM_ID);
@@ -227,7 +229,7 @@ public class RMSiteTests extends BaseRestTest
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists // Check if the RM site exists
if (siteRMExists()) if (rmSiteAPI.existsRMSite())
{ {
// Delete the RM site // Delete the RM site
rmSiteAPI.deleteRMSite(); rmSiteAPI.deleteRMSite();