Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 113590
Collapse All | Expand All

(-)src-hierarchy/org/eclipse/hyades/models/hierarchy/util/EMFUtil.java (-1 / +1 lines)
Lines 117-127 Link Here
117
			changedResources.add(object.eResource());
117
			changedResources.add(object.eResource());
118
118
119
		deleteList.add(object);
119
		deleteList.add(object);
120
		object.eAdapters().clear();
121
		for (int i = deleteList.size() - 1; i >= 0; i--) {
120
		for (int i = deleteList.size() - 1; i >= 0; i--) {
122
			unsetAllFeatures((EObject) deleteList.get(i));
121
			unsetAllFeatures((EObject) deleteList.get(i));
123
		}
122
		}
124
		deleteList.clear();
123
		deleteList.clear();
124
		object.eAdapters().clear();
125
125
126
		return changedResources;
126
		return changedResources;
127
	}
127
	}
(-)src-test/org/eclipse/hyades/models/common/facades/behavioral/impl/HyadesBVRInteractionAdapter.java (-131 lines)
Lines 95-119 Link Here
95
					BVRInteractionImpl interaction = (BVRInteractionImpl) notification.getNotifier();
95
					BVRInteractionImpl interaction = (BVRInteractionImpl) notification.getNotifier();
96
					BVRInteractionFragmentImpl fragment = null;
96
					BVRInteractionFragmentImpl fragment = null;
97
					List fragments = null;
97
					List fragments = null;
98
//					TPFBehaviorImpl implementor = null;
99
//					BVRLifelineImpl selfLifeline = null;
100
					BVRLifelineImpl lifeline = null;
98
					BVRLifelineImpl lifeline = null;
101
					Iterator iter = null;
99
					Iterator iter = null;
102
					List lifelines = null;
100
					List lifelines = null;
103
					Iterator itLifelines = null;
101
					Iterator itLifelines = null;
104
//					TPFTestSuiteImpl testSuite = null;
105
					
102
					
