use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.
the class DefaultMailSenderConfigurationTest method usesAuthenticationWhenUserNameAndPasswordExist.
@Test
public void usesAuthenticationWhenUserNameAndPasswordExist() throws Exception {
ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
when(mailConfigDocumentSource.getProperty("username", (String) null)).thenReturn("user");
when(mailConfigDocumentSource.getProperty("password", (String) null)).thenReturn("pass");
assertTrue(this.mocker.getComponentUnderTest().usesAuthentication());
}
use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.
the class DefaultMailSenderConfigurationTest method getFromAddressWhenDefinedInXWikiProperties.
@Test
public void getFromAddressWhenDefinedInXWikiProperties() throws Exception {
ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
when(documentsSource.getProperty("admin_email", String.class)).thenReturn(null);
ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
when(mailConfigDocumentSource.getProperty("from", null)).thenReturn(null);
ConfigurationSource xwikiPropertiesSource = this.mocker.getInstance(ConfigurationSource.class, "xwikiproperties");
when(xwikiPropertiesSource.getProperty("mail.sender.from", String.class)).thenReturn("john@doe.com");
assertEquals("john@doe.com", this.mocker.getComponentUnderTest().getFromAddress());
}
use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.
the class DefaultMailSenderConfigurationTest method getAdditionalPropertiesFromXWikiPreferences.
@Test
public void getAdditionalPropertiesFromXWikiPreferences() throws Exception {
ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
when(documentsSource.getProperty("javamail_extra_props", String.class)).thenReturn("key1=value1\nkey2=value2");
ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
when(mailConfigDocumentSource.getProperty("properties", "key1=value1\nkey2=value2")).thenReturn("key1=value1\nkey2=value2");
Properties properties = this.mocker.getComponentUnderTest().getAdditionalProperties();
assertEquals("value1", properties.getProperty("key1"));
assertEquals("value2", properties.getProperty("key2"));
}
use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getSpacePreference.
@Test
public void getSpacePreference() throws Exception {
this.mocker.registerMockComponent(ConfigurationSource.class, "wiki");
ConfigurationSource spaceConfiguration = this.mocker.registerMockComponent(ConfigurationSource.class, "space");
when(this.xwikiCfgConfigurationSource.getProperty(any(), anyString())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(1);
}
});
WikiReference wikiReference = new WikiReference("wiki");
SpaceReference space1Reference = new SpaceReference("space1", wikiReference);
SpaceReference space2Reference = new SpaceReference("space2", space1Reference);
// Without preferences and current doc
assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
// Without preferences but with current doc
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));
assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
// With preferences
final Map<String, Map<String, String>> spacesPreferences = new HashMap<>();
Map<String, String> space1Preferences = new HashMap<>();
space1Preferences.put("pref", "prefvalue1");
space1Preferences.put("pref1", "pref1value1");
Map<String, String> space2Preferences = new HashMap<>();
space2Preferences.put("pref", "prefvalue2");
space2Preferences.put("pref2", "pref2value2");
spacesPreferences.put(space1Reference.getName(), space1Preferences);
spacesPreferences.put(space2Reference.getName(), space2Preferences);
when(spaceConfiguration.getProperty(any(), same(String.class))).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
if (context.getDoc() != null) {
Map<String, String> spacePreferences = spacesPreferences.get(context.getDoc().getDocumentReference().getParent().getName());
if (spacePreferences != null) {
return spacePreferences.get(invocation.getArgument(0));
}
}
return null;
}
});
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space1Reference)));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref2", this.context));
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
assertEquals("pref2value2", this.xwiki.getSpacePreference("pref2", this.context));
assertEquals("", this.xwiki.getSpacePreference("nopref", space1Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("nopref", space1Reference, "defaultvalue", this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", space1Reference, this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", space1Reference, "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", space1Reference, this.context));
assertEquals("", this.xwiki.getSpacePreference("pref2", space1Reference, this.context));
assertEquals("", this.xwiki.getSpacePreference("nopref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("nopref", space2Reference, "defaultvalue", this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", space2Reference, this.context));
assertEquals("pref2value2", this.xwiki.getSpacePreference("pref2", space2Reference, this.context));
}
use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.
the class DefaultExtendedRenderingConfigurationTest method getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndNoXWikiCfgProperty.
@Test
public void getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndNoXWikiCfgProperty() throws Exception {
ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(null);
ConfigurationSource xwikiCfgSource = this.mocker.getInstance(ConfigurationSource.class, "xwikicfg");
when(xwikiCfgSource.getProperty("xwiki.rendering.syntaxes", List.class)).thenReturn(null);
CoreConfiguration coreConfiguration = this.mocker.getInstance(CoreConfiguration.class);
Syntax defaultSyntax = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.1");
when(coreConfiguration.getDefaultDocumentSyntax()).thenReturn(defaultSyntax);
// Register some Syntaxes for the test
Parser defaultSyntaxParser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.1");
when(defaultSyntaxParser.getSyntax()).thenReturn(defaultSyntax);
Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
when(syntax1Parser.getSyntax()).thenReturn(syntax1);
Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
when(syntax2Parser.getSyntax()).thenReturn(syntax2);
List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
assertEquals(2, disabledSyntaxes.size());
assertTrue(disabledSyntaxes.contains(syntax1));
assertTrue(disabledSyntaxes.contains(syntax2));
List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
assertEquals(1, configuredSyntaxes.size());
assertTrue(configuredSyntaxes.contains(defaultSyntax));
}
Aggregations