Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 194917 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java (-103 / +136 lines)
Lines 1-103 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.api;
11
package org.eclipse.ui.tests.api;
12
12
13
import org.eclipse.core.resources.IWorkspace;
13
import org.eclipse.core.resources.IWorkspace;
14
import org.eclipse.core.resources.ResourcesPlugin;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.ui.IAggregateWorkingSet;
16
import org.eclipse.ui.IAggregateWorkingSet;
17
import org.eclipse.ui.IMemento;
17
import org.eclipse.ui.IMemento;
18
import org.eclipse.ui.IWorkingSet;
18
import org.eclipse.ui.IWorkingSet;
19
import org.eclipse.ui.IWorkingSetManager;
19
import org.eclipse.ui.IWorkingSetManager;
20
import org.eclipse.ui.XMLMemento;
20
import org.eclipse.ui.XMLMemento;
21
import org.eclipse.ui.internal.IWorkbenchConstants;
21
import org.eclipse.ui.internal.IWorkbenchConstants;
22
import org.eclipse.ui.tests.harness.util.ArrayUtil;
22
import org.eclipse.ui.tests.harness.util.ArrayUtil;
23
import org.eclipse.ui.tests.harness.util.UITestCase;
23
import org.eclipse.ui.tests.harness.util.UITestCase;
24
24
25
public class IAggregateWorkingSetTest extends UITestCase {
25
public class IAggregateWorkingSetTest extends UITestCase {
26
26
27
	final static String WORKING_SET_NAME = "testws";
27
	final static String WORKING_SET_NAME = "testws";
28
	final static String AGGREGATE_WORKING_SET_NAME_ = "testaggregatews";
28
	final static String AGGREGATE_WORKING_SET_NAME_ = "testaggregatews";
29
29
30
	IWorkspace fWorkspace;
30
	IWorkspace fWorkspace;
31
31
32
	IWorkingSet[] components;
32
	IWorkingSet[] components;
33
	IAggregateWorkingSet fWorkingSet;
33
	IAggregateWorkingSet fWorkingSet;
34
34
35
	public IAggregateWorkingSetTest(String testName) {
35
	public IAggregateWorkingSetTest(String testName) {
36
		super(testName);
36
		super(testName);
37
	}
37
	}
38
38
39
	protected void doSetUp() throws Exception {
39
	protected void doSetUp() throws Exception {
40
		super.doSetUp();
40
		super.doSetUp();
41
		IWorkingSetManager workingSetManager = fWorkbench
41
		IWorkingSetManager workingSetManager = fWorkbench
42
		.getWorkingSetManager();
42
		.getWorkingSetManager();
43
43
44
		fWorkspace = ResourcesPlugin.getWorkspace();
44
		fWorkspace = ResourcesPlugin.getWorkspace();
45
		components = new IWorkingSet[4];
45
		components = new IWorkingSet[4];
46
		for (int i = 0; i < 4; i++) {
46
		for (int i = 0; i < 4; i++) {
47
			components[i] = workingSetManager.createWorkingSet(WORKING_SET_NAME
47
			components[i] = workingSetManager.createWorkingSet(WORKING_SET_NAME
48
					+ i, new IAdaptable[] {});
48
					+ i, new IAdaptable[] {});
49
			workingSetManager.addWorkingSet(components[i]);
49
			workingSetManager.addWorkingSet(components[i]);
50
		}
50
		}
51
		fWorkingSet = (IAggregateWorkingSet) workingSetManager
51
		fWorkingSet = (IAggregateWorkingSet) workingSetManager
52
		.createAggregateWorkingSet(AGGREGATE_WORKING_SET_NAME_,
52
		.createAggregateWorkingSet(AGGREGATE_WORKING_SET_NAME_,
53
				AGGREGATE_WORKING_SET_NAME_, components);
53
				AGGREGATE_WORKING_SET_NAME_, components);
54
54
55
		workingSetManager.addWorkingSet(fWorkingSet);
55
		workingSetManager.addWorkingSet(fWorkingSet);
56
	}
56
	}
57
	protected void doTearDown() throws Exception {
57
	protected void doTearDown() throws Exception {
58
		IWorkingSetManager workingSetManager = fWorkbench.getWorkingSetManager();
58
		IWorkingSetManager workingSetManager = fWorkbench.getWorkingSetManager();
59
		workingSetManager.removeWorkingSet(fWorkingSet);
59
		workingSetManager.removeWorkingSet(fWorkingSet);
60
		for (int i = 0; i < components.length; i++) {
60
		for (int i = 0; i < components.length; i++) {
61
			workingSetManager.removeWorkingSet(components[i]);
61
			workingSetManager.removeWorkingSet(components[i]);
62
		}    	
62
		}    	
63
		super.doTearDown();
63
		super.doTearDown();
64
	}
64
	}
65
65
66
	public void testSaveWSet() throws Throwable {
66
	public void testSaveWSet() throws Throwable {
67
		//<possible client code>
67
		//<possible client code>
68
		IWorkingSetManager workingSetManager = fWorkbench
68
		IWorkingSetManager workingSetManager = fWorkbench
69
		.getWorkingSetManager();
69
		.getWorkingSetManager();
70
		IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_);
70
		IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_);
71
		if(set.isAggregateWorkingSet()){
71
		if(set.isAggregateWorkingSet()){
72
			IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents();
72
			IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents();
73
			if(sets.length>=1){
73
			if(sets.length>=1){
74
				sets[0]=null; //client fails to pay enough attention to specs or unknowingly does this
74
				sets[0]=null; //client fails to pay enough attention to specs or unknowingly does this
75
			}
75
			}
76
		}
76
		}
77
		//</possible client code>    	
77
		//</possible client code>    	
78
		//error makes it look like it comes from workingsets api, with no clue about the actual culprit 
78
		//error makes it look like it comes from workingsets api, with no clue about the actual culprit 
79
		IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET);
79
		IMemento memento=XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET);
