mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2009-2013 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -24,6 +24,8 @@ import java.util.Map;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||
import org.alfresco.service.cmr.admin.RepoUsageStatus.RepoUsageLevel;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.license.LicenseDescriptor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
@@ -44,6 +46,7 @@ public abstract class AbstractAdminWebScript extends DeclarativeWebScript
|
||||
public static final String JSON_KEY_READ_ONLY = "readOnly";
|
||||
public static final String JSON_KEY_UPDATED = "updated";
|
||||
public static final String JSON_KEY_LICENSE_VALID_UNTIL = "licenseValidUntil";
|
||||
public static final String JSON_KEY_LICENSE_HOLDER = "licenseHolder";
|
||||
public static final String JSON_KEY_LEVEL = "level";
|
||||
public static final String JSON_KEY_WARNINGS = "warnings";
|
||||
public static final String JSON_KEY_ERRORS = "errors";
|
||||
@@ -54,6 +57,7 @@ public abstract class AbstractAdminWebScript extends DeclarativeWebScript
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
protected RepoAdminService repoAdminService;
|
||||
protected DescriptorService descriptorService;
|
||||
|
||||
/**
|
||||
* @param repoAdminService the service that provides the functionality
|
||||
@@ -63,6 +67,14 @@ public abstract class AbstractAdminWebScript extends DeclarativeWebScript
|
||||
this.repoAdminService = repoAdminService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param descriptorService the service that provides the functionality
|
||||
*/
|
||||
public void setDescriptorService(DescriptorService descriptorService)
|
||||
{
|
||||
this.descriptorService = descriptorService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an I18N'd message for the given key or the key itself if not present
|
||||
*
|
||||
@@ -88,7 +100,14 @@ public abstract class AbstractAdminWebScript extends DeclarativeWebScript
|
||||
model.put(JSON_KEY_READ_ONLY, repoUsage.isReadOnly());
|
||||
model.put(JSON_KEY_LICENSE_VALID_UNTIL, repoUsage.getLicenseExpiryDate());
|
||||
model.put(JSON_KEY_UPDATED, updated);
|
||||
|
||||
|
||||
// Add license holder
|
||||
LicenseDescriptor license = descriptorService.getLicenseDescriptor();
|
||||
if (license != null)
|
||||
{
|
||||
model.put(JSON_KEY_LICENSE_HOLDER, license.getHolderOrganisation());
|
||||
}
|
||||
|
||||
model.put(JSON_KEY_LEVEL, RepoUsageLevel.OK.ordinal());
|
||||
model.put(JSON_KEY_WARNINGS, Collections.emptyList());
|
||||
model.put(JSON_KEY_ERRORS, Collections.emptyList());
|
||||
|
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.admin;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.UsageType;
|
||||
import org.alfresco.service.cmr.admin.RepoUsageStatus;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.license.LicenseDescriptor;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* Test the admin web scripts
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.4
|
||||
*/
|
||||
public class AdminWebScriptTest extends BaseWebScriptTest
|
||||
{
|
||||
private ApplicationContext ctx;
|
||||
private RepoAdminService repoAdminService;
|
||||
private DescriptorService descriptorService;
|
||||
private String admin;
|
||||
private String guest;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
ctx = getServer().getApplicationContext();
|
||||
repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
|
||||
descriptorService = (DescriptorService) ctx.getBean("DescriptorService");
|
||||
admin = AuthenticationUtil.getAdminUserName();
|
||||
guest = AuthenticationUtil.getGuestUserName();
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testGetRestrictions() throws Exception
|
||||
{
|
||||
RepoUsage restrictions = repoAdminService.getRestrictions();
|
||||
|
||||
String url = "/api/admin/restrictions";
|
||||
TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
|
||||
|
||||
Response response = sendRequest(req, Status.STATUS_OK, guest);
|
||||
JSONObject json = new JSONObject(response.getContentAsString());
|
||||
Long maxUsers = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
|
||||
assertEquals("Mismatched max users", restrictions.getUsers(), maxUsers);
|
||||
Long maxDocuments = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
|
||||
assertEquals("Mismatched max documents", restrictions.getDocuments(), maxDocuments);
|
||||
}
|
||||
|
||||
public void testGetUsage() throws Exception
|
||||
{
|
||||
RepoUsageStatus usageStatus = repoAdminService.getUsageStatus();
|
||||
RepoUsage usage = usageStatus.getUsage();
|
||||
LicenseDescriptor licenseDescriptor = descriptorService.getLicenseDescriptor();
|
||||
Date validUntil = (licenseDescriptor == null) ? null : licenseDescriptor.getValidUntil(); // might be null
|
||||
Integer checkLevel = new Integer(usageStatus.getLevel().ordinal());
|
||||
|
||||
String url = "/api/admin/usage";
|
||||
TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
|
||||
|
||||
Response response = sendRequest(req, Status.STATUS_OK, guest);
|
||||
System.out.println(response.getContentAsString());
|
||||
JSONObject json = new JSONObject(response.getContentAsString());
|
||||
Long users = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
|
||||
assertEquals("Mismatched users", usage.getUsers(), users);
|
||||
Long documents = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
|
||||
assertEquals("Mismatched documents", usage.getDocuments(), documents);
|
||||
String licenseMode = json.isNull(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE) ? null : json.getString(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE);
|
||||
assertEquals("Mismatched licenseMode", usage.getLicenseMode().toString(), licenseMode);
|
||||
boolean readOnly = json.getBoolean(AbstractAdminWebScript.JSON_KEY_READ_ONLY);
|
||||
assertEquals("Mismatched readOnly", usage.isReadOnly(), readOnly);
|
||||
boolean updated = json.getBoolean(AbstractAdminWebScript.JSON_KEY_UPDATED);
|
||||
assertEquals("Mismatched updated", false, updated);
|
||||
Long licenseValidUntil = json.isNull(AbstractAdminWebScript.JSON_KEY_LICENSE_VALID_UNTIL) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_LICENSE_VALID_UNTIL);
|
||||
assertEquals("Mismatched licenseValidUntil",
|
||||
(validUntil == null) ? null : validUntil.getTime(),
|
||||
licenseValidUntil);
|
||||
Integer level = json.isNull(AbstractAdminWebScript.JSON_KEY_LEVEL) ? null : json.getInt(AbstractAdminWebScript.JSON_KEY_LEVEL);
|
||||
assertEquals("Mismatched level", checkLevel, level);
|
||||
json.getJSONArray(AbstractAdminWebScript.JSON_KEY_WARNINGS);
|
||||
json.getJSONArray(AbstractAdminWebScript.JSON_KEY_ERRORS);
|
||||
}
|
||||
|
||||
public void testUpdateUsageWithoutPermissions() throws Exception
|
||||
{
|
||||
String url = "/api/admin/usage";
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url, "", MimetypeMap.MIMETYPE_JSON);
|
||||
sendRequest(req, 401, AuthenticationUtil.getGuestRoleName());
|
||||
}
|
||||
|
||||
public void testUpdateUsage() throws Exception
|
||||
{
|
||||
repoAdminService.updateUsage(UsageType.USAGE_ALL);
|
||||
RepoUsage usage = repoAdminService.getUsage();
|
||||
|
||||
String url = "/api/admin/usage";
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url, "", MimetypeMap.MIMETYPE_JSON);
|
||||
|
||||
Response response = sendRequest(req, Status.STATUS_OK, admin);
|
||||
System.out.println(response.getContentAsString());
|
||||
JSONObject json = new JSONObject(response.getContentAsString());
|
||||
Long users = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
|
||||
assertEquals("Mismatched users", usage.getUsers(), users);
|
||||
Long documents = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
|
||||
assertEquals("Mismatched documents", usage.getDocuments(), documents);
|
||||
String licenseMode = json.isNull(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE) ? null : json.getString(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE);
|
||||
assertEquals("Mismatched licenseMode", usage.getLicenseMode().toString(), licenseMode);
|
||||
boolean readOnly = json.getBoolean(AbstractAdminWebScript.JSON_KEY_READ_ONLY);
|
||||
assertEquals("Mismatched readOnly", usage.isReadOnly(), readOnly);
|
||||
boolean updated = json.getBoolean(AbstractAdminWebScript.JSON_KEY_UPDATED);
|
||||
assertEquals("Mismatched updated", true, updated);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user