Skip to content

Commit 31ea59a

Browse files
committed
Improve stability of UI test - CamelLSPCompletionTest #65
Signed-off-by: Dominik Jelinek <[email protected]>
1 parent 3b47b23 commit 31ea59a

File tree

2 files changed

+49
-21
lines changed
  • com.github.camel-tooling.lsp.eclipse.client.tests.ui

2 files changed

+49
-21
lines changed

com.github.camel-tooling.lsp.eclipse.client.tests.ui/plugins/com.github.cameltooling.lsp.reddeer/src/com/github/cameltooling/lsp/reddeer/editor/SourceEditor.java

+31
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
import java.util.List;
2020

21+
import org.eclipse.core.runtime.NullProgressMonitor;
22+
import org.eclipse.reddeer.common.util.Display;
23+
import org.eclipse.reddeer.common.util.ResultRunnable;
2124
import org.eclipse.reddeer.jface.text.contentassist.ContentAssistant;
2225
import org.eclipse.reddeer.swt.impl.styledtext.DefaultStyledText;
26+
import org.eclipse.reddeer.workbench.handler.EditorHandler;
2327
import org.eclipse.reddeer.workbench.impl.editor.DefaultEditor;
2428

2529
/**
@@ -79,4 +83,31 @@ public List<String> getCompletionProposals() {
7983
assistant.close();
8084
return proposals;
8185
}
86+
87+
@Override
88+
public void activate() {
89+
EditorHandler.getInstance().activate(editorPart);
90+
}
91+
92+
public void save() {
93+
log.debug("Saving editor");
94+
Display.syncExec(new Runnable() {
95+
96+
@Override
97+
public void run() {
98+
editorPart.doSave(new NullProgressMonitor());
99+
}
100+
});
101+
}
102+
103+
public boolean isDirty() {
104+
return Display.syncExec(new ResultRunnable<Boolean>() {
105+
106+
@Override
107+
public Boolean run() {
108+
return editorPart.isDirty();
109+
}
110+
});
111+
}
112+
82113
}

com.github.camel-tooling.lsp.eclipse.client.tests.ui/tests/com.github.cameltooling.lsp.ui.tests/src/com/github/cameltooling/lsp/ui/tests/CamelLSPCompletionTest.java

+18-21
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
import java.util.List;
2222

23-
import org.eclipse.reddeer.common.wait.AbstractWait;
2423
import org.eclipse.reddeer.common.wait.TimePeriod;
24+
import org.eclipse.reddeer.common.wait.WaitWhile;
2525
import org.eclipse.reddeer.eclipse.jdt.ui.wizards.JavaProjectWizard;
2626
import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer;
2727
import org.eclipse.reddeer.eclipse.wst.jsdt.ui.wizards.JavaProjectWizardFirstPage;
2828
import org.eclipse.reddeer.jface.text.contentassist.ContentAssistant;
2929
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
30+
import org.eclipse.reddeer.swt.condition.ShellIsAvailable;
3031
import org.eclipse.reddeer.swt.impl.ctab.DefaultCTabItem;
3132
import org.eclipse.reddeer.workbench.impl.editor.DefaultEditor;
3233

@@ -73,15 +74,14 @@ public static void prepareEnvironment() {
7374
createNewJavaProject(PROJECT_NAME);
7475
new ProjectExplorer().selectProjects(PROJECT_NAME);
7576
createNewEmptyXMLFile(CAMEL_CONTEXT);
76-
DefaultEditor editor = new DefaultEditor(CAMEL_CONTEXT);
77-
editor.activate();
77+
new DefaultEditor(CAMEL_CONTEXT).activate();;
7878
new DefaultCTabItem(EDITOR_SOURCE_TAB).activate();
7979
EditorManipulator.copyFileContentToXMLEditor(RESOURCES_CONTEXT_PATH);
8080
}
8181

8282
@After
8383
public void cleanEditor() {
84-
new DefaultEditor(CAMEL_CONTEXT).activate();
84+
editor.activate();
8585
EditorManipulator.copyFileContentToXMLEditor(RESOURCES_CONTEXT_PATH);
8686
}
8787

@@ -116,7 +116,7 @@ public void testEndpointOptions() {
116116
cursorPosition = editor.getText().indexOf("<from");
117117
editor.setCursorPosition(cursorPosition += 42);
118118
tryEndpointOptionsCompletion();
119-
119+
120120
cursorPosition = editor.getText().indexOf("<to");
121121
editor.setCursorPosition(cursorPosition += 42);
122122
tryEndpointOptionsCompletion();
@@ -150,9 +150,9 @@ public void testDuplicateOptionsFiltering() {
150150
editor = new SourceEditor();
151151

152152
cursorPosition = editor.getText().indexOf("<from");
153-
editor.setCursorPosition(cursorPosition += 42);
153+
editor.setCursorPosition(cursorPosition += 42);
154154
tryOptionsFiltering();
155-
155+
156156
cursorPosition = editor.getText().indexOf("<to");
157157
editor.setCursorPosition(cursorPosition += 42);
158158
tryOptionsFiltering();
@@ -183,7 +183,6 @@ private static void createNewJavaProject(String name) {
183183
}
184184

185185
private void assertComponentSchemes(List<String> proposals) {
186-
AbstractWait.sleep(TimePeriod.MEDIUM);
187186
collector.checkThat("Content assistant is empty", proposals.isEmpty(), equalTo(false));
188187
collector.checkThat("Content assistant is not filtered", proposals.get(0).startsWith("f"), equalTo(true));
189188
}
@@ -197,10 +196,9 @@ private void tryEndpointOptionsCompletion() {
197196
assistant = editor.openContentAssistant();
198197
collector.checkThat(assistant.getProposals().isEmpty(), equalTo(false));
199198
assistant.chooseProposal("InOnly");
200-
AbstractWait.sleep(TimePeriod.MEDIUM);
201-
if (editor.isDirty()) {
202-
editor.save();
203-
}
199+
200+
new WaitWhile(new ShellIsAvailable(assistant), TimePeriod.MEDIUM);
201+
editor.save();
204202
}
205203

206204
private void tryAdditionalOptionsCompletion() {
@@ -209,12 +207,11 @@ private void tryAdditionalOptionsCompletion() {
209207
assistant = editor.openContentAssistant();
210208
collector.checkThat(assistant.getProposals().isEmpty(), equalTo(false));
211209
assistant.chooseProposal("allowNullBody");
212-
AbstractWait.sleep(TimePeriod.MEDIUM);
213-
if (editor.isDirty()) {
214-
editor.save();
215-
}
210+
211+
new WaitWhile(new ShellIsAvailable(assistant), TimePeriod.MEDIUM);
212+
editor.save();
216213
}
217-
214+
218215
private void tryOptionsFiltering() {
219216
editor.insertText("?e");
220217
editor.setCursorPosition(cursorPosition += 2);
@@ -225,14 +222,14 @@ private void tryOptionsFiltering() {
225222
collector.checkThat(assistant.getProposals().isEmpty(), equalTo(false));
226223
assistant.chooseProposal("InOnly");
227224
editor.insertText("&amp;e");
228-
editor.setCursorPosition(cursorPosition += 27);
225+
editor.setCursorPosition(cursorPosition += 27);
229226
assistant = editor.openContentAssistant();
230227
collector.checkThat(assistant.getProposals().isEmpty(), equalTo(false));
231228
collector.checkThat(assistant.getProposals().contains("exchangePattern"), equalTo(false));
232229
assistant.close();
233-
if (editor.isDirty()) {
234-
editor.save();
235-
}
230+
231+
new WaitWhile(new ShellIsAvailable(assistant), TimePeriod.MEDIUM);
232+
editor.save();
236233
}
237234

238235
}

0 commit comments

Comments
 (0)