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));
}
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");
}
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;
}
});
}
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;
}
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;
}
Aggregations