Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 822611e90ccd2b5bcc741c09de224211a3fa10a0 (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) 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.sysml.nattable.requirement.tests.paste.without.service.edit;

import java.util.List;

import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.papyrus.infra.emf.nattable.dataprovider.EEnumComboBoxDataProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.uml.nattable.dataprovider.UMLStereotypeSingleEnumerationComboBoxDataProvider;
import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.VisibilityKind;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author VL222926
 *
 */
public class Bug443814_Enumeration extends AbstractPasteTests {

	/**
	 * @see org.eclipse.papyrus.sysml.nattable.requirement.tests.paste.without.service.edit.AbstractPasteTests#getSourcePath()
	 *
	 * @return
	 */
	@Override
	protected String getSourcePath() {
		return "/resources/paste_tests/without_service_edit/bug443814/"; //$NON-NLS-1$
	}

	@Test
	public void availableColorTest() throws Exception {
		
		StringBuilder builder = new StringBuilder(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX);
		builder.append("profile::Task::color"); //$NON-NLS-1$
		String wantedProperty = builder.toString();
		testOpenExistingTable("classTreeTable", " openTest"); //$NON-NLS-1$ //$NON-NLS-2$
		List<IAxis> iAxis = getTable().getCurrentColumnAxisProvider().getAxis();
		IAxis colorAxis = null;
		Object representedElement = null;
	
		for (IAxis current : iAxis) {
			representedElement = AxisUtils.getRepresentedElement(current);
			if (wantedProperty.equals(representedElement)){
				colorAxis = current;
				break;
			}
		}
		Assert.assertNotNull(colorAxis);
		Assert.assertNotNull(representedElement);
		
		UMLStereotypeSingleEnumerationComboBoxDataProvider provider = new UMLStereotypeSingleEnumerationComboBoxDataProvider(colorAxis, getTableManager());
		List<?> values = provider.getValues(iAxis.indexOf(colorAxis), 0);
		boolean findBlack  = false;
		boolean findRed = false;
		boolean findBlue = false;
		for(Object current : values){
			Assert.assertTrue(current instanceof EEnumLiteral);
			EEnumLiteral lit = (EEnumLiteral) current;
			if(lit.getLiteral().equals("black")){ //$NON-NLS-1$
				findBlack = true;
			}
			if(lit.getLiteral().equals("red")){ //$NON-NLS-1$
				findRed = true;
			}
			if(lit.getLiteral().equals("blue")){ //$NON-NLS-1$
				findBlue = true;
			}
		}
		
		
		Assert.assertTrue(findBlack);
		Assert.assertTrue(findRed);
		Assert.assertTrue(findBlue);
	}

	@Test
	public void availablePriorityTest() throws Exception {
		StringBuilder builder = new StringBuilder(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX);
		builder.append("profile::Task::p"); //$NON-NLS-1$
		String wantedProperty = builder.toString();
		testOpenExistingTable("classTreeTable", " openTest"); //$NON-NLS-1$ //$NON-NLS-2$
		List<IAxis> iAxis = getTable().getCurrentColumnAxisProvider().getAxis();
		IAxis priorityAxis = null;
		Object representedElement = null;
	
		for (IAxis current : iAxis) {
			representedElement = AxisUtils.getRepresentedElement(current);
			if (wantedProperty.equals(representedElement)){
				priorityAxis = current;
				break;
			}
		}
		Assert.assertNotNull(priorityAxis);
		Assert.assertNotNull(representedElement);
		
		UMLStereotypeSingleEnumerationComboBoxDataProvider provider = new UMLStereotypeSingleEnumerationComboBoxDataProvider(priorityAxis, getTableManager());
		List<?> values = provider.getValues(iAxis.indexOf(priorityAxis), 0);
		boolean findHight  = false;
		boolean findMedium = false;
		boolean findLow = false;
		for(Object current : values){
			Assert.assertTrue(current instanceof EEnumLiteral);
			EEnumLiteral lit = (EEnumLiteral) current;
			if(lit.getLiteral().equals("hight")){ //$NON-NLS-1$
				findHight = true;
			}
			if(lit.getLiteral().equals("medium")){ //$NON-NLS-1$
				findMedium = true;
			}
			if(lit.getLiteral().equals("low")){ //$NON-NLS-1$
				findLow = true;
			}
		}
		
		
		Assert.assertTrue(findHight);
		Assert.assertTrue(findMedium);
		Assert.assertTrue(findLow);
	}

	@Test
	public void availableVisibilityTest() throws Exception {
		testOpenExistingTable("classTreeTable", " openTest"); //$NON-NLS-1$ //$NON-NLS-2$
		List<IAxis> iAxis = getTable().getCurrentColumnAxisProvider().getAxis();
		IAxis visibilityAxis = null;
		Object representedElement = null;
		for (IAxis current : iAxis) {
			representedElement = AxisUtils.getRepresentedElement(current);
			if (UMLPackage.eINSTANCE.getNamedElement_Visibility() == representedElement) {
				visibilityAxis = current;
				break;
			}
		}
		Assert.assertNotNull(visibilityAxis);
		Assert.assertNotNull(representedElement);
		EEnumComboBoxDataProvider provider = new EEnumComboBoxDataProvider((EEnum) UMLPackage.eINSTANCE.getNamedElement_Visibility().getEType());
		List<?> values = provider.getValues(iAxis.indexOf(visibilityAxis), 0);
		Assert.assertEquals(4, values.size());
		Assert.assertTrue(values.contains(VisibilityKind.PACKAGE_LITERAL));
		Assert.assertTrue(values.contains(VisibilityKind.PUBLIC_LITERAL));
		Assert.assertTrue(values.contains(VisibilityKind.PRIVATE_LITERAL));
		Assert.assertTrue(values.contains(VisibilityKind.PROTECTED_LITERAL));

	}

}

Back to the top