REPO-2620 REST API: Retrieve Application Audit Entries - add TAS-level test

Extend TAS with AuditValuesModel in order to validate Retrieval of the Audit App Entries
       Add Sanity level TAS Tests.
This commit is contained in:
Alexandru-Eusebiu Epure
2017-07-13 17:46:48 +03:00
parent a101d55a41
commit 3197eba6b5
2 changed files with 129 additions and 40 deletions
@@ -6,10 +6,14 @@ import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestRequest;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.RestAuditAppModel;
import org.alfresco.rest.model.RestAuditAppModelsCollection;
import org.alfresco.rest.model.RestAuditEntryModel;
import org.alfresco.rest.model.RestAuditEntryModelsCollection;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import com.jayway.restassured.RestAssured;
@@ -20,17 +24,34 @@ public abstract class AuditTest extends RestTest
@Autowired
protected RestWrapper restAPI;
protected UserModel userModel;
protected UserModel userModel,adminUser;
protected RestAuditAppModelsCollection restAuditCollection;
protected RestAuditAppModel restAuditAppModel;
protected RestAuditEntryModel restAuditEntryModel;
protected RestAuditEntryModelsCollection restAuditEntryCollection;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
//Using two users, because audit API is designed for users with admin rights.
userModel = dataUser.createRandomTestUser();
adminUser=dataUser.getAdminUser();
//GET /alfresco/service/api/audit/control to verify if Audit is enabled on the system.
RestAssured.basePath = "";
restAPI.configureRequestSpec().setBasePath(RestAssured.basePath);
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "alfresco/service/api/audit/control");
RestResponse response = restAPI.authenticateUser(dataUser.getAdminUser()).process(request);
response.assertThat().body("enabled", is(true));
//GET /audit-applications and verify that there are audit applications in the system.
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
//
int i=0;
do
{
restAuditAppModel = restAuditCollection.getEntries().get(i++).onModel();
}while (!restAuditAppModel.getName().equals("alfresco-access"));
}
}
@@ -1,6 +1,7 @@
package org.alfresco.rest.audit;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.alfresco.rest.model.RestAuditAppModel;
import org.alfresco.utility.model.TestGroup;
@@ -12,59 +13,43 @@ import org.testng.annotations.Test;
public class GetAuditCoreTests extends AuditTest
{
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications and status code is 200")
public void getAuditApplicationsWithAdminUser() throws Exception
{
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets audit application info")
public void getAuditApplicationInfoWithAdminUser() throws Exception
{
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
RestAuditAppModel firstRestAuditAppModel = restAuditCollection.getEntries().get(0).onModel();
firstRestAuditAppModel.assertThat().field("isEnabled").is(true);
firstRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service");
firstRestAuditAppModel.assertThat().field("id").is("sync");
restAuditAppModel.assertThat().field("isEnabled").is(true);
restAuditAppModel.assertThat().field("name").is("alfresco-access");
restAuditAppModel.assertThat().field("id").is("alfresco-access");
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
.getAuditApp(firstRestAuditAppModel).assertThat().field("isEnabled").is(true);
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(restAuditAppModel).assertThat().field("isEnabled").is(true);
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
.getAuditApp(firstRestAuditAppModel).assertThat().field("name").is("Alfresco Sync Service");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(restAuditAppModel).assertThat().field("name").is("alfresco-access");
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
.getAuditApp(firstRestAuditAppModel).assertThat().field("id").is("sync");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(restAuditAppModel).assertThat().field("id").is("alfresco-access");
RestAuditAppModel secondRestAuditAppModel = restAuditCollection.getEntries().get(1).onModel();
secondRestAuditAppModel.assertThat().field("isEnabled").is(true);
secondRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service");
secondRestAuditAppModel.assertThat().field("id").is("tagging");
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("isEnabled").is(true);
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("name").is("Alfresco Tagging Service");
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("id").is("tagging");
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify a normal user gets a list of audit applications and status code is 403")
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if a normal user gets a list of audit applications and status code is 403")
public void getAuditApplicationsWithNormalUser() throws Exception
{
restAuditCollection = restClient.authenticateUser(userModel).withCoreAPI().usingAudit().getAuditApplications();
@@ -77,7 +62,7 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using skipCount and status code is 200")
public void getAuditApplicationsWithAdminUserUsingValidSkipCount() throws Exception
{
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=1").withCoreAPI()
restAuditCollection = restClient.authenticateUser(adminUser).withParams("skipCount=1").withCoreAPI()
.usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.getPagination().assertThat().field("totalItems").isNotNull().and().field("totalItems")
@@ -89,7 +74,7 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using invalid skipCount and status code is 400")
public void getAuditApplicationsWithAdminUserUsingInvalidSkipCount() throws Exception
{
restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=-1").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("skipCount=-1").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
}
@@ -99,7 +84,7 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using maxItems and status code is 200")
public void getAuditApplicationsWithAdminUserUsingValidMaxItems() throws Exception
{
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withParams("maxItems=1").withCoreAPI()
restAuditCollection = restClient.authenticateUser(adminUser).withParams("maxItems=1").withCoreAPI()
.usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.getPagination().assertThat().field("totalItems").isNotNull().and().field("totalItems")
@@ -112,11 +97,11 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using invalid maxItems and status code is 400")
public void getAuditApplicationsWithAdminUserUsingInvalidMaxItems() throws Exception
{
restClient.authenticateUser(dataUser.getAdminUser()).withParams("maxItems=-1").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("maxItems=-1").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(dataUser.getAdminUser()).withParams("maxItems=0").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("maxItems=0").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
@@ -127,7 +112,7 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using skipCount and maxItems and status code is 200")
public void getAuditApplicationsWithAdminUserUsingValidSkipCountAndMaxItems() throws Exception
{
restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=1&maxItems=1")
restAuditCollection = restClient.authenticateUser(adminUser).withParams("skipCount=1&maxItems=1")
.withCoreAPI().usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.getPagination().assertThat().field("totalItems").isNotNull().and().field("totalItems")
@@ -140,21 +125,104 @@ public class GetAuditCoreTests extends AuditTest
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using invalid skipCount and/or invalid maxItems and status code is 400")
public void getAuditApplicationsWithAdminUserUsingInvalidSkipCountAndMaxItems() throws Exception
{
restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=-1&maxItems=1").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=1").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=-1&maxItems=-1").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=-1").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=-1&maxItems=0").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=0").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(dataUser.getAdminUser()).withParams("skipCount=1&maxItems=-1").withCoreAPI().usingAudit()
restClient.authenticateUser(adminUser).withParams("skipCount=1&maxItems=-1").withCoreAPI().usingAudit()
.getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if a normal user gets a list of audit entries for audit application auditApplicationId and status code is 403")
public void getAuditEntriesWithNormalUser() throws Exception
{
restClient.authenticateUser(userModel).withCoreAPI().usingAudit()
.listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN);
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using invalid skipCount and/or invalid maxItems and status code is 400")
public void getAuditEntriesWithAdminUserUsingInvalidSkipCountAndMaxItems() throws Exception
{
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=1").withCoreAPI().usingAudit()
.listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=-1").withCoreAPI().usingAudit()
.listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(adminUser).withParams("skipCount=-1&maxItems=0").withCoreAPI().usingAudit()
.listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.authenticateUser(adminUser).withParams("skipCount=1&maxItems=-1").withCoreAPI().usingAudit()
.listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using valid skipCount and maxItems and status code is 200")
public void getAuditEntriesWithAdminUserUsingValidSkipCountAndMaxItems() throws Exception
{
restAuditEntryCollection = restClient.authenticateUser(adminUser).withParams("skipCount=1&maxItems=1")
.withCoreAPI().usingAudit().listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditEntryCollection.getPagination().assertThat().field("totalItems").isNotNull().and().field("totalItems")
.isGreaterThan(0).and().field("maxItems").is("1").and().field("skipCount").is("1");
assertEquals(restAuditEntryCollection.getEntries().size(), 1);
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using orderBy and status code is 200")
public void getAuditEntriesWithAdminUserUsingOrderBy() throws Exception
{
restAuditEntryCollection = restClient.authenticateUser(adminUser).withParams("orderBy=createdAt ASC&maxItems=10")
.withCoreAPI().usingAudit().listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.OK);
String ascId = restAuditEntryCollection.getEntries().get(1).onModel().getId();
restAuditEntryCollection = restClient.authenticateUser(adminUser).withParams("orderBy=createdAt DESC&maxItems=10")
.withCoreAPI().usingAudit().listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.OK);
assertTrue(Integer.parseInt(restAuditEntryCollection.getEntries().get(1).onModel().getId()) > Integer.parseInt(ascId));
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API,
TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets a list of audit applications using the where parameter to and status code is 200")
public void getAuditEntriesWithAdminUserUsingWhere() throws Exception
{
restAuditEntryCollection = restClient.authenticateUser(adminUser).withParams("maxItems=10").withCoreAPI().usingAudit().listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.OK);
String id1 = restAuditEntryCollection.getEntries().get(restAuditEntryCollection.getPagination().getCount()-1).onModel().getId();
String id2 = restAuditEntryCollection.getEntries().get(restAuditEntryCollection.getPagination().getCount()/2).onModel().getId();
restAuditEntryCollection = restClient.authenticateUser(adminUser).withParams("where=(id BETWEEN ("+id2+","+id1+"))")
.withCoreAPI().usingAudit().listAuditEntriesForAnAuditApplication(restAuditAppModel.getId());
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditEntryCollection.assertThat().entriesListCountIs(Integer.parseInt(id1)-Integer.parseInt(id2));
assertEquals(id2, restAuditEntryCollection.getEntries().get(0).onModel().getId());
assertEquals(Integer.toString(Integer.parseInt(id1)-1), restAuditEntryCollection.getEntries().get(Integer.parseInt(id1)-Integer.parseInt(id2)-1).onModel().getId());
}
}