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 217821 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/css/ui/tests/viewer/TestCSSContentAssist.java (-12 / +85 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.css.ui.tests.viewer;
11
package org.eclipse.wst.css.ui.tests.viewer;
12
12
13
import java.io.ByteArrayOutputStream;
14
import java.io.FileNotFoundException;
13
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.InputStream;
14
17
15
import junit.framework.Assert;
18
import junit.framework.Assert;
16
import junit.framework.TestCase;
19
import junit.framework.TestCase;
Lines 41-49 Link Here
41
44
42
public class TestCSSContentAssist extends TestCase {
45
public class TestCSSContentAssist extends TestCase {
43
46
47
	private static final String UTF_8 = "UTF-8";
44
	protected String projectName = null;
48
	protected String projectName = null;
45
	protected String fileName = null;
49
	protected String fileName = null;
46
	protected String resourcesFolder = null;
50
	protected String resourcesFolder = null;
51
	IProject project = null;
47
	private StructuredTextViewer sourceViewer = null;
52
	private StructuredTextViewer sourceViewer = null;
48
	protected IStructuredDocument document = null;
53
	protected IStructuredDocument document = null;
49
	private IStructuredModel model;
54
	private IStructuredModel model;
Lines 55-73 Link Here
55
	protected void setUp() throws Exception {
60
	protected void setUp() throws Exception {
56
61
57
		super.setUp();
62
		super.setUp();
58
		projectName = "CSSContentAssistForMedia";
63
		projectName = "CSSContentAssist";
59
		fileName = "mediaexample.css";
60
		resourcesFolder = "/testresources";
64
		resourcesFolder = "/testresources";
61
65
62
		String filePath = setupProject();
66
		if (fileName == null) {
63
		file = ResourcesPlugin.getWorkspace().getRoot().getFile(
67
			fileName = "mediaexample.css";
64
				new Path(filePath));
65
66
		if (file != null && !file.exists()) {
67
			Assert.fail("Unable to locate " + file + ".");
68
		}
68
		}
69
69
70
		loadFile();
70
		String filePath = setupProject();
71
		loadFile(filePath);
71
72
72
		initializeSourceViewer();
73
		initializeSourceViewer();
73
	}
74
	}
Lines 100-106 Link Here
100
		sourceViewer.setDocument(document);
101
		sourceViewer.setDocument(document);
101
	}
102
	}
102
103
103
	protected void loadFile() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
104
	protected void loadFile(String filePath) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
105
		file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
106
107
		if (file != null && !file.exists()) {
108
			Assert.fail("Unable to locate " + file + ".");
109
		}
110
		
104
		IModelManager modelManager = StructuredModelManager.getModelManager();
111
		IModelManager modelManager = StructuredModelManager.getModelManager();
105
		model = modelManager.getModelForEdit(file);
112
		model = modelManager.getModelForEdit(file);
106
		document = model.getStructuredDocument();
113
		document = model.getStructuredDocument();
Lines 109-132 Link Here
109
	protected String setupProject() throws Exception{
116
	protected String setupProject() throws Exception{
110
		IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
117
		IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
111
118
112
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
119
		project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
113
		try {
120
		try {
114
			project.create(description, new NullProgressMonitor());
121
			project.create(description, new NullProgressMonitor());
115
			project.open(new NullProgressMonitor());
122
			project.open(new NullProgressMonitor());
116
		} catch (CoreException e) {
123
		} catch (CoreException e) {
117
124
118
		}
125
		}
119
		String filePath = project.getFullPath().addTrailingSeparator().append(fileName).toString();
126
		String filePath = getProjectPath();
120
127
121
		ProjectUtil.copyBundleEntriesIntoWorkspace(resourcesFolder, project.getFullPath().toString());
128
		ProjectUtil.copyBundleEntriesIntoWorkspace(resourcesFolder, project.getFullPath().toString());
122
129
123
		return filePath;
130
		return filePath;
124
	}
131
	}
132
	
133
	protected String getProjectPath()
134
	{
135
		if(project != null)
136
		{
137
			return project.getFullPath().addTrailingSeparator().append(fileName).toString();
138
		}
139
		return null;
140
	}
125
141
126
	protected void tearDown() throws Exception {
142
	protected void tearDown() throws Exception {
127
		super.tearDown();
143
		super.tearDown();
128
	}
144
	}
129
145
146
	/**
147
	 * must release model (from edit) after
148
	 * 
149
	 * @param filename
150
	 *            relative to this class (TestFormatProcessorCSS)
151
	 */
152
	private IStructuredModel getModelForEdit(final String file)	throws IOException {
153
154
		IStructuredModel model = null;
155
		IModelManager modelManager = StructuredModelManager.getModelManager();
156
		InputStream inStream = getClass().getResourceAsStream(file);
157
		if (inStream == null)
158
			throw new FileNotFoundException("Can't file resource stream " + file);
159
		final String baseFile = getClass().getResource(file).toString();
160
		model = modelManager.getModelForEdit(baseFile, inStream, null);
161
		return model;
162
	}
163
	
130
	public void testContentAssistInsideMedia() throws Exception {
164
	public void testContentAssistInsideMedia() throws Exception {
131
165
132
		try {
166
		try {
Lines 139-142 Link Here
139
			model.releaseFromEdit();
173
			model.releaseFromEdit();
140
		}
174
		}
141
	}
175
	}
176
177
	public void testContentAssistCompletion() throws Exception {
178
		IStructuredModel afterModel = null;
179
		try {
180
			fileName = "contentAssistCompletion.css";
181
			String filePath = getProjectPath();
182
			loadFile(filePath);
183
			initializeSourceViewer();
184
185
			CSSContentAssistProcessor processor = new CSSContentAssistProcessor();
186
			ICompletionProposal[] proposals = processor
187
					.computeCompletionProposals(sourceViewer, 11);
188
			assertTrue("No proposals at offset.", proposals.length > 0);
189
			ICompletionProposal proposal = proposals[0];
190
			assertEquals("Wrong proposal returned for H1.", "h1", proposal.getDisplayString());
191
			proposal.apply(document);
192
193
			String resultfile = "results/contentAssistCompletion-result.css";
194
			afterModel = getModelForEdit(resultfile);
195
			assertNotNull("could not retrieve structured model for : "+ resultfile, afterModel);
196
197
			ByteArrayOutputStream updatedBytes = new ByteArrayOutputStream();
198
			model.save(updatedBytes);
199
200
			ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
201
			afterModel.save(afterBytes);
202
203
			String updatedContents = new String(updatedBytes.toByteArray(),UTF_8);
204
			String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
205
			assertTrue("Edited document differs from the expected", updatedContents.equalsIgnoreCase(expectedContents));
206
207
		} finally {
208
			if (model != null)
209
				model.releaseFromEdit();
210
			if (afterModel != null)
211
				afterModel.releaseFromEdit();
212
		}
213
	}
214
	
142
}
215
}
(-)testresources/contentAssistCompletion.css (+9 lines)
Added Link Here
1
H2 {
2
	
3
}
4
5
H
6
7
H3 {
8
	
9
}
(-)src/org/eclipse/wst/css/ui/tests/viewer/results/contentAssistCompletion-result.css (+11 lines)
Added Link Here
1
H2 {
2
	
3
}
4
5
h1 {
6
	
7
}
8
9
H3 {
10
	
11
}

Return to bug 217821