Skip to content
Snippets Groups Projects
Commit 250d8d62 authored by Jean-Vincent Drean's avatar Jean-Vincent Drean
Browse files

XWIKI-7686 : Spaces preferences can't be retrieved through the configuration component

parent 73545cfe
No related merge requests found
......@@ -169,7 +169,7 @@ private DocumentReference getFailsafeClassReference()
DocumentReference classReference;
try {
classReference = getDocumentReference();
classReference = getClassReference();
} catch (Exception e) {
// We verify that no error has happened and if one happened then we skip this configuration source. This
// ensures the system will continue to work even if this source has a problem.
......
......@@ -23,9 +23,11 @@
import org.junit.Assert;
import org.junit.Test;
import org.xwiki.bridge.DocumentAccessBridge;
import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.model.ModelContext;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.test.AbstractComponentTestCase;
import org.xwiki.model.reference.WikiReference;
import org.xwiki.test.AbstractMockingComponentTestCase;
import org.xwiki.test.annotation.MockingRequirement;
/**
* Unit tests for {@link org.xwiki.configuration.internal.SpacePreferencesConfigurationSource}.
......@@ -33,33 +35,30 @@
* @version $Id$
* @since 2.4M2
*/
public class SpacePreferencesConfigurationSourceTest extends AbstractComponentTestCase
public class SpacePreferencesConfigurationSourceTest extends AbstractMockingComponentTestCase
{
private DocumentAccessBridge bridge;
@Override
protected void registerComponents() throws Exception
{
super.registerComponents();
this.bridge = registerMockComponent(DocumentAccessBridge.class);
}
@MockingRequirement
private SpacePreferencesConfigurationSource source;
@Test
public void testGetPropertyForStringWhenExists() throws Exception
public void getPropertyForStringWhenExists() throws Exception
{
ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class, "space");
final DocumentReference webPreferencesReference = new DocumentReference("wiki", "space", "WebPreferences");
final DocumentReference xwikiPreferencesReference = new DocumentReference("wiki", "XWiki", "XWikiPreferences");
final DocumentReference currentDocument = new DocumentReference("wiki", "space", "page");
final DocumentAccessBridge dab = getComponentManager().lookupComponent(DocumentAccessBridge.class);
final ModelContext modelContext = getComponentManager().lookupComponent(ModelContext.class);
getMockery().checking(new Expectations() {{
allowing(bridge).getCurrentDocumentReference();
allowing(dab).getCurrentDocumentReference();
will(returnValue(currentDocument));
oneOf(bridge).getProperty(webPreferencesReference, webPreferencesReference, "key");
allowing(modelContext).getCurrentEntityReference();
will(returnValue(new WikiReference("wiki")));
oneOf(dab).getProperty(webPreferencesReference, xwikiPreferencesReference, "key");
will(returnValue("value"));
}});
String result = source.getProperty("key", String.class);
String result = this.source.getProperty("key", String.class);
Assert.assertEquals("value", result);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment