Search in sources :

Example 1 with ConfigurationSource

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

the class DefaultMailSenderConfigurationTest method getFromAddressWhenDefinedInXWikiPreferences.

@Test
public void getFromAddressWhenDefinedInXWikiPreferences() throws Exception {
    ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
    when(documentsSource.getProperty("admin_email", String.class)).thenReturn("john@doe.com");
    ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
    when(mailConfigDocumentSource.getProperty("from", "john@doe.com")).thenReturn("john@doe.com");
    assertEquals("john@doe.com", this.mocker.getComponentUnderTest().getFromAddress());
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Example 2 with ConfigurationSource

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

the class DefaultMailSenderConfigurationTest method getAdditionalPropertiesFromMailConfigDocument.

@Test
public void getAdditionalPropertiesFromMailConfigDocument() throws Exception {
    ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
    when(documentsSource.getProperty("javamail_extra_props", String.class)).thenReturn("key=value");
    ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
    when(mailConfigDocumentSource.getProperty("properties", "key=value")).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 3 with ConfigurationSource

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

the class DefaultMailSenderConfigurationTest method getAllProperties.

@Test
public void getAllProperties() throws Exception {
    ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
    when(mailConfigDocumentSource.getProperty("properties", (String) null)).thenReturn("mail.smtp.starttls.enable=true");
    when(mailConfigDocumentSource.getProperty("username", (String) null)).thenReturn(null);
    when(mailConfigDocumentSource.getProperty("password", (String) null)).thenReturn(null);
    when(mailConfigDocumentSource.getProperty("host", (String) null)).thenReturn("server");
    when(mailConfigDocumentSource.getProperty("port", Integer.class)).thenReturn(25);
    when(mailConfigDocumentSource.getProperty("from", (String) null)).thenReturn("john@doe.com");
    Properties returnedProperties = this.mocker.getComponentUnderTest().getAllProperties();
    assertEquals(5, returnedProperties.size());
    assertEquals("true", returnedProperties.getProperty("mail.smtp.starttls.enable"));
    assertEquals("server", returnedProperties.getProperty("mail.smtp.host"));
    assertEquals("25", returnedProperties.getProperty("mail.smtp.port"));
    assertEquals("smtp", returnedProperties.getProperty("mail.transport.protocol"));
    assertEquals("john@doe.com", returnedProperties.getProperty("mail.smtp.from"));
    assertNull(returnedProperties.getProperty("mail.smtp.user"));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with ConfigurationSource

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

the class DefaultMailSenderConfigurationTest method getAdditionalPropertiesWhenErrorInFormat.

@Test
public void getAdditionalPropertiesWhenErrorInFormat() throws Exception {
    ConfigurationSource documentsSource = this.mocker.getInstance(ConfigurationSource.class, "documents");
    when(documentsSource.getProperty("javamail_extra_props", String.class)).thenReturn("\\uinvalid");
    ConfigurationSource mailConfigDocumentSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
    when(mailConfigDocumentSource.getProperty("properties", "\\uinvalid")).thenReturn("\\uinvalid");
    assertTrue(this.mocker.getComponentUnderTest().getAdditionalProperties().isEmpty());
    // Verify the logs
    verify(this.mocker.getMockedLogger()).warn("Error while parsing mail properties [{}]. Root cause [{}]. Ignoring configuration...", "\\uinvalid", "IllegalArgumentException: Malformed \\uxxxx encoding.");
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Example 5 with ConfigurationSource

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

the class ActionFilter method getTargetURL.

/**
 * Compose a new URL path based on the original request and the specified action. The result is relative to the
 * application context, so that it can be used with {@link HttpServletRequest#getRequestDispatcher(String)}. For
 * example, calling this method with a request for <tt>/xwiki/bin/edit/Some/Document</tt> and <tt>action_save</tt>,
 * the result is <tt>/bin/save/Some/Document</tt>.
 *
 * @param request the original request
 * @param action the action parameter, starting with <tt>action_</tt>
 * @return The rebuilt URL path, with the specified action in place of the original Struts action. Note that unlike
 *         the HTTP path, this does not contain the application context part.
 */
private String getTargetURL(HttpServletRequest request, String action) {
    String newAction = PATH_SEPARATOR + action.substring(ACTION_PREFIX.length());
    // Extract the document name from the requested path. We don't use getPathInfo() since it is decoded
    // by the container, thus it will not work when XWiki uses a non-UTF-8 encoding.
    String path = request.getRequestURI();
    // First step, remove the context path, if any.
    path = XWiki.stripSegmentFromPath(path, request.getContextPath());
    // Second step, remove the servlet path, if any.
    String servletPath = request.getServletPath();
    path = XWiki.stripSegmentFromPath(path, servletPath);
    // Third step, remove the struts mapping. This step is mandatory, so this filter will fail if the
    // requested action was a hidden (default) 'view', like in '/bin/Main/'. This is OK, since forms
    // don't use 'view' as a target.
    int index = path.indexOf(PATH_SEPARATOR, 1);
    // We need to also get rid of the wiki name in case of a XEM in usepath mode
    ConfigurationSource configuration = Utils.getComponent(ConfigurationSource.class, XWikiCfgConfigurationSource.ROLEHINT);
    if ("1".equals(configuration.getProperty("xwiki.virtual.usepath", "1"))) {
        if (servletPath.equals(PATH_SEPARATOR + configuration.getProperty("xwiki.virtual.usepath.servletpath", "wiki"))) {
            // Move the wiki name together with the servlet path
            servletPath += path.substring(0, index);
            index = path.indexOf(PATH_SEPARATOR, index + 1);
        }
    }
    String document = path.substring(index);
    // Compose the target URL starting with the servlet path.
    return servletPath + newAction + document;
}
Also used : XWikiCfgConfigurationSource(com.xpn.xwiki.internal.XWikiCfgConfigurationSource) ConfigurationSource(org.xwiki.configuration.ConfigurationSource)

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