Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 79ee3aa6a88f70b4e2208fc74058442c026974fc (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
/*
 * Copyright (c) 2004 - 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;

import org.eclipse.emf.cdo.dawn.tests.AbstractDawnUITest;
import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnCodeGenerationTestUtil;
import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnSWTBotUtil;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;

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

/**
 * @author Martin Fluegge
 */
@CleanRepositoriesBefore
@RunWith(SWTBotJunit4ClassRunner.class)
public class DawnCodeGenerationTest extends AbstractDawnUITest<SWTWorkbenchBot>
{
  private SWTBotView packageExplorer;

  @Override
  @Before
  public void setUp() throws Exception
  {
    super.setUp();
    prepare();
  }

  @Override
  @After
  public void tearDown() throws Exception
  {
    cleanup();
    super.tearDown();
  }

  private void cleanup()
  {
    deleteProject("org.eclipse.emf.cdo.dawn.examples.acore");
  }

  @Test
  public void testCodeGenerationGMF() throws Exception
  {
    SWTBotView packageExplorer = DawnSWTBotUtil.openView(getBot(), "Java", "Package Explorer");
    packageExplorer.setFocus();

    SWTBotTreeItem modelFolder = getBot().tree().expandNode("org.eclipse.emf.cdo.dawn.examples.acore", "model");

    SWTBotTreeItem gmfgen = modelFolder.expandNode("acore.gmfgen");
    gmfgen.contextMenu("Generate Dawn GenModel").click();

    sleep(5000);

    assertNotNull(modelFolder.getNode("acore.dawngenmodel"));
    SWTBotTreeItem dawngenmodel_gmf = modelFolder.getNode("acore.dawngenmodel_gmf");
    assertNotNull(dawngenmodel_gmf);

    dawngenmodel_gmf.contextMenu("Generate Dawn GMF Fragment").click();

    sleep(10000);

    IProject fragment = ResourcesPlugin.getWorkspace().getRoot()
        .getProject("org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn");

    assertNotNull(fragment);
    String diagramFolder = "src/org/eclipse/emf/cdo/dawn/examples/acore/diagram";
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "META-INF/MANIFEST.MF"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "/fragment.xml"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "/build.properties"));

    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/edit/parts/DawnAcoreEditPartFactory.java"));
    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/edit/parts/DawnACoreRootEditPart.java"));
    assertEquals(
        true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder
            + "/edit/policies/DawnACoreRootCanonicalEditPolicy.java"));

    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/part/DawnAcoreCreationWizard.java"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/part/DawnAcoreDiagramEditor.java"));
    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/part/DawnAcoreDiagramEditorUtil.java"));
    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/part/DawnAcoreDocumentProvider.java"));

    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/providers/DawnAcoreEditPartProvider.java"));
    assertEquals(true,
        DawnCodeGenerationTestUtil.exists(fragment, diagramFolder + "/providers/DawnAcoreEditPolicyProvider.java"));
    deleteProject("org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn");
    sleep(2000);
  }

  @Test
  public void testCodeGenerationEMF() throws Exception
  {
    packageExplorer = DawnSWTBotUtil.openView(getBot(), "Java", "Package Explorer");
    packageExplorer.setFocus();

    SWTBotTreeItem modelFolder = getBot().tree().expandNode("org.eclipse.emf.cdo.dawn.examples.acore", "model");

    SWTBotTreeItem gmfgen = modelFolder.expandNode("acore.genmodel");
    gmfgen.contextMenu("Generate Dawn GenModel").click();

    IProject rootProject = ResourcesPlugin.getWorkspace().getRoot()
        .getProject("org.eclipse.emf.cdo.dawn.examples.acore");

    waitUntilExists(rootProject, "model/acore.dawngenmodel", 10000);

    assertEquals(true, DawnCodeGenerationTestUtil.exists(rootProject, "model/acore.dawngenmodel_emf"));

    modelFolder.setFocus();
    SWTBotTreeItem dawngenmodel_emf = modelFolder.getNode("acore.dawngenmodel_emf");

    assertNotNull(dawngenmodel_emf);

    dawngenmodel_emf.contextMenu("Generate Dawn EMF Fragment").click();

    sleep(10000);

    assertNotNull(modelFolder.getNode("acore.dawngenmodel"));
    assertNotNull(modelFolder.getNode("acore.dawngenmodel_emf"));

    IProject fragment = ResourcesPlugin.getWorkspace().getRoot()
        .getProject("org.eclipse.emf.cdo.dawn.examples.acore.editor.dawn");

    assertNotNull(fragment);

    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "META-INF/MANIFEST.MF"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "/fragment.xml"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, "/build.properties"));

    String folder = "src/org/eclipse/emf/cdo/dawn/examples/acore/presentation/";

    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, folder + "DawnAcoreEditor.java"));
    assertEquals(true, DawnCodeGenerationTestUtil.exists(fragment, folder + "DawnAcoreModelWizard.java"));
    deleteProject("org.eclipse.emf.cdo.dawn.examples.acore.editor.dawn");
    sleep(2000);
  }

  private void waitUntilExists(IProject project, String path, int timeout)
  {
    while (timeout > 0)
    {
      if (DawnCodeGenerationTestUtil.exists(project, "model/acore.dawngenmodel"))
      {
        return;
      }
      sleep(1000);
      timeout -= 1000;
    }
    throw new RuntimeException("Could not find " + path + " within " + timeout + " ms.");
  }

  private SWTWorkbenchBot prepare()
  {
    SWTWorkbenchBot bot = getBot();

    SWTBotView pluginsView = DawnSWTBotUtil.openView(bot, "Plug-in Development", "Plug-ins");

    pluginsView.setFocus();

    final SWTBotTree tree = bot.tree();
    final SWTBotTree plugin = tree.select("org.eclipse.emf.cdo.dawn.examples.acore (1.0.0.qualifier)");

    DawnSWTBotUtil.findContextMenu(plugin, "Import As", "Source Project").click();

    // wait here until the import has finished
    sleep(10000);
    return bot;
  }

  private void deleteProject(String projectName)
  {
    SWTWorkbenchBot bot = getBot();
    SWTBotTreeItem project = bot.tree().expandNode(projectName);
    project.contextMenu("Delete").click();
    bot.shell("Delete Resources").activate();
    bot.checkBox().select();
    bot.button("OK").click();
    sleep(2000);
  }
}

Back to the top