106
					switch(eventType) {	
103
					switch(eventType) {	
107
						case Notification.ADD:
104
						case Notification.ADD:
108
							fragment = (BVRInteractionFragmentImpl)notification.getNewValue();	
105
							fragment = (BVRInteractionFragmentImpl)notification.getNewValue();	
109
							HyadesUtil.INSTANCE.createSUTInstances(interaction, fragment);
106
							HyadesUtil.INSTANCE.createSUTInstances(interaction, fragment);
110
111
							// (Add the self lifeline to the the InteractionFragment's lifeline collection.
112
							// (Convention -- for MessageEnd, caller lifeline is first, then invoked lifeline.)					
113
//							implementor = (TPFBehaviorImpl)interaction.getBehavior();
114
//							selfLifeline = implementor.getSelfLifeline();
115
							// Add it to the front of the collection
116
//							fragment.getLifelines().add(0,selfLifeline); 
117
							
107
							
118
							if(fragment instanceof ITestInvocation)
108
							if(fragment instanceof ITestInvocation)
119
							{
109
							{
Lines 130-189 Link Here
130
							}
120
							}
131
							
121
							
132
							break;
122
							break;
133
						case Notification.ADD_MANY:
134
							fragments = (List)notification.getNewValue();
135
							iter = fragments.iterator();
136
							while (iter.hasNext()) {
137
								fragment = (BVRInteractionFragmentImpl)iter.next();
138
139
								// (Add the self lifeline to the the InteractionFragment's lifeline collection.
140
								// (Convention -- for MessageEnd, caller lifeline is first, then invoked lifeline.)					
141
//								implementor = (TPFBehaviorImpl)interaction.getBehavior();
142
//								selfLifeline = implementor.getSelfLifeline();
143
								// Add it to the front of the collection
144
//								fragment.getLifelines().add(0,selfLifeline); 
145
146
								HyadesUtil.INSTANCE.createSUTInstances(interaction, fragment);
147
								if(fragment instanceof ITestInvocation)
148
								{
149
									ITestSuite test = HyadesUtil.INSTANCE.getTestSuite(((ITestInvocation)fragment).getInvokedTest());
150
									ITestSuite owner = (ITestSuite) EcoreUtil.getRootContainer(interaction);
151
							 	
152
									if(owner != null && test != null && !owner.getId().equals(test.getId()))
153
									{
154
										if(!HyadesUtil.INSTANCE.containsSuite(owner.getIReferencedSuites(), test))
155
										{
156
											owner.getIReferencedSuites().add(test);
157
										}
158
									}
159
								}
160
							}
161
							break;
162
						case Notification.REMOVE:
123
						case Notification.REMOVE:
163
							fragment = (BVRInteractionFragmentImpl)notification.getOldValue();
124
							fragment = (BVRInteractionFragmentImpl)notification.getOldValue();
164
							if(fragment instanceof ITestInvocation)
165
							{
166
								ITestSuite test = null;
167
								BVRExecutionOccurrenceImpl executionOccurrenceImpl = (BVRExecutionOccurrenceImpl)fragment;
168
								if((executionOccurrenceImpl.getOtherBehavior() != null) && (executionOccurrenceImpl.getOtherBehavior().eIsProxy()))
169
								{
170
									TPFBehavior behavior = (TPFBehavior)EcoreUtil.resolve(((BVRExecutionOccurrenceImpl)fragment).getOtherBehavior(), interaction.eResource().getResourceSet());
171
									if(behavior != null)
172
									{
173
										test = HyadesUtil.INSTANCE.getTestSuite((ITest)behavior.getTest());
174
									}
175
								}
176
								else
177
								{
178
									test = HyadesUtil.INSTANCE.getTestSuite(((ITestInvocation)fragment).getInvokedTest());
179
								}
180
								ITestSuite owner = HyadesUtil.INSTANCE.getTestSuite(((TPFBehaviorImpl)interaction.getBehavior()).getOwner());
181
									
182
								if(owner != null && test != null && !hasSuite(interaction.getInteractionFragments(), test, interaction))
183
								{
184
									owner.getIReferencedSuites().remove(test);
185
								}
186
							}
187
125
188
							// Iterate over all lifelines in the interaction, and remove 
126
							// Iterate over all lifelines in the interaction, and remove 
189
							// any references to this interaction fragment from each of them.
127
							// any references to this interaction fragment from each of them.
Lines 195-273 Link Here
195
								lifeline.getInteractionFragments().remove(fragment);
133
								lifeline.getInteractionFragments().remove(fragment);
196
							}
134
							}
197
							break;
135
							break;
198
						case Notification.REMOVE_MANY:
199
							fragments = (List)notification.getOldValue();
200
							iter = fragments.iterator();
201
							while (iter.hasNext()) {
202
								fragment = (BVRInteractionFragmentImpl)iter.next();
203
								if(fragment instanceof ITestInvocation)
204
								{
205
									ITestSuite test = null;
206
									if(((BVRExecutionOccurrenceImpl)fragment).getOtherBehavior().eIsProxy())
207
									{
208
										TPFBehavior behavior = (TPFBehavior)EcoreUtil.resolve(((BVRExecutionOccurrenceImpl)fragment).getOtherBehavior(), interaction.eResource().getResourceSet());
209
										if(behavior != null)
210
										{
211
											test = HyadesUtil.INSTANCE.getTestSuite((ITest)behavior.getTest());
212
										}
213
									}
214
									else
215
									{
216
										test = HyadesUtil.INSTANCE.getTestSuite(((ITestInvocation)fragment).getInvokedTest());
217
									}
218
									ITestSuite owner = HyadesUtil.INSTANCE.getTestSuite(((TPFBehaviorImpl)interaction.getBehavior()).getOwner());
219
									
220
									if(owner != null && test != null && !hasSuite(interaction.getInteractionFragments(), test, interaction))
221
									{
222
										owner.getIReferencedSuites().remove(test);
223
									}
224
								}
225
226
								// Iterate over all lifelines in the interaction, and remove 
227
								// any references to this interaction fragment from each of them.
228
								lifelines = interaction.getLifelines();
229
								itLifelines = lifelines.iterator();
230
								while ( itLifelines.hasNext() )
231
								{
232
									lifeline = (BVRLifelineImpl)itLifelines.next();
233
									lifeline.getInteractionFragments().remove(fragment);
234
								}
235
							}											
