Commits

Vincent Choy [Atlassian] committed 72717bf

Initial Default integration test project crated by AMPS

Comments (0)

Files changed (9)

+.idea
+*.iml
+*.ipr
+*.iws
+*.log
+*.pyc
+*.tags
+*target/
+*~
+.DS_Store
+.svn
+tags
+.settings
+.project
+.classpath
+Copyright (c) 2011, Atlassian Pty Ltd
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of Atlassian nor the names of its contributors may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+
+You can find the full instructions for this tutorial here:
+
+https://developer.atlassian.com/display/CONFDEV/Plugin+Tutorial+-+Writing+Integration+Tests+for+your+Plugin
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.atlassian.tutorial.confluence.plugin.integrationtesting</groupId>
+    <artifactId>confluence-integrationtesting-plugin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <organization>
+        <name>Example Company</name>
+        <url>http://www.example.com/</url>
+    </organization>
+
+    <name>confluence-integrationtesting-plugin</name>
+    <description>This is the com.atlassian.tutorial.confluence.plugin.integrationtesting:confluence-integrationtesting-plugin plugin for Atlassian Confluence.</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.6</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.confluence</groupId>
+            <artifactId>confluence</artifactId>
+            <version>${confluence.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.confluence.plugin</groupId>
+            <artifactId>func-test</artifactId>
+            <version>2.3</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.jwebunit</groupId>
+            <artifactId>jwebunit-htmlunit-plugin</artifactId>
+            <version>2.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.nekohtml</groupId>
+            <artifactId>nekohtml</artifactId>
+            <version>1.9.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-confluence-plugin</artifactId>
+                <version>${amps.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${confluence.version}</productVersion>
+                    <productDataVersion>${confluence.data.version}</productDataVersion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <confluence.version>4.1.6</confluence.version>
+        <confluence.data.version>3.5</confluence.data.version>
+        <amps.version>3.11</amps.version>
+    </properties>
+
+</project>

src/main/java/com/atlassian/tutorial/confluence/plugin/integrationtesting/ExampleMacro.java

+package com.atlassian.tutorial.confluence.plugin.integrationtesting;
+
+import java.util.Map;
+import java.util.List;
+
+import com.atlassian.confluence.content.render.xhtml.ConversionContext;
+import com.atlassian.confluence.macro.Macro;
+import com.atlassian.confluence.macro.MacroExecutionException;
+import com.atlassian.confluence.pages.PageManager;
+import com.atlassian.confluence.pages.Page;
+import com.atlassian.confluence.spaces.SpaceManager;
+import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
+import com.atlassian.user.User;
+import com.opensymphony.util.TextUtils;
+
+/**
+ * This very simple macro shows you the very basic use-case of displaying *something* on the Confluence page where it is used.
+ * Use this example macro to toy around, and then quickly move on to the next example - this macro doesn't
+ * really show you all the fun stuff you can do with Confluence.
+ */
+public class ExampleMacro implements Macro
+{
+
+    // We just have to define the variables and the setters, then Spring injects the correct objects for us to use. Simple and efficient.
+    // You just need to know *what* you want to inject and use.
+
+    private final PageManager pageManager;
+    private final SpaceManager spaceManager;
+
+    public ExampleMacro(PageManager pageManager, SpaceManager spaceManager)
+    {
+        this.pageManager = pageManager;
+        this.spaceManager = spaceManager;
+    }
+
+    /**
+     * This method returns XHTML to be displayed on the page that uses this macro
+     * we just do random stuff here, trying to show how you can access the most basic
+     * managers and model objects. No emphasis is put on beauty of code nor on
+     * doing actually useful things :-)
+     */
+    @Override
+    public String execute(Map<String, String> parameters, String body, ConversionContext context) throws MacroExecutionException
+    {
+        // in this most simple example, we build the result in memory, appending HTML code to it at will.
+        // this is something you absolutely don't want to do once you start writing plugins for real. Refer
+        // to the next example for better ways to render content.
+        StringBuffer result = new StringBuffer();
+
+        // get the currently logged in user and display his name
+        User user = AuthenticatedUserThreadLocal.getUser();
+        if (user != null)
+        {
+            String greeting = "<p>Hello <b>" + TextUtils.htmlEncode(user.getFullName()) + "</b>.</p>";
+            result.append(greeting);
+        }
+
+        //get the pages added in the last 55 days to the DS space ("Demo Space"), and display them
+        List<Page> list = pageManager.getRecentlyAddedPages(55, "DS");
+        result.append("<p>");
+        result.append("Some stats for <b>Demonstration Space</b>:");
+        result.append("<table class=\"confluenceTable\">");
+        result.append("<thead><tr><th class=\"confluenceTh\">Page</th><th class=\"confluenceTh\">Number of children</th></tr></thead>");
+        result.append("<tbody>");
+        for (Page page : list)
+        {
+            int numberOfChildren = page.getChildren().size();
+            String pageWithChildren = "<tr><td class=\"confluenceTd\">" + TextUtils.htmlEncode(page.getTitle()) + "</td><td class=\"confluenceTd\" style=\"text-align:right\">" + numberOfChildren + "</td></tr>";
+            result.append(pageWithChildren);
+        }
+        result.append("</tbody>");
+        result.append("</table>");
+        result.append("</p>");
+
+        // and show the number of all spaces in this installation.
+        String spaces = "<p>Altogether, this installation has <b>" + spaceManager.getAllSpaces().size() + "</b> spaces.</p>";
+        result.append(spaces);
+
+        // this concludes our little demo. Now you should understand the basics of code injection use in Confluence, and how
+        // to get a really simple macro running.
+
+        return result.toString();
+    }
+
+    @Override
+    public BodyType getBodyType()
+    {
+        return BodyType.NONE;
+    }
+
+    @Override
+    public OutputType getOutputType()
+    {
+        return OutputType.BLOCK;
+    }
+
+}

src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}" />
+    </plugin-info>
+
+    <xhtml-macro name="confluence-integrationtesting-plugin" class="com.atlassian.tutorial.confluence.plugin.integrationtesting.ExampleMacro" key="my-macro">
+        <parameters/>
+    </xhtml-macro>
+</atlassian-plugin>

src/test/java/com/atlassian/tutorial/confluence/plugin/integrationtesting/ExampleMacroTest.java

+package com.atlassian.tutorial.confluence.plugin.integrationtesting;
+
+import org.junit.Test;
+
+/**
+ * Testing {@link com.atlassian.tutorial.confluence.plugin.integrationtesting.ExampleMacro}
+ */
+public class ExampleMacroTest
+{
+    @Test
+    public void basic()
+    {
+        // add test here...
+    }
+}

src/test/java/it/AbstractIntegrationTestCase.java

+package it;
+
+import com.atlassian.confluence.plugin.functest.AbstractConfluencePluginWebTestCase;
+import com.atlassian.confluence.plugin.functest.JWebUnitConfluenceWebTester;
+import com.atlassian.confluence.plugin.functest.TesterConfiguration;
+import junit.framework.Assert;
+
+import java.io.IOException;
+import java.util.Properties;
+
+public class AbstractIntegrationTestCase extends AbstractConfluencePluginWebTestCase
+{
+    @Override
+    protected JWebUnitConfluenceWebTester createConfluenceWebTester()
+    {
+        Properties props = new Properties();
+        props.put("confluence.webapp.protocol", "http");
+        props.put("confluence.webapp.host", "localhost");
+
+        // this is deceiving: the func test library checks for the system properties
+        // *before* checking in this properties file for these values, so these
+        // properties are technically ignored
+        props.put("confluence.webapp.port", Integer.parseInt(System.getProperty("http.port")));
+        props.put("confluence.webapp.context.path", System.getProperty("context.path"));
+
+        props.put("confluence.auth.admin.username", "admin");
+        props.put("confluence.auth.admin.password", "admin");
+
+        TesterConfiguration conf;
+        try
+        {
+            conf = new TesterConfiguration(props);
+        }
+        catch (IOException ioe)
+        {
+            Assert.fail("Unable to create tester: " + ioe.getMessage());
+            return null;
+        }
+
+        JWebUnitConfluenceWebTester tester = new JWebUnitConfluenceWebTester(conf);
+
+        tester.getTestContext().setBaseUrl(tester.getBaseUrl());
+        tester.setScriptingEnabled(false);
+
+        return tester;
+    }
+}

src/test/java/it/IntegrationTestMyPlugin.java

+package it;
+
+public class IntegrationTestMyPlugin extends AbstractIntegrationTestCase
+{
+	public void testSomething()
+	{
+        gotoPage("");
+        assertTextPresent("Welcome");
+	}
+}