Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7ad0d8d0007ba1d75c333439c52384adb4043e55 (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
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 * 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:
 * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com  - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;

import java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
import org.eclipse.papyrus.junit.utils.ProjectUtils;
import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRootElementPage;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;



public class TestCreateModelFromExistingModelWizard extends TestNewModelWizardBase {

	// This test only covers the creation of the wizard and check if the first page contain the expected file name
	private static IProject createProject;

	private static IFile file, fileWithDot;

	/**
	 * @see org.eclipse.papyrus.uml.diagram.wizards.TestNewModelWizardBase#createWizard()
	 *
	 * @return
	 */

	@BeforeClass
	public static void init() {
		try {
			createProject = ProjectUtils.createProject("UMLOnlyTest");
		} catch (CoreException e) {
			Assert.fail(e.getMessage());
		}

		try {
			file = PapyrusProjectUtils.copyIFile("/resources/model.uml", Platform.getBundle("org.eclipse.papyrus.uml.diagram.wizards.tests"), createProject, "model.uml");
			fileWithDot = PapyrusProjectUtils.copyIFile("/resources/model.model.uml", Platform.getBundle("org.eclipse.papyrus.uml.diagram.wizards.tests"), createProject, "model.model.uml");

		} catch (CoreException e) {
			Assert.fail(e.getMessage());
		} catch (IOException e) {
			Assert.fail(e.getMessage());
		}
	}

	@Override
	protected IWorkbenchWizard createWizard() {
		return new InitModelWizard() {

			private boolean isInitFromExistingDomainModel;

			private SelectRootElementPage selectRootElementPage;

			@Override
			public void init(IWorkbench workbench, IStructuredSelection selection) {
				URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
				isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
				super.init(workbench, selection);
				selectRootElementPage = createSelectRootElementPage(selection);
				if (isCreateFromExistingDomainModel()) {
					// Init Model not Create a new one
					setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
				}
			}

			@Override
			public boolean isCreateFromExistingDomainModel() {
				return true;
			}

		};

	}


	@Test
	public void testOrderOfPages() {
		// actual pages: [SelectDiagramCategory -> SelectDiagramCategoryPage, SelectStorageProvider -> SelectStorageProviderPage,
		// NewPapyrusModel -> NewModelFilePage, NewCDOModel -> NewModelPage, SelectDiagramKind -> SelectDiagramKindPage, SelectRootPage -> SelectRootElementPage]
		Class<?>[] expectedPages = new Class[] { SelectDiagramCategoryPage.class, NewModelFilePage.class, SelectDiagramKindPage.class, /* SelectRootElementPage.class, */ };

		IWorkbenchWizard wizard = initWizardDialog();
		testOrderOfPages(wizard, expectedPages);
	}

	@Test
	public void testForSimpleModel() {
		InitModelWizard wizard = new InitModelWizard() {

			private boolean isInitFromExistingDomainModel;

			// private SelectRootElementPage selectRootElementPage;

			@Override
			public void init(IWorkbench workbench, IStructuredSelection selection) {
				URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
				isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
				super.init(workbench, selection);
				// selectRootElementPage = createSelectRootElementPage(selection);
				if (isCreateFromExistingDomainModel()) {
					// Init Model not Create a new one
					setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
				}
			}

			@Override
			public boolean isCreateFromExistingDomainModel() {
				return true;
			}

		};
		initWizardDialog(wizard);
		NewModelFilePage page = getPage(wizard, NewModelFilePage.class);
		assertEquals("model.di", page.getFileName());

	}

	@Test
	public void testForModelWithDot() {
		InitModelWizard wizard = new InitModelWizard() {

			private boolean isInitFromExistingDomainModel;

			private SelectRootElementPage selectRootElementPage;

			@Override
			public void init(IWorkbench workbench, IStructuredSelection selection) {
				URI uri = URI.createPlatformResourceURI(fileWithDot.getFullPath().toString(), true);
				isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
				super.init(workbench, selection);
				selectRootElementPage = createSelectRootElementPage(selection);
				if (isCreateFromExistingDomainModel()) {
					// Init Model not Create a new one
					setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
				}
			}

			@Override
			public boolean isCreateFromExistingDomainModel() {
				return true;
			}
		};
		initWizardDialog(wizard);
		NewModelFilePage page = getPage(wizard, NewModelFilePage.class);
		assertNotSame("model.model.di", page.getFileName());
		// this should be fixed in the wizard to have the right name from the begining if the name contain a dot


	}


}

Back to the top