mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api.tests;
|
package org.alfresco.rest.api.tests;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -65,13 +67,13 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAuditApp() throws Exception
|
public void testGetAuditApps() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
setRequestContext(DEFAULT_ADMIN);
|
setRequestContext(DEFAULT_ADMIN);
|
||||||
testGetAuditAppSkipPaging();
|
testGetAuditAppsSkipPaging();
|
||||||
|
|
||||||
}
|
}
|
||||||
finally
|
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<AuditApp> 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.
|
// +ve: check skip count.
|
||||||
{
|
{
|
||||||
@@ -120,7 +159,7 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
|||||||
|
|
||||||
private ListResponse<AuditApp> getAuditApps(final PublicApiClient.Paging paging) throws Exception
|
private ListResponse<AuditApp> 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<String, String> createParams(Paging paging)
|
protected Map<String, String> createParams(Paging paging)
|
||||||
@@ -141,4 +180,12 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateAuditApplicationFields(AuditApp auditApp)
|
||||||
|
{
|
||||||
|
assertNotNull(auditApp);
|
||||||
|
assertNotNull(auditApp.getId());
|
||||||
|
assertNotNull(auditApp.getName());
|
||||||
|
assertNotNull(auditApp.getIsEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2431,7 +2431,6 @@ public class PublicApiClient
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AuditApps extends AbstractProxy
|
public class AuditApps extends AbstractProxy
|
||||||
@@ -2452,7 +2451,32 @@ public class PublicApiClient
|
|||||||
return null;
|
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<String, String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user