Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ebf63c3189f185e2874bfb4b2c7207d8a9d2fb38 (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
/*****************************************************************************
 * Copyright (c) 2013 Cedric Dumoulin.
 *
 *
 * 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:
 *  Cedric Dumoulin  Cedric.dumoulin@lifl.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.integrationtests.editor;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.BadArgumentExcetion;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * Test for the utility class {@link ProgramaticPapyrusEditor}
 *
 * @author cedric dumoulin
 *
 */
public class ProgramaticPapyrusEditorTest {

	/**
	 * Name of the plugin that is created.
	 */
	final protected String PLUGIN_PROJECT_NAME = "org.eclipse.papyrus.integrationtests.editor.tests";

	/**
	 * Name of the bundle containing resources to copied.
	 */
	final protected String BUNDLE_NAME = "org.eclipse.papyrus.integrationtests.editor";


	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#createEditor()}.
	 *
	 * @throws ExecutionException
	 */
	@Test
	public void testCreateEditor() throws ExecutionException {
		ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
		IMultiDiagramEditor editor = editorHandler.getEditor();

		assertNotNull("editor created", editor);
		editorHandler.dispose();
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#dispose()}.
	 *
	 * @throws ExecutionException
	 */
	@Test
	public void testDispose() throws ExecutionException {
		ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
		IMultiDiagramEditor editor = editorHandler.getEditor();

		assertNotNull("editor created", editor);
		// Try to dispose
		editorHandler.dispose();
		assertNull("editor cleaned", editorHandler.getEditor());
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#getEditor()}.
	 *
	 * @throws ExecutionException
	 */
	@Test
	public void testGetEditor() throws ExecutionException {
		ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
		IMultiDiagramEditor editor = editorHandler.getEditor();

		assertNotNull("editor created", editor);

		editorHandler.dispose();
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#getServiceRegistry()}.
	 *
	 * @throws ExecutionException
	 */
	@Test
	public void testGetServiceRegistry() throws ExecutionException {
		ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
		IMultiDiagramEditor editor = editorHandler.getEditor();

		assertNotNull("editor created", editor);

		// Try to get the Registry
		ServicesRegistry servicesRegistry = editorHandler.getServiceRegistry();
		assertNotNull("registry initialized", servicesRegistry);

		editorHandler.dispose();
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#getEditor()}.
	 *
	 * @throws ServiceException
	 * @throws BadArgumentExcetion
	 * @throws NotFoundException
	 * @throws ExecutionException
	 */
	@Test
	public void testGetEditorAndLoadModel() throws ServiceException, NotFoundException, BadArgumentExcetion, ExecutionException {

		String modelName = "models/modelTestLoadModel";
		// String modelName = "modelTestLoadModel";
		String diagramName = "diagram1";
		EclipseProject eclipseProject = new EclipseProject(PLUGIN_PROJECT_NAME);
		eclipseProject.copyResources(BUNDLE_NAME, modelName + ".di", modelName + ".notation", modelName + ".uml");

		ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor(eclipseProject, modelName);
		IMultiDiagramEditor editor = editorHandler.getEditor();

		assertNotNull("editor created", editor);

		NotationModel notationModel = (NotationModel) editorHandler.getModelSet().getModel(NotationModel.MODEL_ID);
		assertNotNull("notation model loaded", notationModel);

		// If the following assertion is false, this means that the model is not loaded from file (it has been created)
		Diagram diagram = notationModel.getDiagram(diagramName);
		assertNotNull("diagram loaded", diagram);

		editorHandler.dispose();
	}


}

Back to the top