236
							break;
237
					}					
136
					}					
238
				break;
137
				break;
239
			}			
138
			}			
240
		}
139
		}
241
	}
140
	}
242
		
141
		
243
	private boolean hasSuite(List otherInteractionFragments, ITestSuite suite, BVRInteraction interaction)
244
	{
245
		Iterator iter = otherInteractionFragments.iterator();
246
		while(iter.hasNext())
247
		{
248
			BVRInteractionFragmentImpl fragment = (BVRInteractionFragmentImpl)iter.next();
249
			if(fragment instanceof BVRExecutionOccurrenceImpl)
250
			{
251
				ITestSuite test = null;
252
				if(((BVRExecutionOccurrenceImpl)fragment).getOtherBehavior().eIsProxy())
253
				{
254
					TPFBehavior behavior = (TPFBehavior)EcoreUtil.resolve(((BVRExecutionOccurrenceImpl)fragment).getOtherBehavior(), interaction.eResource().getResourceSet());
255
					if(behavior != null)
256
					{
257
						test = HyadesUtil.INSTANCE.getTestSuite((ITest)behavior.getTest());
258
					}
259
				}
260
				else
261
				{
262
					test = HyadesUtil.INSTANCE.getTestSuite(((ITestInvocation)fragment).getInvokedTest());
263
				}
264
	
265
				if(test.getId().equals(suite.getId()))
266
				{
267
					return true;
268
				}
269
			}
270
		}
271
		return false;
272
	}
273
}
142
}
(-)src-test/org/eclipse/hyades/models/common/facades/behavioral/impl/FacadeResourceImpl.java (-7 / +17 lines)
Lines 36-41 Link Here
36
import org.eclipse.emf.ecore.xmi.XMLResource;
36
import org.eclipse.emf.ecore.xmi.XMLResource;
37
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
37
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
38
import org.eclipse.hyades.models.common.fragments.Common_Behavior_FragmentsPackage;
38
import org.eclipse.hyades.models.common.fragments.Common_Behavior_FragmentsPackage;
39
import org.eclipse.hyades.models.common.interactions.Common_Behavior_InteractionsPackage;
39
import org.eclipse.hyades.models.common.testprofile.Common_TestprofilePackage;
40
import org.eclipse.hyades.models.common.testprofile.Common_TestprofilePackage;
40
import org.eclipse.hyades.models.common.util.FileUtil;
41
import org.eclipse.hyades.models.common.util.FileUtil;
41
import org.eclipse.hyades.models.hierarchy.util.HierarchyURIConverterImpl;
42
import org.eclipse.hyades.models.hierarchy.util.HierarchyURIConverterImpl;
Lines 137-142 Link Here
137
			HyadesCommon_TestprofileAdapterFactory adaptorFactory = new HyadesCommon_TestprofileAdapterFactory();
138
			HyadesCommon_TestprofileAdapterFactory adaptorFactory = new HyadesCommon_TestprofileAdapterFactory();
138
			adaptorFactory.adapt(arg0, Common_TestprofilePackage.eINSTANCE.getTPFTestComponent()); 
139
			adaptorFactory.adapt(arg0, Common_TestprofilePackage.eINSTANCE.getTPFTestComponent()); 
139
		}
140
		}
141
		
142
		if(arg0.eClass().equals(Common_Behavior_InteractionsPackage.eINSTANCE.getBVRExecutionOccurrence()))
143
		{
144
			TptpCommon_BVRExecutionOccurrenceAdapterFactory adaptorFactory = new TptpCommon_BVRExecutionOccurrenceAdapterFactory();
145
			adaptorFactory.adapt(arg0, Common_Behavior_InteractionsPackage.eINSTANCE.getBVRExecutionOccurrence());
146
		}
147
		
140
	}
148
	}
