From ac56441fc3acddadaae6f6c439f43525a659e820 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 12 Jun 2015 13:19:08 +0000 Subject: [PATCH] RM-2217 Allow null as a filter value. Also add a few unit tests for the file. +review RM-96 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106034 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../UserSecurityClearanceGet.java | 5 +- .../UserQueryParamsUnitTest.java | 78 +++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParamsUnitTest.java diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/UserSecurityClearanceGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/UserSecurityClearanceGet.java index c77897c093..9cc5282b82 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/UserSecurityClearanceGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/UserSecurityClearanceGet.java @@ -147,11 +147,12 @@ public class UserSecurityClearanceGet extends AbstractRmWebScript * Gets the name filter from the webscript request * * @param req {@link WebScriptRequest} The webscript request - * @return {@link String} The name filter (can be null) + * @return {@link String} The name filter from the request (or the empty string if the request doesn't contain one). */ private String getNameFilter(WebScriptRequest req) { - return req.getParameter(NAME_FILTER); + String nameFilter = req.getParameter(NAME_FILTER); + return (nameFilter != null ? nameFilter : ""); } /** diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParamsUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParamsUnitTest.java new file mode 100644 index 0000000000..1f0b19578a --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParamsUnitTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2005-2015 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.classification; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.alfresco.service.namespace.QName; +import org.junit.Test; + +/** + * Unit tests for the {@link UserQueryParams}. + * + * @author tpage + * @since 3.0 + */ +public class UserQueryParamsUnitTest +{ + private static final QName QNAME1 = QName.createQName("1"); + private static final QName QNAME2 = QName.createQName("2"); + + /** Check that the constructor escapes backslashes correctly. */ + @Test + public void testConstructor_backSlashes() + { + UserQueryParams userQueryParams = new UserQueryParams("\\Hello\\\\World!"); + assertEquals("\\\\Hello\\\\\\\\World!", userQueryParams.getSearchTerm()); + } + + /** Check that the constructor rejects null. */ + @Test(expected = IllegalArgumentException.class) + public void testConstructor_null() + { + new UserQueryParams(null); + } + + /** Check that providing two properties results in a list being returned. */ + @Test + public void testWithFilterProps_twoProperties() + { + UserQueryParams userQueryParams = new UserQueryParams("Search term"); + userQueryParams.withFilterProps(QNAME1, QNAME2); + assertEquals(Arrays.asList(QNAME1, QNAME2), userQueryParams.getFilterProps()); + } + + /** Check that the first parameter can't be null. */ + @Test(expected = IllegalArgumentException.class) + public void testWithFilterProps_firstPropertyNull() + { + UserQueryParams userQueryParams = new UserQueryParams("Search term"); + userQueryParams.withFilterProps(null); + } + + /** Check that providing a null after the first argument fails. */ + @Test(expected = IllegalArgumentException.class) + public void testWithFilterProps_containsNull() + { + UserQueryParams userQueryParams = new UserQueryParams("Search term"); + userQueryParams.withFilterProps(QNAME1, (QName) null); + } +}