Fix for issue blocking ACE-2932. This checkin means that the SolrFacetConfigAdmin{Post,Put} webscripts will accept both long and short-form qname strings.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@85991 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2014-09-30 11:42:55 +00:00
parent ca1c9b2d2a
commit e2dded6a18
5 changed files with 204 additions and 4 deletions

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2005-2014 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.facet;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
import org.junit.Test;
/**
* Unit tests for {@link FacetQNameUtils}.
* @since 5.0
*/
public class FacetQNameUtilsTest
{
/** A test-only namespace resolver. */
private final NamespacePrefixResolver resolver = new NamespacePrefixResolver()
{
private final List<String> uris = Arrays.asList(new String[] { "http://www.alfresco.org/model/foo/1.0" });
private final List<String> prefixes = Arrays.asList(new String[] { "foo" });
@Override public Collection<String> getURIs() { return this.uris; }
@Override public Collection<String> getPrefixes() { return this.prefixes; }
@Override public Collection<String> getPrefixes(String namespaceURI) throws NamespaceException
{
if (uris.contains(namespaceURI))
{ return prefixes; }
else
{ throw new NamespaceException("Unrecognised namespace: " + namespaceURI); }
}
@Override public String getNamespaceURI(String prefix) throws NamespaceException
{
if (prefixes.contains(prefix))
{ return "http://www.alfresco.org/model/foo/1.0"; }
else
{ throw new NamespaceException("Unrecognised prefix: " + prefix); }
}
};
@Test public void canCreateFromShortForm() throws Exception
{
assertEquals(QName.createQName("http://www.alfresco.org/model/foo/1.0", "localName"),
FacetQNameUtils.createQName("foo:localName", resolver));
}
@Test public void canCreateFromLongForm() throws Exception
{
assertEquals(QName.createQName("http://www.alfresco.org/model/foo/1.0", "localName"),
FacetQNameUtils.createQName("{http://www.alfresco.org/model/foo/1.0}localName", resolver));
}
// Note: it doesn't really make sense to have a short-form qname with no prefix.
@Test public void canCreateFromLongFormWithNoPrefix() throws Exception
{
assertEquals(QName.createQName(null, "localName"),
FacetQNameUtils.createQName("{}localName", resolver));
}
@Test public void canCreateLongFormQnameWithUnrecognisedUri() throws Exception
{
// Intentionally no validation of URIs against dictionary.
assertEquals(QName.createQName("http://www.alfresco.org/model/illegal/1.0", "localName"),
FacetQNameUtils.createQName("{http://www.alfresco.org/model/illegal/1.0}localName", resolver));
}
@Test (expected=NamespaceException.class)
public void shortFormQnameWithUnrecognisedPrefixFails() throws Exception
{
FacetQNameUtils.createQName("illegal:localName", resolver);
}
}

View File

@@ -35,14 +35,18 @@ import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.collections.CollectionUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
import org.springframework.extensions.webscripts.TestWebScriptServer.*;
/**
* This class tests the ReST API of the {@link SolrFacetService}.
@@ -504,7 +508,35 @@ public class FacetRestApiTest extends BaseWebScriptTest
}, SEARCH_ADMIN_USER);
}
/** The REST API should accept both 'cm:name' and '{http://www.alfresco.org/model/content/1.0}name' forms of filter IDs. */
public void testCreateFacetWithLongFormQnameFilterId() throws Exception
{
final JSONObject filter = new JSONObject();
final String filterName = "filter" + GUID.generate();
filters.add(filterName);
filter.put("filterID", filterName);
// This is the long-form qname that needs to be acceptable.
filter.put("facetQName", "{http://www.alfresco.org/model/content/1.0}testLongQname");
filter.put("displayName", "facet-menu.facet.testLongQname");
filter.put("displayControl", "alfresco/search/FacetFilters/testLongQname");
filter.put("maxFilters", 5);
filter.put("hitThreshold", 1);
filter.put("minFilterValueLength", 4);
filter.put("sortBy", "ALPHABETICALLY");
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
// Post the filter
sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 200);
return null;
}
}, SEARCH_ADMIN_USER);
}
public void testUpdateSingleValue() throws Exception
{
// Build the Filter object