Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ua.tests.cheatsheet.other; |
13 |
|
14 |
import java.util.Set; |
15 |
|
16 |
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; |
17 |
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; |
18 |
|
19 |
import junit.framework.TestCase; |
20 |
|
21 |
public class TestCheatSheetManager extends TestCase { |
22 |
|
23 |
private static final String CHEATSHEET_ID = "RandomId0234"; |
24 |
private static final String CHEATSHEET_NAME = "Name"; |
25 |
private static final String KEY1 = "key1"; |
26 |
private static final String PARENT_KEY1 = "parent.key1"; |
27 |
private static final String PARENT_KEY2 = "parent.key2"; |
28 |
private static final String VALUE_A = "A"; |
29 |
private static final String VALUE_B = "B"; |
30 |
private static final String VALUE_C = "C"; |
31 |
|
32 |
public CheatSheetManager createManager() { |
33 |
CheatSheetElement element = new CheatSheetElement(CHEATSHEET_NAME); |
34 |
element.setID(CHEATSHEET_ID); |
35 |
return new CheatSheetManager(element); |
36 |
} |
37 |
|
38 |
/** |
39 |
* Test for correct initialization |
40 |
*/ |
41 |
public void testNewManager() { |
42 |
CheatSheetManager manager = createManager(); |
43 |
assertNotNull(manager.getKeySet()); |
44 |
assertTrue(manager.getKeySet().isEmpty()); |
45 |
assertEquals(CHEATSHEET_ID, manager.getCheatSheetID()); |
46 |
} |
47 |
|
48 |
/** |
49 |
* Test that if there is no parent all references are local. |
50 |
*/ |
51 |
public void testNoParent() { |
52 |
CheatSheetManager manager = createManager(); |
53 |
manager.setDataQualified(KEY1, VALUE_A); |
54 |
manager.setDataQualified(PARENT_KEY1, VALUE_B); |
55 |
assertEquals(VALUE_A, manager.getData(KEY1)); |
56 |
assertEquals(VALUE_A, manager.getDataQualified(KEY1)); |
57 |
assertEquals(VALUE_B, manager.getData(PARENT_KEY1)); |
58 |
assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1)); |
59 |
Set keys = manager.getKeySet(); |
60 |
assertEquals(keys.size(), 2); |
61 |
assertTrue(keys.contains(KEY1)); |
62 |
assertTrue(keys.contains(PARENT_KEY1)); |
63 |
} |
64 |
|
65 |
/** |
66 |
* Test that if there is a parent getDataQualified and setDataQualified |
67 |
* can reference the parent but getData is always local |
68 |
*/ |
69 |
public void testParentAccess() { |
70 |
CheatSheetManager manager = createManager(); |
71 |
CheatSheetManager parentManager = createManager(); |
72 |
manager.setParent(parentManager); |
73 |
manager.setDataQualified(KEY1, VALUE_A); |
74 |
manager.setDataQualified(PARENT_KEY1, VALUE_B); |
75 |
assertEquals(VALUE_A, manager.getData(KEY1)); |
76 |
assertEquals(VALUE_A, manager.getDataQualified(KEY1)); |
77 |
assertNull(manager.getData(PARENT_KEY1)); |
78 |
assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1)); |
79 |
Set keys = manager.getKeySet(); |
80 |
assertEquals(keys.size(), 1); |
81 |
assertTrue(keys.contains(KEY1)); |
82 |
assertFalse(keys.contains(PARENT_KEY1)); |
83 |
|
84 |
Set parentKeys = parentManager.getKeySet(); |
85 |
assertEquals(parentKeys.size(), 1); |
86 |
assertTrue(parentKeys.contains(KEY1)); |
87 |
assertFalse(parentKeys.contains(PARENT_KEY1)); |
88 |
} |
89 |
|
90 |
/** |
91 |
* Test that setData always writes locally |
92 |
*/ |
93 |
public void testSetDataWithParent() { |
94 |
CheatSheetManager manager = createManager(); |
95 |
CheatSheetManager parentManager = createManager(); |
96 |
manager.setParent(parentManager); |
97 |
manager.setData(KEY1, VALUE_A); |
98 |
manager.setData(PARENT_KEY1, VALUE_B); |
99 |
assertEquals(VALUE_A, manager.getData(KEY1)); |
100 |
assertEquals(VALUE_A, manager.getDataQualified(KEY1)); |
101 |
assertNull(manager.getDataQualified(PARENT_KEY1)); |
102 |
assertEquals(VALUE_B, manager.getData(PARENT_KEY1)); |
103 |
Set keys = manager.getKeySet(); |
104 |
assertEquals(keys.size(), 2); |
105 |
assertTrue(keys.contains(KEY1)); |
106 |
assertTrue(keys.contains(PARENT_KEY1)); |
107 |
|
108 |
Set parentKeys = parentManager.getKeySet(); |
109 |
assertEquals(parentKeys.size(), 0); |
110 |
} |
111 |
|
112 |
public void testSubstitution() { |
113 |
CheatSheetManager manager = createManager(); |
114 |
CheatSheetManager parentManager = createManager(); |
115 |
manager.setParent(parentManager); |
116 |
manager.setDataQualified(KEY1, VALUE_A); |
117 |
manager.setDataQualified(PARENT_KEY1, VALUE_B); |
118 |
manager.setDataQualified(PARENT_KEY2, VALUE_C); |
119 |
assertEquals(VALUE_A, manager.getVariableData("${key1}")); |
120 |
assertEquals(VALUE_B, manager.getVariableData("${parent.key1}")); |
121 |
assertEquals(VALUE_C, manager.getVariableData("${parent.key2}")); |
122 |
assertEquals("Values are A B C", manager.performVariableSubstitution |
123 |
("Values are ${key1} ${parent.key1} ${parent.key2}")); |
124 |
} |
125 |
|
126 |
} |