Skip to content

Commit

Permalink
Merge branch '118-goalsAsChildren' into 118-pluginsGoalsAschild-5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wattazoum committed Feb 15, 2017
2 parents 8e18e95 + 8f3a183 commit 54ac88f
Show file tree
Hide file tree
Showing 23 changed files with 1,042 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.*;

import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -77,17 +80,17 @@ protected String getHomePageTitle() {

return new java.io.ByteArrayInputStream( ser.toString().getBytes() );
}

/**
*
* @param uri
* @return
* @throws Exception
*/
public static <T> T processUri(
final java.net.URI uri,
final String homePageTitle,
final Func2<java.io.InputStream,Storage.Representation,T> onSuccess ) throws /*ProcessUri*/Exception
public static <T> T processUri(
final java.net.URI uri,
final String homePageTitle,
final Func2<java.io.InputStream,Storage.Representation,T> onSuccess ) throws /*ProcessUri*/Exception
{
if( uri == null ) {
throw new IllegalArgumentException( "uri is null!" );
Expand All @@ -108,7 +111,7 @@ public static <T> T processUri(
final boolean isStorage = (path !=null && (path.endsWith(".xml") || path.endsWith(".xhtml")));

final Storage.Representation representation = (isStorage) ? Storage.Representation.STORAGE : Storage.Representation.WIKI;

java.io.InputStream result = null;

if ("classpath".equalsIgnoreCase(scheme)) {
Expand Down Expand Up @@ -402,7 +405,73 @@ public boolean isIgnoreVariables() {
public void setIgnoreVariables(boolean value) {
this.ignoreVariables = value;
}



@XmlElement(name = "generated")
protected List<Generated> generateds;

/**
* Gets the value of the generateds property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the generateds property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getGenerateds().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Generated }
*
*
*/
public List<Page.Generated> getGenerateds() {
if (generateds == null) {
generateds = new ArrayList<Generated>();
}
return this.generateds;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public static class Generated {

@XmlAttribute(name = "ref")
protected String ref;

/**
* Obtient la valeur de la propriété ref.
*
* @return
* possible object is
* {@link String }
*
*/
public String getRef() {
return ref;
}

/**
* Définit la valeur de la propriété ref.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setRef(String value) {
this.ref = value;
}

}

}

public Site() {
Expand Down
75 changes: 75 additions & 0 deletions maven-confluence-plugin-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-confluence-parent</artifactId>
<groupId>org.bsc.maven</groupId>
<version>4.13-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>maven-confluence-plugin-test</artifactId>
<name>Integration testing project</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>

<dependencies>

<dependency>
<groupId>org.codehaus.swizzle</groupId>
<artifactId>swizzle-confluence</artifactId>
<version>1.6.1</version>

<exclusions>
<exclusion>
<groupId>xmlrpc</groupId>
<artifactId>xmlrpc</artifactId>
</exclusion>
<exclusion>
<artifactId>sisu-xmlrpc-client</artifactId>
<groupId>org.sonatype.sisu</groupId>
</exclusion>
</exclusions>

</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlrpc</groupId>
<artifactId>xmlrpc</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package org.bsc.maven.confluence.plugin;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
import org.apache.xmlrpc.WebServer;
import org.apache.xmlrpc.XmlRpc;
import org.codehaus.swizzle.confluence.Page;
import org.junit.*;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.File;
import java.io.IOException;
import java.util.*;

import static java.lang.String.format;
import static org.apache.maven.it.util.FileUtils.*;
import static org.apache.maven.it.util.ResourceExtractor.simpleExtractResources;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@SuppressWarnings("unchecked")
public class TemplateVariablesInPagesTest {

@SuppressWarnings("WeakerAccess")
public interface Handler {
Map<String, String> getPage(String tokken, String space, String page);
Map<String, Object> getServerInfo(String tokken);
List<?> getChildren(String tokken, String parentId);
String login(String username, String password);
boolean logout(String tokken);
Map<String, Object> storePage(String tokken, Hashtable<String, Object> page);
}

private static WebServer ws;
private Handler handler;

@BeforeClass
public static void createWebServer() {
ws = new WebServer( 19005 );
ws.start();
}

@AfterClass
public static void shutTheWebServerDown() {
ws.shutdown();
}

@Before
public void setUp() {
ws.removeHandler( "confluence1" );
handler = mock( Handler.class );
ws.addHandler( "confluence1", handler );
String tokken = "tokken";
when(handler.login("admin", "password")).thenReturn(tokken);
Map<String, Object> serverInfo = new Hashtable<String, Object>();
serverInfo.put("baseUrl", "http://localhost:19005");
when(handler.getServerInfo(tokken)).thenReturn(serverInfo);
when(handler.logout(tokken)).thenReturn(true);

when(handler.getChildren(tokken, "0")).thenReturn(new Vector());
String homePageName = "Hello Plugin";
when(handler.getChildren(tokken, DigestUtils.md5Hex(homePageName))).thenReturn(new Vector());

}

//@After
public void teardown() throws IOException {
String[] projects = new String[] {"simple-plugin-project"};
for (String project : projects) {
File file = ResourceExtractor.simpleExtractResources(getClass(), format("/%s/results", project));
if (file != null) deleteDirectory(file);
}
}

private Verifier testLaunchingMaven(File testBasedir, List<String> cliOptions, String... goals) throws IOException, VerificationException {
final String results = testBasedir.getAbsolutePath() + "/results";
mkdir(results);

final HashMap<String, Map> titleToPage = new HashMap<String, Map>();
Hashtable<String, String> homePage = new Hashtable<String, String>();
homePage.put("title", "Fake Root");
homePage.put("id", "0");
homePage.put("space", "DOC");
titleToPage.put("Fake Root", homePage);

when(handler.getPage(anyString(), anyString(), anyString())).then(new Answer<Hashtable>() {
@Override
public Hashtable answer(InvocationOnMock invocationOnMock) throws Throwable {
String title = (String)invocationOnMock.getArguments()[2];
if (titleToPage.containsKey(title)) {
return (Hashtable) titleToPage.get(title);
}
return new Hashtable();
}
});

when(handler.storePage(anyString(), any(Hashtable.class))).then(new Answer<Map<String,Object>>() {
@Override
public Map<String, Object> answer(InvocationOnMock invocationOnMock) throws Throwable {
Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
Map<String, String> pageMap = (Map) invocationOnMock.getArguments()[1];
hashtable.putAll(pageMap);
Page page = new Page(pageMap);

String parentId = page.getParentId();
if (parentId != null) {
String parentTitle = null;
for (Map map : titleToPage.values()) {
Page p = new Page(map);
if (parentId.equals(p.getId())) {
parentTitle = p.getTitle();
break;
}
}
if (parentTitle == null) {
throw new IllegalStateException(format("pageId '%s' not found", parentId));
}

fileWrite(results + "/" + parentTitle + "=>" + page.getTitle(), page.getContent());
} else {
fileWrite(results + "/" + page.getTitle(), page.getContent());
}

hashtable.put("id",DigestUtils.md5Hex(page.getTitle()));
hashtable.put("space", "DOC");
titleToPage.put(page.getTitle(), hashtable);
return hashtable;
}
});

when(handler.getChildren(anyString(), anyString())).then(new Answer<List>() {
@Override
public List answer(InvocationOnMock invocationOnMock) throws Throwable {
String parentPageId = (String)invocationOnMock.getArguments()[1];
Vector<Map> children = new Vector<Map>();
for (Map pageMap : titleToPage.values()) {
Page page = new Page(pageMap);
if (parentPageId.equals(page.getParentId())) {
children.add(pageMap);
}
}
return children;
}
});

Verifier verifier = new Verifier(testBasedir.getAbsolutePath());
verifier.deleteArtifact("sample.plugin", "hello-maven-plugin", "1.0-SNAPSHOT", "jar");

File settings = simpleExtractResources(TemplateVariablesInPagesTest.class, "/settings.xml");
cliOptions.add("-s");
cliOptions.add(settings.getAbsolutePath());
verifier.setCliOptions(cliOptions);
verifier.executeGoals(Arrays.asList(goals));
verifier.verifyErrorFreeLog();
verifier.resetStreams();
verifier.setDebug(true);
return verifier;
}

@Test
public void shouldRenderTheIndexPage() throws IOException, VerificationException, InterruptedException {
File testDir = simpleExtractResources(getClass(), "/simple-plugin-project");
testLaunchingMaven(testDir, new ArrayList<String>() {}, "clean", "package", "confluence-reporting:deploy");
assertTrue(fileExists(testDir.getAbsolutePath() + "/results/Fake Root=>Hello Plugin"));
assertTrue(fileExists(testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - Summary"));

String pluginGoalsPath = testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - Goals";
assertTrue(fileExists(pluginGoalsPath));
assertThat(fileRead(pluginGoalsPath), not(containsString("${plugin.goals}")));

String pluginsSummaryPath = testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - PluginsSummary";
assertTrue(fileExists(pluginsSummaryPath));
String pluginsSummary = fileRead(pluginsSummaryPath);
assertThat(pluginsSummary, not(containsString("${plugin.summary}")));
}

@Test
public void shouldPutTheGoalsAsChildrenOfGoalsPage() throws IOException, VerificationException, InterruptedException {
File testDir = simpleExtractResources(getClass(), "/plugin-project-goals-in-subpage");
testLaunchingMaven(testDir, new ArrayList<String>() {}, "clean", "package", "confluence-reporting:deploy");
assertTrue(fileExists(testDir.getAbsolutePath() + "/results/Fake Root=>Hello Plugin"));
String pluginGoalsPath = testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - Goals";
assertTrue(fileExists(pluginGoalsPath));

String pluginGoalhelpPath = testDir.getAbsolutePath() + "/results/Hello Plugin - Goals=>Hello Plugin - help";
assertTrue("help goal should be a subpage of Goals", fileExists(pluginGoalhelpPath));
String pluginGoaltouchPath = testDir.getAbsolutePath() + "/results/Hello Plugin - Goals=>Hello Plugin - touch";
assertTrue("touch goal should be a subpage of Goals", fileExists(pluginGoaltouchPath));

assertFalse("help goal should not be under the home page",
fileExists(testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - help"));
assertFalse("touch goal should not be under the home page",
fileExists(testDir.getAbsolutePath() + "/results/Hello Plugin=>Hello Plugin - touch"));
}
}
Loading

0 comments on commit 54ac88f

Please sign in to comment.