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
|
/*******************************************************************************
* Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf.
* 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:
* Michael Jastram - initial API and implementation
******************************************************************************/
package org.eclipse.rmf.reqif10.provider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.rmf.pror.reqif10.provider.VirtualSpecObjectItemProvider;
import org.eclipse.rmf.pror.reqif10.util.ProrUtil;
import org.eclipse.rmf.reqif10.ReqIF;
import org.eclipse.rmf.reqif10.ReqIF10Factory;
import org.eclipse.rmf.reqif10.ReqIF10Package;
import org.eclipse.rmf.reqif10.SpecElementWithAttributes;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.SpecObject;
import org.eclipse.rmf.reqif10.SpecType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* A test case for the model object '<em><b>Spec Object</b></em>'.
*/
public class SpecObjectTest extends SpecElementWithAttributesTest {
/**
* Returns the fixture for this Spec Object test case.
*/
@Override
protected SpecObject getFixture() {
return (SpecObject)fixture;
}
/**
* @see junit.framework.TestCase#setUp()
*/
@Before
public void setUp() throws Exception {
setFixture(ReqIF10Factory.eINSTANCE.createSpecObject());
setupReqif();
}
/**
* @see junit.framework.TestCase#tearDown()
*/
@After
public void tearDown() throws Exception {
setFixture(null);
}
private ReqIF reqif;
private SpecObject specObject;
private SpecHierarchy specHierarchy;
@Before
public void setupReqif() throws URISyntaxException {
reqif = getTestReqif("simple.reqif");
specObject = reqif.getCoreContent().getSpecObjects().get(0);
specHierarchy = reqif.getCoreContent().getSpecifications().get(0).getChildren().get(0);
// Just to make sure that the test file is correct
assertEquals(specObject, specHierarchy.getObject());
}
/**
* Ensure that the SpecObject is notified if the AttributeValue changes.
*/
@Test public void testSpecObjectNotificationValueChanged() {
ItemProviderAdapter ip = getItemProvider(specObject);
ip.addListener(listener);
assertEquals(0, notifications.size());
ProrUtil.setTheValue(specObject.getValues().get(0), "newDescription", editingDomain);
assertEquals(1, notifications.size());
assertEquals(specObject, notifications.get(0).getNotifier());
assertEquals(ReqIF10Package.Literals.SPEC_ELEMENT_WITH_ATTRIBUTES__VALUES, notifications.get(0).getFeature());
}
/**
* Ensure that the SpecHierarchy is notified if the AttributeValue changes.
*/
@Test public void testSpecHierarchyNotificationValueChanged() {
adapterFactory.adapt(specObject, IItemLabelProvider.class);
ItemProviderAdapter ip = getItemProvider(specHierarchy);
ip.addListener(listener);
assertEquals(0, notifications.size());
ProrUtil.setTheValue(specObject.getValues().get(0), "newDescription", editingDomain);
assertEquals(1, notifications.size());
assertEquals(specHierarchy, notifications.get(0).getNotifier());
assertEquals(ReqIF10Package.Literals.SPEC_HIERARCHY__OBJECT, notifications.get(0).getFeature());
}
@Test
public void testParentIsVirtual() throws URISyntaxException {
reqif = getTestReqif("simple.reqif");
// Required for generating the Virtual Element lazily.
getItemProvider(reqif.getCoreContent()).getChildren(reqif.getCoreContent());
specObject = reqif.getCoreContent().getSpecObjects().get(0);
ItemProviderAdapter ip = ProrUtil.getItemProvider(adapterFactory, specObject);
assertTrue(ip.getParent(specObject) instanceof VirtualSpecObjectItemProvider);
}
@Override
public void addFixtureToReqIf(ReqIF reqif) {
reqif.getCoreContent().getSpecObjects().add(getFixture());
}
@Override
protected Set<String> getStandardPropertyNames() {
return new HashSet<String>(Arrays.asList(STANDARD_PROPERTIES));
}
@Override
protected void setFixtureType(SpecElementWithAttributes specElement,
SpecType specType) {
setViaCommand(specElement, ReqIF10Package.Literals.SPEC_OBJECT__TYPE, specType);
}
@Override
protected SpecType getSpecTypeInstance() {
return ReqIF10Factory.eINSTANCE.createSpecObjectType();
}
} //SpecObjectTest
|