141
149
142
	/* (non-Javadoc)
150
	/* (non-Javadoc)
Lines 165-177 Link Here
165
		options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
173
		options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
166
		
174
		
167
/*		try {
175
/*		try {
168
			if ( inputStream.available() == 0 )
176
				if ( inputStream.available() == 0 )
177
					return;
178
			}
179
			catch (IOException ex)
180
			{
169
				return;
181
				return;
170
		}
182
			}
171
		catch (IOException ex)
172
		{
173
			return;
174
		}
175
*/	
183
*/	
176
		if ( inputStream instanceof ZipInputStream )
184
		if ( inputStream instanceof ZipInputStream )
177
		{
185
		{
Lines 183-189 Link Here
183
			try {
191
			try {
184
				FileOutputStream file = new FileOutputStream(tempResourceContents);
192
				FileOutputStream file = new FileOutputStream(tempResourceContents);
185
				BufferedOutputStream bufFile = new BufferedOutputStream(file);
193
				BufferedOutputStream bufFile = new BufferedOutputStream(file);
186
	
194
187
				int bufSize = 65536;
195
				int bufSize = 65536;
188
				byte[] readBuffer = new byte[bufSize];
196
				byte[] readBuffer = new byte[bufSize];
189
				int count;
197
				int count;
Lines 384-387 Link Here
384
	protected URIConverter getURIConverter() {
392
	protected URIConverter getURIConverter() {
385
		return new HierarchyURIConverterImpl();
393
		return new HierarchyURIConverterImpl();
386
	}
394
	}
395
396
387
}
397
}
(-)src-test/org/eclipse/hyades/models/common/facades/behavioral/impl/TptpBVRExecutionOccurrenceAdapter.java (+142 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2007 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.models.common.facades.behavioral.impl;
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
import java.util.Set;
18
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.common.notify.impl.AdapterImpl;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.resource.Resource;
23
import org.eclipse.emf.ecore.util.EcoreUtil;
24
import org.eclipse.hyades.models.common.facades.behavioral.IImplementor;
25
import org.eclipse.hyades.models.common.facades.behavioral.ITest;
26
import org.eclipse.hyades.models.common.facades.behavioral.ITestInvocation;
27
import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite;
28
import org.eclipse.hyades.models.common.fragments.BVRInteraction;
29
import org.eclipse.hyades.models.common.fragments.Common_Behavior_FragmentsPackage;
30
import org.eclipse.hyades.models.common.fragments.impl.BVRInteractionImpl;
31
import org.eclipse.hyades.models.common.interactions.BVRExecutionOccurrence;
32
import org.eclipse.hyades.models.common.interactions.Common_Behavior_InteractionsPackage;
33
import org.eclipse.hyades.models.common.interactions.impl.BVRExecutionOccurrenceImpl;
34
import org.eclipse.hyades.models.common.interactions.impl.BVRInteractionFragmentImpl;
35
import org.eclipse.hyades.models.common.interactions.impl.BVRLifelineImpl;
36
import org.eclipse.hyades.models.common.testprofile.TPFBehavior;
37
import org.eclipse.hyades.models.common.testprofile.TPFTestSuite;
38
import org.eclipse.hyades.models.common.testprofile.impl.TPFBehaviorImpl;
39
import org.eclipse.hyades.models.common.testprofile.impl.TPFTestSuiteImpl;
40
import org.eclipse.hyades.models.hierarchy.util.ContainmentTraverser;
41
42
43
/**
44
 * @author jtoomey
45
 *
46
 */
47
public class TptpBVRExecutionOccurrenceAdapter extends AdapterImpl {
48
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.emf.common.notify.Adapter#isAdapterForType(java.lang.Object)
51
	 */
52
	public boolean isAdapterForType(Object obj) {
53
		if (obj instanceof EObject)
54
		{
55
		  return ((EObject)obj).eClass() == Common_Behavior_InteractionsPackage.eINSTANCE.getBVRExecutionOccurrence();
56
		}
57
		return false;
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
62
	 */
63
	public void notifyChanged(Notification notification) {
64
		
65
		if (notification.getEventType() == Notification.SET)
66
		{
67
			if (isLoading((EObject) notification.getNotifier()))
68
				return;
69
			
70
			switch (notification.getFeatureID(BVRExecutionOccurrence.class))
71
			{
72
				case Common_Behavior_InteractionsPackage.BVR_EXECUTION_OCCURRENCE__OTHER_BEHAVIOR:
73
					BVRExecutionOccurrence executionOccurrence = (BVRExecutionOccurrence) notification.getNotifier();
74
					ITestSuite invokedTestSuite = HyadesUtil.INSTANCE.getTestSuite(executionOccurrence.getInvokedTest());
75
76
					if (invokedTestSuite == null) {
77
				 		// The invocation is being removed -- clean up the referenced test suite collection
78
				 		ITestSuite notInvokedTestSuite = HyadesUtil.INSTANCE.getTestSuite(((TPFBehavior) notification.getOldValue()).getTest());
79
						ITestSuite notInvoker = (ITestSuite) EcoreUtil.getRootContainer(executionOccurrence);
80
					 	if(notInvoker != notInvokedTestSuite && notInvoker != null && notInvokedTestSuite != null && 
81
					 			!invokesTest(notInvoker, notInvokedTestSuite))
82
					 	{
83
							notInvoker.getIReferencedSuites().remove(notInvokedTestSuite);
84
					 	}
85
				 		
86
				 	}
87
				break;
88
			}			
89
		}
90
	}
91
92
	private boolean isLoading(EObject obj) {
93
		Resource res = obj.eResource();
94
		if (res != null && res instanceof FacadeResourceImpl) {
95
			return ((FacadeResourceImpl)res).isLoading();
96
		}
97
		return false;
98
	}
99
100
	private boolean invokesTest(ITestSuite notInvoker,
101
			final ITestSuite notInvokedTestSuite) {
102
		ArrayList roots = new ArrayList();
103
		roots.add(notInvoker);
104
		final MutableBoolean invokes = new MutableBoolean(false);
105
		
106
		ContainmentTraverser invokesTraverser = new ContainmentTraverser(roots) {
107
			protected boolean beforeChildren(EObject element) {
108
				if (element instanceof BVRExecutionOccurrence) {
109
					BVRExecutionOccurrence executionOccurrence = (BVRExecutionOccurrence) element;
110
					ITest test = executionOccurrence.getInvokedTest();
111
					if (test != null) {
112
						ITestSuite invokedTestSuite = HyadesUtil.INSTANCE.getTestSuite(test);
113
						if (invokedTestSuite.getId() == notInvokedTestSuite.getId()) {
114
							invokes.setState(true);
115
							return true;
116
						}
117
					}
118
				}
119
				return true;
120
			}
121
		};
122
		
123
		invokesTraverser.traverse();
124
		return invokes.getState();
125
	}
126
	
127
	private class MutableBoolean {
128
		private boolean state;
129
		
130
		public MutableBoolean (boolean state) {
131
			this.state = state; 
132
		}
133
		
134
		public void setState(boolean state) {
135
			this.state = state; 
136
		}
137
		
138
		public boolean getState() {
139
			return state;
140
		}
141
	}
142
}
(-)src-test/org/eclipse/hyades/models/common/facades/behavioral/impl/TptpCommon_BVRExecutionOccurrenceAdapterFactory.java (+34 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2007 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.models.common.facades.behavioral.impl;
13
14
import org.eclipse.emf.common.notify.Adapter;
15
import org.eclipse.hyades.models.common.interactions.util.Common_Behavior_InteractionsAdapterFactory;
16
17
/**
18
 * @author jtoomey
19
 *
20
 */
21
public class TptpCommon_BVRExecutionOccurrenceAdapterFactory extends
22
		Common_Behavior_InteractionsAdapterFactory {
23
24
	public TptpCommon_BVRExecutionOccurrenceAdapterFactory() {
25
		super();
26
	}
27
28
	public Adapter createBVRExecutionOccurrenceAdapter() {
29
		return new TptpBVRExecutionOccurrenceAdapter();
30
	}
31
	
32
	
33
34
}

Return to bug 113590