Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b52feee14df7af571d473e39d091513b93f571cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2007, 2013 David Green and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     David Green - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.wikitext.ant.internal;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Pattern;

import org.eclipse.mylyn.wikitext.ant.internal.MarkupToDocbookTask;


public class MarkupToDocbookTaskTest extends AbstractTestAntTask {

	private MarkupToDocbookTask task;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		task = new MarkupToDocbookTask();
		task.setMarkupLanguage(languageName);
	}

	public void testSimpleOutput() throws IOException {
		File markup = createSimpleTextileMarkup();
		task.setFile(markup);
		task.execute();

		listFiles();

		File docbookFile = new File(markup.getParentFile(), "markup.xml");
		assertTrue(docbookFile.exists() && docbookFile.isFile());

		String content = getContent(docbookFile);
//		

		assertTrue(content.contains("<book"));
		assertTrue(content.contains("</book>"));
		assertTrue(content.contains("<title>markup</title>"));
		assertTrue(Pattern.compile(
				"<chapter id=\"FirstHeading\">\\s*<title>First Heading</title>\\s*<para>some content</para>\\s*</chapter>",
				Pattern.MULTILINE)
				.matcher(content)
				.find());
		assertTrue(Pattern.compile(
				"<chapter id=\"SecondHeading\">\\s*<title>Second Heading</title>\\s*<para>some more content</para>\\s*</chapter>",
				Pattern.MULTILINE)
				.matcher(content)
				.find());

	}

	public void testSimpleOutputAlternateTitle() throws IOException {
		File markup = createSimpleTextileMarkup();
		task.setFile(markup);
		task.setBookTitle("Alternate Title");
		task.execute();

		listFiles();

		File docbookFile = new File(markup.getParentFile(), "markup.xml");
		assertTrue(docbookFile.exists() && docbookFile.isFile());

		String content = getContent(docbookFile);
//		

		assertTrue(content.contains("<book"));
		assertTrue(content.contains("</book>"));
		assertTrue(content.contains("<title>Alternate Title</title>"));
		assertTrue(Pattern.compile(
				"<chapter id=\"FirstHeading\">\\s*<title>First Heading</title>\\s*<para>some content</para>\\s*</chapter>",
				Pattern.MULTILINE)
				.matcher(content)
				.find());
		assertTrue(Pattern.compile(
				"<chapter id=\"SecondHeading\">\\s*<title>Second Heading</title>\\s*<para>some more content</para>\\s*</chapter>",
				Pattern.MULTILINE)
				.matcher(content)
				.find());

	}

	protected File createSimpleTextileMarkup() throws IOException {
		File markupFile = new File(tempFolder, "markup.textile");
		PrintWriter writer = new PrintWriter(new FileWriter(markupFile));
		try {
			writer.println("h1. First Heading");
			writer.println();
			writer.println("some content");
			writer.println();
			writer.println("h1. Second Heading");
			writer.println();
			writer.println("some more content");
		} finally {
			writer.close();
		}
		return markupFile;
	}

	public void testTaskdef() {
		assertEquals(MarkupToDocbookTask.class.getName(), loadTaskdefBundle().getString("wikitext-to-docbook"));
	}
}

Back to the top