Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 238a63e023dd37f299d12165b5094ce1ac116668 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright (c) 2010-2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.tests.ui.emf;

import org.eclipse.emf.cdo.dawn.tests.AbstractDawnEMFTest;
import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnAcoreTestUtil;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author Martin Fluegge
 */
@CleanRepositoriesBefore
@RunWith(SWTBotJunit4ClassRunner.class)
public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest
{
  private String resourceFieldLabel = org.eclipse.emf.cdo.dawn.ui.messages.Messages.DawnCreateNewResourceWizardPage_6;

  @Test
  public void testCreateNewDawnAcoreEditor() throws Exception
  {
    getBot().menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = getBot().shell("New");
    shell.activate();
    getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    getBot().button("Next >").click();
    getBot().button("Next >").click();

    shell = getBot().shell("New");
    shell.activate();

    SWTBotCombo comboBox = getBot().comboBox(0);// bot.ccomboBox(0);
    comboBox.setFocus();
    comboBox.setSelection("ACore Root");

    getBot().button("Finish").click();

    sleep(500);

    SWTBotEditor editor = getBot().editorByTitle("default.acore");
    assertNotNull(editor);
    editor.close();
    {
      assertEquals(true, resourceExists("/default.acore"));
    }
  }

  @Test
  public void testCreateNewDawnEditorSetName() throws Exception
  {
    getBot().menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = getBot().shell("New");
    shell.activate();
    getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    getBot().button("Next >").click();

    shell = getBot().shell("New");
    shell.activate();

    SWTBotText fileSemanticNameLabel = getBot().textWithLabel(resourceFieldLabel);
    fileSemanticNameLabel.setText("test.acore");
    assertEquals("test.acore", fileSemanticNameLabel.getText());

    getBot().button("Next >").click();

    SWTBotCombo comboBox = getBot().comboBox(0);// bot.ccomboBox(0);
    comboBox.setFocus();
    comboBox.setSelection("ACore Root");

    getBot().button("Finish").click();

    SWTBotEditor editor = getBot().editorByTitle("test.acore");
    assertNotNull(editor);
    editor.close();
  }

  @Test
  public void testCreateNewDawnEditorWrongResourceName() throws Exception
  {
    getBot().menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = getBot().shell("New");
    shell.activate();
    getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    getBot().button("Next >").click();

    shell = getBot().shell("New");
    shell.activate();

    SWTBotText fileSemanticNameLabel = getBot().textWithLabel(resourceFieldLabel);
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    Keyboard keyboard = KeyboardFactory.getDefaultKeyboard(fileSemanticNameLabel.widget, null);
    fileSemanticNameLabel.setFocus();
    fileSemanticNameLabel.setText("x");
    // fileSemanticNameLabel.typeText("x", 500);
    keyboard.pressShortcut(Keystrokes.BS);

    assertEquals(false, getBot().button("Next >").isEnabled());
    getBot().button("Cancel").click();
  }

  @Test
  public void testCreateNewDawnEditorSelectFolder() throws Exception
  {
    {
      CDOSession session = openSession();
      ResourceSet resourceSet = new ResourceSetImpl();
      CDOTransaction transaction = session.openTransaction(resourceSet);

      final URI uri = URI.createURI("cdo:/folder/dummy");
      resourceSet.createResource(uri);
      transaction.commit();
    }

    getBot().menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = getBot().shell("New");
    shell.activate();
    getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    getBot().button("Next >").click();

    shell = getBot().shell("New");
    shell.activate();

    SWTBotText fileNameLabel = getBot().textWithLabel(resourceFieldLabel);
    fileNameLabel.setText("test.acore");

    SWTBotTree tree = getBot().tree(0);

    selectFolder(tree.getAllItems(), "folder", false);

    getBot().button("Next >").click();

    SWTBotCombo comboBox = getBot().comboBox(0);// bot.ccomboBox(0);
    comboBox.setFocus();
    comboBox.setSelection("ACore Root");

    getBot().button("Finish").click();

    SWTBotEditor editor = getBot().editorByTitle("test.acore");
    assertNotNull(editor);
    editor.close();

    {
      assertEquals(true, resourceExists("/folder/test.acore"));
    }
  }

  @Test
  public void testCreateNewDawnDiagramTypeFolder() throws Exception
  {
    {
      CDOSession session = openSession();
      ResourceSet resourceSet = new ResourceSetImpl();
      CDOTransaction transaction = session.openTransaction(resourceSet);

      final URI uri = URI.createURI("cdo:/folder/dummy");
      resourceSet.createResource(uri);
      transaction.commit();
    }

    getBot().menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = getBot().shell("New");
    shell.activate();
    getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    getBot().button("Next >").click();

    shell = getBot().shell("New");
    shell.activate();

    SWTBotText fileNameLabel = getBot().textWithLabel(resourceFieldLabel);
    fileNameLabel.setText("test.acore");

    SWTBotText folder = getBot().textWithLabel("Enter or select the parent folder: ");
    folder.setText("/folder");
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";

    getBot().button("Next >").click();

    SWTBotCombo comboBox = getBot().comboBox(0);// bot.ccomboBox(0);
    comboBox.setFocus();
    comboBox.setSelection("ACore Root");

    getBot().button("Finish").click();

    SWTBotEditor editor = getBot().editorByTitle("test.acore");
    assertNotNull(editor);
    editor.close();

    {
      assertEquals(true, resourceExists("/folder/test.acore"));
    }
  }
}

Back to the top