Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9c2c655af28f171e9cb3de49fd2096a650e5b286 (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
/*****************************************************************************
 * Copyright (c) 2013 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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.nattable.model.editor.tests.tests;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableaxisEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableaxisconfigurationEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableaxisproviderEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattablecellEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableconfigurationEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattablelabelproviderEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattableproblemEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.customeditors.CustomNattabletesterEditor;
import org.eclipse.papyrus.infra.nattable.model.editor.tests.Activator;
import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.GenericUtils;
import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
import org.eclipse.papyrus.junit.utils.ProjectUtils;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;

/**
 * If some tests of this class doesn't work, the problem comes probably from the plugin.xml of the plugin oep.infra.nattable.model.editor.
 * We replace the initial contributions to org.eclipse.ui.editor by our with our Custom Editor which override the save options
 * 
 * @author vl222926
 * 
 */
public class EditorsTests {

	private IProject project;

	@Before
	public void init() throws CoreException {
		ProjectUtils.removeAllProjectFromTheWorkspace();

	}

	/**
	 * 
	 * @param projectName
	 *        the name of the project
	 * @param modelName
	 *        the name of the file
	 * @param bundle
	 *        the bundle to use
	 * @return
	 * @throws Exception
	 */
	protected IEditorPart openFile(String projectName, String modelName, final Bundle bundle) throws Exception {
		project = ProjectUtils.createProject(projectName);
		final IFile diModelFile = PapyrusProjectUtils.copyIFile(getSourcePath() + modelName, bundle, project, modelName);
		RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() {

			public void run() {
				setStatus(Status.OK_STATUS);
				try {
					IEditorPart editor = EditorUtils.openEditor(diModelFile);
					setResult(editor);
				} catch (Exception ex) {
					Activator.log.error(ex);
					setStatus(new Status(IStatus.ERROR, bundle.getSymbolicName(), ex.getMessage()));
				}

			}
		};

		Display.getDefault().syncExec(runnableWithResult);
		Assert.assertEquals(runnableWithResult.getStatus().getMessage(), IStatus.OK, runnableWithResult.getStatus().getSeverity());

		IEditorPart editor = (IEditorPart)runnableWithResult.getResult();
		Assert.assertNotNull(editor);
		return editor;
	}

	private Bundle getBundle() {
		return Activator.getDefault().getBundle();
	}

	@Test
	public void testOpenNattableFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattable", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableEditor);
	}

	@Test
	public void testOpenNattableAxisFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattableaxis", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableaxisEditor);
	}

	@Test
	public void testOpenNattableAxisConfigurationFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattableaxisconfiguration", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableaxisconfigurationEditor);
	}

	@Test
	public void testOpenNattableAxisProviderFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattableaxisprovider", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableaxisproviderEditor);
	}

	@Test
	public void testOpenNattableConfigurationFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattableconfiguration", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableconfigurationEditor);
	}


	@Test
	public void testOpenNattableLabelProviderFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattablelabelprovider", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattablelabelproviderEditor);
	}

	@Test
	public void testOpenNattableTesterFileEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattabletester", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattabletesterEditor);
	}


	@Test
	public void testOpenNattableTesterCellEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattablecell", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattablecellEditor);
	}


	@Test
	public void testOpenNattableTesterProblemEditor() throws Exception {
		IEditorPart editor = openFile("testTableConfiguration", "My.nattableproblem", getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
		Assert.assertTrue(editor instanceof CustomNattableproblemEditor);
	}

	protected String getSourcePath() {
		return "/resources/"; //$NON-NLS-1$
	}

	@After
	public void after() {
		GenericUtils.closeAllEditors();

	}
}

Back to the top