blob: fff3efc064a3553310bf61e7115e10b7a02348cd (
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
|
/*******************************************************************************
* Copyright (c) 2007, 2016 IBM Corporation and others.
*
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.other;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.IUAElement;
import org.eclipse.help.internal.context.Context;
import org.eclipse.ua.tests.help.util.DocumentCreator;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class ContextMergeTest {
private static final String ENABLEMENT_CHEATSHEETS = "<enablement><with variable=\"platform\">" +
"<test property=\"org.eclipse.core.runtime.isBundleInstalled\" args=\"org.eclipse.ui.cheatsheets\"/>" +
"</with></enablement>";
private static final String TOPIC_END = "</topic>";
private static final String TOPIC_HEAD_ECLIPSE = "<topic href=\"http://www.eclipse.org\" label=\"enabled\">";
private static final String CONTEXT_DESCRIPTION = "<description>Context Description</description>";
private static final String CONTEXT_HEAD = "<context id=\"viewer\" title=\"Sample View\">";
private final String TOPIC_ECLIPSE = "<topic href=\"http://www.eclipse.org\" label=\"eclipse\"/>";
private final String TOPIC_BUGZILLA = "<topic href=\"http://www.eclipse.org/bugzilla\" label=\"bugzilla\"/>";
private final String TOPIC_WITH_ENABLEMENT = TOPIC_HEAD_ECLIPSE + ENABLEMENT_CHEATSHEETS + TOPIC_END;
private final String END_CONTEXT = "</context>";
private Context createContext(final String contextSource) {
Context context;
Document doc;
try {
doc = DocumentCreator.createDocument(contextSource);
} catch (Exception e) {
fail("Caught Exception");
doc = null;
}
context = new Context((Element) doc.getFirstChild());
return context;
}
@Test
public void testContextMerge() {
final String contextSource1 = CONTEXT_HEAD +
CONTEXT_DESCRIPTION +
TOPIC_ECLIPSE +
TOPIC_WITH_ENABLEMENT +
END_CONTEXT;
final String contextSource2 = CONTEXT_HEAD +
CONTEXT_DESCRIPTION +
TOPIC_BUGZILLA +
END_CONTEXT;
Context context1;
Context context2;
context1 = createContext(contextSource1);
context2 = createContext(contextSource2);
context1.mergeContext(context2);
assertEquals("Sample View", context1.getTitle());
assertEquals("Context Description", context1.getText());
assertEquals("viewer", context1.getId());
IHelpResource[] related = context1.getRelatedTopics();
assertEquals(3, related.length);
assertEquals("eclipse", related[0].getLabel());
assertEquals("enabled", related[1].getLabel());
assertEquals("bugzilla", related[2].getLabel());
assertTrue(related[0] instanceof IUAElement);
IUAElement topic = (IUAElement)related[1];
IUAElement[] topicChildren = topic.getChildren();
assertEquals(1, topicChildren.length);
}
}
|