Skip to main content
summaryrefslogtreecommitdiffstats
blob: 626fd2af02f892515c47a70a38301ec834043028 (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
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST 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:
 *   CEA LIST - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests;

import java.io.IOException;
import java.util.List;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.junit.utils.GenericUtils;
import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
import org.eclipse.papyrus.uml.nattable.clazz.config.tests.Activator;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;

import ca.odell.glazedlists.TreeList;

/**
 * @author Vincent Lorenzo
 *
 */
public class TableFillingAndExpandTest extends AbstractEditorTest {
	protected Resource di;

	protected Resource notation;

	protected Resource uml;

	protected Model rootModel;

	protected Class classTest;

	protected List<?> elementListTest;

	protected Package packageTest;

	private final String modelName = "tableFillingAndTableExpandTest"; //$NON-NLS-1$

	private final String uml_EXT = "uml"; //$NON-NLS-1$
	private final String notation_EXT = "notation"; //$NON-NLS-1$
	private final String di_EXT = "di"; //$NON-NLS-1$
	private final String DOT = "."; //$NON-NLS-1$
	private final StringBuilder umlBuiler = new StringBuilder(modelName).append(DOT).append(uml_EXT);
	private final StringBuilder notationBuiler = new StringBuilder(modelName).append(DOT).append(notation_EXT);
	private final StringBuilder diBuilder = new StringBuilder(modelName).append(DOT).append(di_EXT);

	@Before
	public void initTests() throws CoreException, IOException {
		try {
			initModel(modelName, modelName, getBundle());
		} catch (Exception e) {
			Activator.log.error(e);
		}

		ResourceSet set = null;
		try {
			set = getModelSet();
		} catch (ServiceException e) {
			e.printStackTrace();
		}

		List<Resource> resources = set.getResources();

		for (Resource current : resources) {
			if (current.getURI().lastSegment().equals(umlBuiler.toString())) {
				uml = current;
			} else if (current.getURI().lastSegment().equals(notationBuiler.toString())) {
				notation = current;
			} else if (current.getURI().lastSegment().equals(diBuilder.toString())) {
				di = current;
			}
		}

		rootModel = (Model) uml.getContents().get(0);
		// TODO on luna : open diagram
	}

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

	@Override
	protected Bundle getBundle() {
		return Activator.getDefault().getBundle();
	}

	@AfterClass
	public static void endOfTest() {
		GenericUtils.closeAllEditors();
	}

	@Test
	public void fullTest() {
		selectTablePage(0);
		INattableModelManager manager = (INattableModelManager) this.editor.getAdapter(INattableModelManager.class);
		List<?> elements = manager.getRowElementsList();
		Assert.isTrue(elements instanceof TreeList<?>, " the list managing the rows in not a TreeList"); //$NON-NLS-1$
	}

	protected void selectTablePage(int index) {
		try {
			Object tablePage = getPageManager().allPages().get(index);
			// getPageManager().closeAllOpenedPages();
			// getPageManager().openPage(tablePage);
			getPageManager().selectPage(tablePage);
		} catch (ServiceException e) {
			Activator.log.error(e);
		}
	}

}

Back to the top