80
		set.saveState(memento);
80
		set.saveState(memento);
81
	}
81
	}
82
	public void testGetElemets() throws Throwable {
82
	public void testGetElemets() throws Throwable {
83
		//<possible client code>
83
		//<possible client code>
84
		IWorkingSetManager workingSetManager = fWorkbench
84
		IWorkingSetManager workingSetManager = fWorkbench
85
		.getWorkingSetManager();
85
		.getWorkingSetManager();
86
		IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_);
86
		IWorkingSet set=workingSetManager.getWorkingSet(AGGREGATE_WORKING_SET_NAME_);
87
		if(set.isAggregateWorkingSet()){
87
		if(set.isAggregateWorkingSet()){
88
			IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents();
88
			IWorkingSet[] sets=((IAggregateWorkingSet)set).getComponents();
89
			if(sets.length>1){
89
			if(sets.length>1){
90
				//code 2 fails to pay enough attention to specs or unknowingly does this
90
				//code 2 fails to pay enough attention to specs or unknowingly does this
91
				sets[0]=workingSetManager.createWorkingSet(WORKING_SET_NAME, new IAdaptable[] { fWorkspace.getRoot() }); 
91
				sets[0]=workingSetManager.createWorkingSet(WORKING_SET_NAME, new IAdaptable[] { fWorkspace.getRoot() }); 
92
				//code 1 part  removes a workingset
92
				//code 1 part  removes a workingset
93
				workingSetManager.removeWorkingSet(sets[1]);
93
				workingSetManager.removeWorkingSet(sets[1]);
94
			}
94
			}
95
		}
95
		}
96
		//</possible client code>    	
96
		//</possible client code>    	
97
		
97
		
98
		//unexpected 
98
		//unexpected 
99
		assertTrue(ArrayUtil.equals(
99
		assertTrue(ArrayUtil.equals(
100
				new IAdaptable[] {},
100
				new IAdaptable[] {},
101
				fWorkingSet.getElements()));
101
				fWorkingSet.getElements()));
102
	}
102
	}
103
}
103
104
105
	public void testSaveRestoreFreeWorkingSet() throws Throwable {
106
		IWorkingSetManager manager = fWorkbench.getWorkingSetManager();
107
108
		IWorkingSet freeWorkingSet = manager.createWorkingSet("containing",
109
				new IAdaptable[] { fWorkspace.getRoot() });
110
111
		IAggregateWorkingSet containing = (IAggregateWorkingSet) manager
112
				.createAggregateWorkingSet("container", "container",
113
						new IWorkingSet[] { freeWorkingSet });
114
115
		assertTrue(ArrayUtil.equals(new IAdaptable[] { fWorkspace.getRoot() },
116
				containing.getElements()));
117
118
		IMemento memento = XMLMemento
119
				.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET);
120
		containing.saveState(memento);
121
122
		// load the IMemento
123
		IAggregateWorkingSet aggregateReloaded = (IAggregateWorkingSet) manager
124
				.createWorkingSet(memento);
125
		manager.addWorkingSet(aggregateReloaded);
126
		try {
127
			assertTrue(ArrayUtil.equals(
128
					new IAdaptable[] { fWorkspace.getRoot() },
129
					aggregateReloaded.getElements()));
130
		} finally {
131
			// restore
132
			manager.removeWorkingSet(aggregateReloaded);
133
		}
134
	}
135
136
}

Return to bug 194917