Search in sources :

Example 16 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class XWikiRenderingConfigurationTest method getTransformationNames.

@Test
public void getTransformationNames() throws Exception {
    ConfigurationSource source = this.mocker.getInstance(ConfigurationSource.class);
    when(source.getProperty("rendering.transformations", Arrays.asList("macro", "icon"))).thenReturn(Arrays.asList("mytransformation"));
    List<String> txs = this.mocker.getComponentUnderTest().getTransformationNames();
    assertEquals(1, txs.size());
    assertEquals("mytransformation", txs.get(0));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Example 17 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class DefaultConfigurationSourceTest method containsKey.

@Test
public void containsKey() throws Exception {
    ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
    when(documentsSource.containsKey("key")).thenReturn(false);
    ConfigurationSource xwikiPropertiesSource = this.mocker.getInstance(ConfigurationSource.class, "xwikiproperties");
    when(xwikiPropertiesSource.containsKey("key")).thenReturn(true);
    assertTrue(this.mocker.getComponentUnderTest().containsKey("key"));
    // Verify that the order call is correct
    InOrder inOrder = inOrder(xwikiPropertiesSource, documentsSource);
    // First call
    inOrder.verify(documentsSource).containsKey("key");
    // Second call
    inOrder.verify(xwikiPropertiesSource).containsKey("key");
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 18 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class SpacesConfigurationSourceTest method before.

@Before
public void before() throws ComponentLookupException {
    this.xcontext = new XWikiContext();
    Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    ConfigurationSource spaceConfiguration = this.mocker.getInstance(ConfigurationSource.class, "space");
    when(spaceConfiguration.getProperty(any(), same(String.class))).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                return spacePreferences.get(invocation.getArgument(0));
            }
            return null;
        }
    });
    when(spaceConfiguration.getProperty(any())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                return spacePreferences.get(invocation.getArgument(0));
            }
            return null;
        }
    });
    when(spaceConfiguration.getProperty(any(), anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                String key = invocation.getArgument(0);
                if (spacePreferences.containsKey(key)) {
                    return spacePreferences.get(key);
                }
            }
            return invocation.getArgument(1);
        }
    });
    when(spaceConfiguration.containsKey(any())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                return spacePreferences.containsKey(invocation.getArgument(0));
            }
            return false;
        }
    });
    when(spaceConfiguration.getKeys()).then(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                return new ArrayList<>(spacePreferences.keySet());
            }
            return Collections.emptyList();
        }
    });
    when(spaceConfiguration.isEmpty()).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Map<String, String> spacePreferences = getSpacePreferences();
            if (spacePreferences != null) {
                return spacePreferences.isEmpty();
            }
            return true;
        }
    });
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) XWikiContext(com.xpn.xwiki.XWikiContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Before(org.junit.Before)

Example 19 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class CompositeWikiConfigurationSource method initializeWikiSources.

private synchronized List<ConfigurationSource> initializeWikiSources() {
    if (this.wikiInitialized) {
        return this.sources;
    }
    XWikiContext xcontext = this.xcontextProvider.get();
    // If context is not ready don't do anything
    if (xcontext == null) {
        return Collections.emptyList();
    }
    // Inject registered configuration sources
    List<ConfigurationSource> newSources = new ArrayList<>(this.sources.size() + this.wikiHints.size());
    for (String wikiHint : this.wikiHints) {
        try {
            newSources.add(this.componentManager.getInstance(ConfigurationSource.class, wikiHint));
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to lookup configuration source with hint [%s]. It won't be used.", wikiHint, e);
        }
    }
    this.sources = newSources;
    return this.sources;
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 20 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class AbstractApplicationContext method getConfiguredPermanentDirectory.

/**
 * @return the directory indicated in configuration, null if none is configured or if it's invalid
 * @throws ComponentLookupException error when trying to lookup {@link ConfigurationSource} component
 */
private File getConfiguredPermanentDirectory() throws ComponentLookupException {
    File directory = null;
    ConfigurationSource source = this.componentManager.getInstance(ConfigurationSource.class, "xwikiproperties");
    String directoryName = source.getProperty(PROPERTY_PERSISTENTDIRECTORY);
    if (directoryName != null) {
        directory = new File(directoryName);
        if (directory.exists()) {
            if (!directory.isDirectory()) {
                LOGGER.error("Configured permanent storage directory [{}] is not a directory", directory.getAbsolutePath());
                directory = null;
            } else if (!directory.canWrite()) {
                LOGGER.error("Configured permanent storage directory [{}] is not writable", directory.getAbsolutePath());
                directory = null;
            }
        } else {
            directory.mkdirs();
        }
    }
    return directory;
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) File(java.io.File)

Aggregations

ConfigurationSource (org.xwiki.configuration.ConfigurationSource)42 Test (org.junit.Test)29 Properties (java.util.Properties)7 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 XWikiCfgConfigurationSource (com.xpn.xwiki.internal.XWikiCfgConfigurationSource)3 ArrayList (java.util.ArrayList)3 Expectations (org.jmock.Expectations)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Parser (org.xwiki.rendering.parser.Parser)3 Syntax (org.xwiki.rendering.syntax.Syntax)3 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)3 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)3 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)2 File (java.io.File)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2