Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d1dfacd8071419a37b5537758740a87730caa63f (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
/*****************************************************************************
 * Copyright (c) 2009, 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:
 *  Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
 *  Christian W. Damus (CEA) - bug 422257
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.requirements.tests;

import static org.junit.Assert.fail;

import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.eclipse.papyrus.sysml.requirements.Requirement;
import org.eclipse.papyrus.sysml.requirements.RequirementsFactory;
import org.eclipse.papyrus.sysml.requirements.RequirementsPackage;
import org.eclipse.papyrus.sysml.utils.SysMLTestResources;
import org.eclipse.uml2.uml.Abstraction;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * <!-- begin-user-doc --> A test case for the model object '<em><b>Test Case</b></em>'. <!--
 * end-user-doc -->
 * <p>
 * The following features are tested:
 * <ul>
 * <li>{@link org.eclipse.papyrus.sysml.requirements.TestCase#getVerifies() <em>Verifies</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TestCaseTest extends AbstractPapyrusTest {

	@Rule
	public final HouseKeeper houseKeeper = new HouseKeeper();
	
	protected org.eclipse.papyrus.sysml.requirements.TestCase fixture = null;

	// ////////////////////////////////////////////////////////////////////
	protected Model model = null;

	protected Requirement verified1_req = null;

	protected Requirement verified2_req = null;

	protected org.eclipse.papyrus.sysml.requirements.TestCase testCase0 = null;

	protected org.eclipse.papyrus.sysml.requirements.TestCase testCase1 = null;

	protected org.eclipse.papyrus.sysml.requirements.TestCase testCase2 = null;

	// ////////////////////////////////////////////////////////////////////

	/**
	 * Returns the fixture for this Test Case test case. <!-- begin-user-doc --> <!-- end-user-doc
	 * -->
	 *
	 * @generated
	 */
	protected org.eclipse.papyrus.sysml.requirements.TestCase getFixture() {
		return fixture;
	}

	/**
	 * Sets the fixture for this Test Case test case.
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 *
	 * @generated
	 */
	protected void setFixture(org.eclipse.papyrus.sysml.requirements.TestCase fixture) {
		this.fixture = fixture;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 *
	 * @see junit.framework.TestCase#setUp()
	 * @generated NOT
	 */
	@Before
	public void setUp() throws Exception {
		setFixture(RequirementsFactory.eINSTANCE.createTestCase());

		// Prepare test
		model = SysMLTestResources.createSysMLModel(houseKeeper.createResourceSet());
		if(model == null) {
			fail();
		}

		if(model.getAppliedProfiles().isEmpty()) {
			fail();
		}

		// ////////////////////////////////////////////////////////////////////
		// Prepare getVerifies test elements
		// ////////////////////////////////////////////////////////////////////

		Class verified1 = model.createOwnedClass("verified1", false);
		verified1_req = (Requirement)StereotypeApplicationHelper.INSTANCE.applyStereotype(verified1, RequirementsPackage.eINSTANCE.getRequirement());

		Class verified2 = model.createOwnedClass("verified2", false);
		verified2_req = (Requirement)StereotypeApplicationHelper.INSTANCE.applyStereotype(verified2, RequirementsPackage.eINSTANCE.getRequirement());

		Class testClass = model.createOwnedClass("testClass", false);
		Operation op0 = testClass.createOwnedOperation("op0", null, null, null);
		Operation op1 = testClass.createOwnedOperation("op1", null, null, null);
		Operation op2 = testClass.createOwnedOperation("op2", null, null, null);

		testCase0 = (org.eclipse.papyrus.sysml.requirements.TestCase)StereotypeApplicationHelper.INSTANCE.applyStereotype(op0, RequirementsPackage.eINSTANCE.getTestCase());
		testCase1 = (org.eclipse.papyrus.sysml.requirements.TestCase)StereotypeApplicationHelper.INSTANCE.applyStereotype(op1, RequirementsPackage.eINSTANCE.getTestCase());
		testCase2 = (org.eclipse.papyrus.sysml.requirements.TestCase)StereotypeApplicationHelper.INSTANCE.applyStereotype(op2, RequirementsPackage.eINSTANCE.getTestCase());

		// Add "Verify" (Abstraction)
		// testCase1, testCase2 -> verified1
		// testCase2 -> verified2
		Abstraction t1_v1 = UMLFactory.eINSTANCE.createAbstraction();
		t1_v1.getClients().add(op1);
		t1_v1.getSuppliers().add(verified1);
		model.getPackagedElements().add(t1_v1);
		StereotypeApplicationHelper.INSTANCE.applyStereotype(t1_v1, RequirementsPackage.eINSTANCE.getVerify());

		Abstraction t1_v2 = UMLFactory.eINSTANCE.createAbstraction();
		t1_v2.getClients().add(op1);
		t1_v2.getSuppliers().add(verified2);
		model.getPackagedElements().add(t1_v2);
		StereotypeApplicationHelper.INSTANCE.applyStereotype(t1_v2, RequirementsPackage.eINSTANCE.getVerify());

		Abstraction t2_v2 = UMLFactory.eINSTANCE.createAbstraction();
		t2_v2.getClients().add(op2);
		t2_v2.getSuppliers().add(verified2);
		model.getPackagedElements().add(t2_v2);
		StereotypeApplicationHelper.INSTANCE.applyStereotype(t2_v2, RequirementsPackage.eINSTANCE.getVerify());

		// ////////////////////////////////////////////////////////////////////
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 *
	 * @see junit.framework.TestCase#tearDown()
	 * @generated
	 */
	@After
	public void tearDown() throws Exception {
		setFixture(null);
	}

	/**
	 * Tests the '{@link org.eclipse.papyrus.sysml.requirements.TestCase#getVerifies()
	 * <em>Verifies</em>}' feature getter. <!-- begin-user-doc --> <!-- end-user-doc -->
	 *
	 * @see org.eclipse.papyrus.sysml.requirements.TestCase#getVerifies()
	 * @generated NOT
	 */
	@Test
	public void testGetVerifies() {

		// testCase0 -> []
		if(!testCase0.getVerifies().isEmpty()) {
			fail();
		}

		// testCase1 -> [verified1_req, verified2_req]
		if(!testCase1.getVerifies().contains(verified1_req)) {
			fail();
		}
		if(!testCase1.getVerifies().contains(verified2_req)) {
			fail();
		}

		// testCase2 -> [verified2_req]
		if(!testCase2.getVerifies().contains(verified2_req)) {
			fail();
		}

	}

} // TestCaseTest

Back to the top