Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bf12286ed8e1471d0778873d8109d60e2510057c (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*****************************************************************************
 * 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.infra.core.sasheditor.contentprovider;

import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.folder;
import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.page;
import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.vSash;
import static org.junit.Assert.assertNotNull;

import java.util.Map;

import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
import org.eclipse.swt.SWT;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * Test suite for {@link ISashWindowsContentProviderFacade} implementations.
 * Each implementation of {@link ISashWindowsContentProviderFacade} can be tested with this suite.
 * This class provides the tests common to all implementation. 
 * 
 * An implementation can be tested by subclassing this class, and by implementing the 
 * getIcontentProviderFacade method. This later should return the implementation of 
 * {@link ISashWindowsContentProviderFacade} to test.
 * 
 * @author cedric dumoulin
 *
 */
public abstract class AbstractSashWindowContentProviderFacadeTest {

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

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

	/**
	 * Create an instance of the {@link ISashWindowsContentProviderFacade} to test.
	 * 
	 * @return an instance of {@link ISashWindowsContentProviderFacade};
	 */
	public abstract ISashWindowsContentProviderFacade createISashWindowsContentProviderFacade();
	/**
	 * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#assertConform(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
	 * @throws PagesModelException 
	 */
	@Test
	public void testAssertConform() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
		// Try to create the model
		helper.createModel(expr);

		// Try to check model
		helper.assertConform(expr);
	
	}

	/**
	 * Test assertConform with expr starting with a folder.
	 * @throws PagesModelException 
	 */
	@Test
	public void testAssertConformExprStartngWithFolder() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
				                       page("p5"), page("p6"), page("p7"), page("p8"));
		// Try to create the model
		helper.createModel(expr);
		

		// Check if conform
		helper.assertConform(expr);
	}
	
	/**
	 * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#createModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
	 * @throws PagesModelException 
	 */
	@Test
	public void testCreateModel() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
		// Try to create the model
		helper.createModel(expr);
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#queryModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
	 * @throws PagesModelException 
	 */
	@Test
	public void testQueryModel() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
		// Try to create the model
		helper.createModel(expr);
		
		// Query model
		Map<String, Object> res = helper.queryModel(expr);
		assertNotNull("found f1", res.get("f1"));
//		assertTrue("right type", res.get("f1") instanceof TabFolderModel );

		assertNotNull("found f2", res.get("f2"));
//		assertTrue("right type", res.get("f2") instanceof TabFolderModel );

		assertNotNull("found p2", res.get("p2"));
//		assertTrue("right type", res.get("p2") instanceof IPageModel );
	}

	/**
	 * Test folder creation.
	 * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
	 * @throws PagesModelException 
	 */
	@Test
	public void testCreateFolder() throws PagesModelException {
	

		ISashWindowsContentProviderFacade contentFacade = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", contentFacade);
		// Create a query
//		IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
		IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
				                       page("p5"), page("p6"), page("p7"), page("p8"));
		// Try to create the model
		contentFacade.createModel(expr);
		
		// Create another folder
		contentFacade.createFolder("f1", 0, "f1", SWT.UP);
		// Check the content configuration
		IModelExp conf1Expr = vSash( 
				folder( "f2", page("p1") ),
				folder( "f1", page("p2"), page("p3"), page("p4"),
                page("p5"), page("p6"), page("p7"), page("p8") )
                );
		// Check if conform
		contentFacade.assertConform(conf1Expr);
		
		// Check resetContext
		contentFacade.resetNamesContext(conf1Expr);
		
		assertNotNull("new name found", contentFacade.getNamesToInternalMap().get("f2"));
	}


	/**
	 * Test page creation.
	 * @throws PagesModelException 
	 */
	@Test
	public void testCreateNewPage() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
				                       page("p5"), page("p6"), page("p7"), page("p8"));
		// Try to create the model
		helper.createModel(expr);
		
		// Create a new page
		helper.addPage(page("newPage"), "f1");
		
		// Check the content configuration
		IModelExp conf1Expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
                page("p5"), page("p6"), page("p7"), page("p8"), page("newPage"));

		// Check if conform
		helper.assertConform(conf1Expr);
		
	}
	
	/**
	 * Test page deletion.
	 * @throws PagesModelException 
	 */
	@Test
	public void testClosePage() throws PagesModelException {
		ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", helper);
		// Create a query
		IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
				                       page("p5"), page("p6"), page("p7"), page("p8"));
		// Try to create the model
		helper.createModel(expr);
		
		// Create a new page
		helper.removePage( "p8");
		
		// Check the content configuration
		IModelExp conf1Expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
                page("p5"), page("p6"), page("p7"));

		// Check if conform
		helper.assertConform(conf1Expr);
		
	}

	/**
	 * Test folder deletion.
	 * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
	 * @throws PagesModelException 
	 */
	@Test
	public void testDeleteFolder() throws PagesModelException {
	

		ISashWindowsContentProviderFacade contentFacade = createISashWindowsContentProviderFacade();
		
		assertNotNull("helper created", contentFacade);
		// Create a query
//		IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
		IModelExp expr = vSash( 
				folder( "f1", page("p2"), page("p3"), page("p4") ),
				folder( "f2", page("p1") )
                );
		// Try to create the model
		contentFacade.createModel(expr);
		
		// Create the folder.
		// This is done by closing the last page
		contentFacade.removePage("p1");
		
		// Check the content configuration
		IModelExp conf1Expr = folder( "f1", page("p2"), page("p3"), page("p4"));
		// Check if conform
		contentFacade.assertConform(conf1Expr);
		
	}


}

Back to the top