Search in sources :

Example 31 with ConfigurationSource

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());
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Example 32 with ConfigurationSource

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());
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Example 33 with ConfigurationSource

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"));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Properties(java.util.Properties) Test(org.junit.Test)

Example 34 with ConfigurationSource

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));
}
Also used : XWikiCfgConfigurationSource(com.xpn.xwiki.internal.XWikiCfgConfigurationSource) ConfigurationSource(org.xwiki.configuration.ConfigurationSource) HashMap(java.util.HashMap) SpaceReference(org.xwiki.model.reference.SpaceReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WikiReference(org.xwiki.model.reference.WikiReference) Map(java.util.Map) HashMap(java.util.HashMap) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 35 with ConfigurationSource

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));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) CoreConfiguration(com.xpn.xwiki.CoreConfiguration) Syntax(org.xwiki.rendering.syntax.Syntax) Parser(org.xwiki.rendering.parser.Parser) Test(org.junit.Test)

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