added checks for property setting, fixing merge fallouts and reusing code

This commit is contained in:
jcule
2017-07-14 20:44:40 +01:00
parent 40ac17a085
commit b206af38e3
3 changed files with 37 additions and 40 deletions
@@ -11,11 +11,12 @@ 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.alfresco.utility.network.JmxBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.Assert;
import com.jayway.restassured.RestAssured;
public abstract class AuditTest extends RestTest
@@ -24,6 +25,9 @@ public abstract class AuditTest extends RestTest
@Autowired
protected RestWrapper restAPI;
@Autowired
protected JmxBuilder jmxBuilder;
protected UserModel userModel,adminUser;
protected RestAuditAppModelsCollection restAuditCollection;
protected RestAuditAppModel restAuditAppModel;
@@ -43,12 +47,18 @@ public abstract class AuditTest extends RestTest
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);
RestResponse response = restAPI.authenticateUser(adminUser).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();
restAuditCollection = restClient.authenticateUser(adminUser).withCoreAPI().usingAudit().getAuditApplications();
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
//enable alfresco-access audit application
jmxBuilder.getJmxClient().writeProperty("Alfresco:Type=Configuration,Category=Audit,id1=default", "audit.alfresco-access.enabled", Boolean.TRUE.toString());
String alfrescoAccessEnabled = jmxBuilder.getJmxClient().readProperty("Alfresco:Type=Configuration,Category=Audit,id1=default", "audit.alfresco-access.enabled").toString();
Assert.assertEquals(alfrescoAccessEnabled, Boolean.TRUE.toString(), String.format("Property audit.alfresco-access.enabled is [%s]", alfrescoAccessEnabled));
//
int i=0;
do
@@ -64,7 +74,7 @@ public abstract class AuditTest extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
RestAuditAppModel syncRestAuditAppModel = restAuditCollection.getEntries().get(0).onModel();
return syncRestAuditAppModel;
return syncRestAuditAppModel;
}
protected RestAuditAppModel getTaggingRestAuditAppModel(UserModel userModel) throws Exception
@@ -73,7 +83,7 @@ public abstract class AuditTest extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK);
restAuditCollection.assertThat().entriesListIsNotEmpty();
RestAuditAppModel taggingRestAuditAppModel = restAuditCollection.getEntries().get(1).onModel();
return taggingRestAuditAppModel;
return taggingRestAuditAppModel;
}
}
@@ -21,30 +21,17 @@ public class GetAuditCoreTests extends AuditTest
restAuditAppModel.assertThat().field("isEnabled").is(true);
restAuditAppModel.assertThat().field("name").is("alfresco-access");
restAuditAppModel.assertThat().field("id").is("alfresco-access");
syncRestAuditAppModel = getSyncRestAuditAppModel(adminUser);
syncRestAuditAppModel.assertThat().field("isEnabled").is(true);
syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service");
syncRestAuditAppModel.assertThat().field("id").is("sync");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(restAuditAppModel).assertThat().field("isEnabled").is(true);
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(restAuditAppModel).assertThat().field("name").is("alfresco-access");
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(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("isEnabled").is(true);
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("name").is("Alfresco Tagging Service");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit()
.getAuditApp(secondRestAuditAppModel).assertThat().field("id").is("tagging");
taggingRestAuditAppModel = getTaggingRestAuditAppModel(adminUser);
taggingRestAuditAppModel.assertThat().field("isEnabled").is(true);
taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service");
taggingRestAuditAppModel.assertThat().field("id").is("tagging");
}
@Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE })
@@ -14,20 +14,20 @@ public class PutAuditCoreTests extends AuditTest
public void enableDisableSyncApplicationAuditingAsAdminUser() throws Exception
{
//disable sync audit app
syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser());
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "false");
syncRestAuditAppModel = getSyncRestAuditAppModel(adminUser);
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "false");
//check isEnabled=false
syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser());
syncRestAuditAppModel = getSyncRestAuditAppModel(adminUser);
syncRestAuditAppModel.assertThat().field("isEnabled").is(false);
syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service");
syncRestAuditAppModel.assertThat().field("id").is("sync");
//enable sync audit app
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "true");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "true");
//check isEnabled=true
syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser());
syncRestAuditAppModel = getSyncRestAuditAppModel(adminUser);
syncRestAuditAppModel.assertThat().field("isEnabled").is(true);
syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service");
syncRestAuditAppModel.assertThat().field("id").is("sync");
@@ -40,20 +40,20 @@ public class PutAuditCoreTests extends AuditTest
public void enableDisableTaggingApplicationAuditingAsAdminUser() throws Exception
{
//disable tagging audit app
taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser());
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "false");
taggingRestAuditAppModel = getTaggingRestAuditAppModel(adminUser);
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "false");
//check isEnabled=false
taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser());
taggingRestAuditAppModel = getTaggingRestAuditAppModel(adminUser);
taggingRestAuditAppModel.assertThat().field("isEnabled").is(false);
taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service");
taggingRestAuditAppModel.assertThat().field("id").is("tagging");
//enable tagging audit app
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "true");
restClient.authenticateUser(adminUser).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "true");
//check isEnabled=true
taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser());
taggingRestAuditAppModel = getTaggingRestAuditAppModel(adminUser);
taggingRestAuditAppModel.assertThat().field("isEnabled").is(true);
taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service");
taggingRestAuditAppModel.assertThat().field("id").is("tagging");
@@ -67,7 +67,7 @@ public class PutAuditCoreTests extends AuditTest
public void enableDisableSyncApplicationAuditingAsNormalUser() throws Exception
{
//disable sync audit app
syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser());
syncRestAuditAppModel = getSyncRestAuditAppModel(adminUser);
restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "false");
//permission denied
@@ -86,7 +86,7 @@ public class PutAuditCoreTests extends AuditTest
public void enableDisableTaggingApplicationAuditingAsNormalUser() throws Exception
{
//disable tagging audit app
taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser());
taggingRestAuditAppModel = getTaggingRestAuditAppModel(adminUser);
restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "false");
//permission denied