From 02d812a0cdb497d74cdc3768238a19fed523f448 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 12 Jul 2017 12:09:21 +0000 Subject: [PATCH] Merged 5.2.N-AUDIT-API (5.2.2) to 5.2.N (5.2.2) 137889 aforascu: REPO-1785 / REPO-2585 - Retrieve Audit Application info - added Junit tests (positive and negative) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137960 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/rest/api/tests/AuditAppTest.java | 55 +++++++++++++++++-- .../api/tests/client/PublicApiClient.java | 32 +++++++++-- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java b/source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java index 7ed0822d7f..e5c902fc75 100644 --- a/source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java @@ -25,6 +25,8 @@ */ package org.alfresco.rest.api.tests; +import static org.junit.Assert.assertNotNull; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -65,13 +67,13 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest } @Test - public void testGetAuditApp() throws Exception + public void testGetAuditApps() throws Exception { try { setRequestContext(DEFAULT_ADMIN); - testGetAuditAppSkipPaging(); + testGetAuditAppsSkipPaging(); } finally @@ -80,7 +82,44 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest } } - private void testGetAuditAppSkipPaging() throws Exception + @Test + public void testGetAuditApp() throws Exception + { + + final AuditApps auditAppsProxy = publicApiClient.auditApps(); + + // Negative tests + // Check with invalid audit application id. + { + setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); + auditAppsProxy.getAuditApp("invalidAuditId", HttpServletResponse.SC_NOT_FOUND); + } + + // Check that non-admin user doesn't have access to audit applications + { + setRequestContext(networkOne.getId(), user1, null); + auditAppsProxy.getAuditApp("randomAuditId", HttpServletResponse.SC_FORBIDDEN); + } + + // Positive tests + // Get audit application information + { + // Get the list of audit applications in the system + setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); + + int skipCount = 0; + int maxItems = 4; + Paging paging = getPaging(skipCount, maxItems); + + ListResponse auditApps = getAuditApps(paging); + + // Get audit application info + AuditApp auditApp = auditAppsProxy.getAuditApp(auditApps.getList().get(0).getId()); + validateAuditApplicationFields(auditApp); + } + } + + private void testGetAuditAppsSkipPaging() throws Exception { // +ve: check skip count. { @@ -120,7 +159,7 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest private ListResponse getAuditApps(final PublicApiClient.Paging paging) throws Exception { - return getAuditApps(paging, "Failed to get groups", HttpServletResponse.SC_OK); + return getAuditApps(paging, "Failed to get audit applications", HttpServletResponse.SC_OK); } protected Map createParams(Paging paging) @@ -141,4 +180,12 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest return params; } + private void validateAuditApplicationFields(AuditApp auditApp) + { + assertNotNull(auditApp); + assertNotNull(auditApp.getId()); + assertNotNull(auditApp.getName()); + assertNotNull(auditApp.getIsEnabled()); + } + } diff --git a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java index 583bfe7f0a..21ae3ca7b7 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java @@ -2431,10 +2431,9 @@ public class PublicApiClient return null; } - } - public class AuditApps extends AbstractProxy + public class AuditApps extends AbstractProxy { public ListResponse getAuditApps(Map params, String errorMessage, int expectedStatus) throws PublicApiException @@ -2451,8 +2450,33 @@ public class PublicApiClient } return null; } - + + public AuditApp getAuditApp(String applicationId) throws PublicApiException + { + return getAuditApp(applicationId, HttpServletResponse.SC_OK); + } + + public AuditApp getAuditApp(String applicationId, int expectedStatus) throws PublicApiException + { + return getAuditApp(applicationId, null, expectedStatus); + } + + public AuditApp getAuditApp(String applicationId, Map params, int expectedStatus) throws PublicApiException + { + HttpResponse response = getSingle("audit-applications", applicationId, null, null, params, "Failed to get Audit Application " + applicationId, + expectedStatus); + + if (response != null && response.getJsonResponse() != null) + { + JSONObject jsonEntry = (JSONObject) response.getJsonResponse().get("entry"); + if (jsonEntry != null) + { + return AuditApp.parseAuditApp(jsonEntry); + } + } + return null; + } + } - }