Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 51b15db3cfd9dc6a6f20c63f9420ecfb72facd13 (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
/*******************************************************************************
 * Copyright (c) 2006, 2016 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ua.tests.help.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.toc.TocFile;
import org.eclipse.help.ui.internal.HelpUIPlugin;
import org.junit.Before;
import org.junit.Test;

/*
 * A utility for regenerating the _expected.txt files that contain the expected
 * result for the TOC model when serialized. This reads all the TOC content from
 * the plugin manifest (for this test plugin only), constructs the model, then
 * serializes the model to a text file, which is stored in the same directory as the
 * TOC xml file, as <original_name>_expected.txt.
 *
 * These files are used by the JUnit tests to compare the result with the expected
 * result.
 *
 * Usage:
 *
 * 1. Run this test as a JUnit plug-in test.
 * 2. Right-click in "Package Explorer -> Refresh".
 *
 * The new files should appear.
 */
public class TocModelSerializerTest {

	/*
	 * Ensure that org.eclipse.help.ui is started. It contributes extra content
	 * filtering that is used by this test. See UIContentFilterProcessor.
	 */
	@Before
	public void setUp() throws Exception {
		HelpUIPlugin.getDefault();
	}

	@Test
	public void testRunSerializer() throws IOException {
		/*
		Collection tocFiles = getTocFiles();
		TocBuilder builder = new TocBuilder();
		builder.build(tocFiles);
		Collection builtTocs = builder.getBuiltTocs();

		Iterator iter = builtTocs.iterator();
		while (iter.hasNext()) {
			Toc toc = (Toc)iter.next();
			TocFile file = toc.getTocFile();

			String pluginRoot = UserAssistanceTestPlugin.getDefault().getBundle().getLocation().substring("update@".length());
			String relativePath = file.getHref();
			String absolutePath = pluginRoot + relativePath;
			String resultFile = FileUtil.getResultFile(absolutePath);

			PrintWriter out = new PrintWriter(new FileOutputStream(resultFile));
			out.print(TocModelSerializer.serialize(toc));
			out.close();
		}
		*/
	}

	/**
	 * Find all the TOC files to use for this test.
	 */
	public static Collection<TocFile> getTocFiles() {
		Collection<TocFile> tocFiles = new ArrayList<TocFile>();
		IExtensionPoint xpt = Platform.getExtensionRegistry().getExtensionPoint(HelpPlugin.PLUGIN_ID, "toc");
		IExtension[] extensions = xpt.getExtensions();
		for (IExtension extension : extensions) {
			String pluginId = extension.getContributor().getName();
			if (pluginId.equals("org.eclipse.ua.tests")) {
				IConfigurationElement[] configElements = extension.getConfigurationElements();
				for (IConfigurationElement configElement : configElements) {
					if (configElement.getName().equals("toc")) {
						// only get files in data/help/toc/
						String href = configElement.getAttribute("file"); //$NON-NLS-1$
						if (href.startsWith("data/help/toc/")) {
							boolean isPrimary = "true".equals(configElement.getAttribute("primary")); //$NON-NLS-1$
							String extraDir = configElement.getAttribute("extradir"); //$NON-NLS-1$
							String categoryId = configElement.getAttribute("category"); //$NON-NLS-1$
							tocFiles.add(new TocFile(pluginId, href, isPrimary, Platform.getNL(), extraDir, categoryId));
						}
					}
				}
			}
		}
		return tocFiles;
	}
}

Back to the top