-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '118-goalsAsChildren' into 118-pluginsGoalsAschild-5.0
- Loading branch information
Showing
23 changed files
with
1,042 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
204 changes: 204 additions & 0 deletions
204
...ugin-test/src/test/java/org/bsc/maven/confluence/plugin/TemplateVariablesInPagesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
Oops, something went wrong.