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)
137882 anechifor: REPO-1784 - Retrieve Audit Applications Implementation subtask - REPO-2581 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137959 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -75,7 +75,8 @@ import org.junit.runners.Suite;
|
||||
TestFavourites.class,
|
||||
TestPublicApi128.class,
|
||||
TestPublicApiCaching.class,
|
||||
TestDownloads.class
|
||||
TestDownloads.class,
|
||||
AuditAppTest.class
|
||||
})
|
||||
public class ApiTest
|
||||
{
|
||||
|
144
source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java
Normal file
144
source/test-java/org/alfresco/rest/api/tests/AuditAppTest.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.AuditApps;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.data.AuditApp;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
|
||||
protected PermissionService permissionService;
|
||||
protected AuthorityService authorityService;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
|
||||
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
|
||||
authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuditApp() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
setRequestContext(DEFAULT_ADMIN);
|
||||
testGetAuditAppSkipPaging();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void testGetAuditAppSkipPaging() throws Exception
|
||||
{
|
||||
// +ve: check skip count.
|
||||
{
|
||||
|
||||
// Paging and list auditApp
|
||||
|
||||
int skipCount = 0;
|
||||
int maxItems = 4;
|
||||
Paging paging = getPaging(skipCount, maxItems);
|
||||
|
||||
ListResponse<AuditApp> resp = getAuditApps(paging);
|
||||
|
||||
// Paging and list groups with skip count.
|
||||
|
||||
skipCount = 2;
|
||||
maxItems = 2;
|
||||
paging = getPaging(skipCount, maxItems);
|
||||
|
||||
ListResponse<AuditApp> sublistResponse = getAuditApps(paging);
|
||||
|
||||
List<AuditApp> expectedSublist = sublist(resp.getList(), skipCount, maxItems);
|
||||
checkList(expectedSublist, sublistResponse.getPaging(), sublistResponse);
|
||||
}
|
||||
|
||||
// -ve: check skip count.
|
||||
{
|
||||
getAuditApps(getPaging(-1, null), "", HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ListResponse<AuditApp> getAuditApps(final PublicApiClient.Paging paging, String errorMessage, int expectedStatus) throws Exception
|
||||
{
|
||||
final AuditApps auditAppsProxy = publicApiClient.auditApps();
|
||||
return auditAppsProxy.getAuditApps(createParams(paging), errorMessage, expectedStatus);
|
||||
}
|
||||
|
||||
private ListResponse<AuditApp> getAuditApps(final PublicApiClient.Paging paging) throws Exception
|
||||
{
|
||||
return getAuditApps(paging, "Failed to get groups", HttpServletResponse.SC_OK);
|
||||
}
|
||||
|
||||
protected Map<String, String> createParams(Paging paging)
|
||||
{
|
||||
Map<String, String> params = new HashMap<String, String>(2);
|
||||
if (paging != null)
|
||||
{
|
||||
if (paging.getSkipCount() != null)
|
||||
{
|
||||
params.put("skipCount", String.valueOf(paging.getSkipCount()));
|
||||
}
|
||||
if (paging.getMaxItems() != null)
|
||||
{
|
||||
params.put("maxItems", String.valueOf(paging.getMaxItems()));
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
@@ -46,10 +46,12 @@ import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
|
||||
import org.alfresco.rest.api.model.SiteUpdate;
|
||||
import org.alfresco.rest.api.tests.TestPeople;
|
||||
import org.alfresco.rest.api.tests.TestSites;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
|
||||
import org.alfresco.rest.api.tests.client.data.Activities;
|
||||
import org.alfresco.rest.api.tests.client.data.Activity;
|
||||
import org.alfresco.rest.api.tests.client.data.AuditApp;
|
||||
import org.alfresco.rest.api.tests.client.data.CMISNode;
|
||||
import org.alfresco.rest.api.tests.client.data.Comment;
|
||||
import org.alfresco.rest.api.tests.client.data.ContentData;
|
||||
@@ -120,6 +122,8 @@ public class PublicApiClient
|
||||
private SiteMembershipRequests siteMembershipRequests;
|
||||
private Groups groups;
|
||||
private RawProxy rawProxy;
|
||||
private AuditApps auditApps;
|
||||
|
||||
|
||||
private ThreadLocal<RequestContext> rc = new ThreadLocal<RequestContext>();
|
||||
|
||||
@@ -142,6 +146,7 @@ public class PublicApiClient
|
||||
siteMembershipRequests = new SiteMembershipRequests();
|
||||
groups = new Groups();
|
||||
rawProxy = new RawProxy();
|
||||
auditApps = new AuditApps();
|
||||
}
|
||||
|
||||
public void setRequestContext(RequestContext rc)
|
||||
@@ -209,6 +214,10 @@ public class PublicApiClient
|
||||
return groups;
|
||||
}
|
||||
|
||||
public AuditApps auditApps(){
|
||||
return auditApps;
|
||||
}
|
||||
|
||||
public CmisSession createPublicApiCMISSession(Binding binding, String version)
|
||||
{
|
||||
return createPublicApiCMISSession(binding, version, null);
|
||||
@@ -2424,4 +2433,26 @@ public class PublicApiClient
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class AuditApps extends AbstractProxy
|
||||
{
|
||||
|
||||
public ListResponse<AuditApp> getAuditApps(Map<String, String> params, String errorMessage, int expectedStatus) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("audit-applications", null, null, null, params, errorMessage, expectedStatus);
|
||||
|
||||
if (response != null && response.getJsonResponse() != null)
|
||||
{
|
||||
JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list");
|
||||
if (jsonList != null)
|
||||
{
|
||||
return AuditApp.parseAuditApps(response.getJsonResponse());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
/**
|
||||
* A representation of a Audit App in JUnit Test
|
||||
*
|
||||
* @author Andreea Nechifor
|
||||
*
|
||||
*/
|
||||
public class AuditApp extends org.alfresco.rest.api.model.AuditApp implements Serializable, ExpectedComparison
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void expected(Object o)
|
||||
{
|
||||
assertTrue("o is an instance of " + o.getClass(), o instanceof AuditApp);
|
||||
|
||||
AuditApp other = (AuditApp) o;
|
||||
|
||||
AssertUtil.assertEquals("id", getId(), other.getId());
|
||||
AssertUtil.assertEquals("name", getName(), other.getName());
|
||||
AssertUtil.assertEquals("isEnabled", getIsEnabled(), other.getIsEnabled());
|
||||
}
|
||||
|
||||
public JSONObject toJSON()
|
||||
{
|
||||
JSONObject auditAppJson = new JSONObject();
|
||||
if (getId() != null)
|
||||
{
|
||||
auditAppJson.put("id", getId());
|
||||
}
|
||||
|
||||
auditAppJson.put("name", getName());
|
||||
auditAppJson.put("isEnabled", getIsEnabled());
|
||||
|
||||
return auditAppJson;
|
||||
}
|
||||
|
||||
public static AuditApp parseAuditApp(JSONObject jsonObject)
|
||||
{
|
||||
String id = (String) jsonObject.get("id");
|
||||
String name = (String) jsonObject.get("name");
|
||||
Boolean isEnabled = (Boolean) jsonObject.get("isEnabled");
|
||||
|
||||
AuditApp auditApp = new AuditApp();
|
||||
auditApp.setId(id);
|
||||
auditApp.setName(name);
|
||||
auditApp.setIsEnabled(isEnabled);
|
||||
|
||||
return auditApp;
|
||||
}
|
||||
|
||||
public static ListResponse<AuditApp> parseAuditApps(JSONObject jsonObject)
|
||||
{
|
||||
List<AuditApp> groups = new ArrayList<>();
|
||||
|
||||
JSONObject jsonList = (JSONObject) jsonObject.get("list");
|
||||
assertNotNull(jsonList);
|
||||
|
||||
JSONArray jsonEntries = (JSONArray) jsonList.get("entries");
|
||||
assertNotNull(jsonEntries);
|
||||
|
||||
for (int i = 0; i < jsonEntries.size(); i++)
|
||||
{
|
||||
JSONObject jsonEntry = (JSONObject) jsonEntries.get(i);
|
||||
JSONObject entry = (JSONObject) jsonEntry.get("entry");
|
||||
groups.add(parseAuditApp(entry));
|
||||
}
|
||||
|
||||
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
|
||||
ListResponse<AuditApp> resp = new ListResponse<AuditApp>(paging, groups);
|
||||
return resp;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user