Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 250265 Details for
Bug 458151
Unstability on resource reload
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
JUnit test corresponding to comment 3
EMFUnloadWithStrangeProxyURITests.java (text/x-java), 8.30 KB, created by
Laurent Redor
on 2015-01-27 09:15:45 EST
(
hide
)
Description:
JUnit test corresponding to comment 3
Filename:
MIME Type:
Creator:
Laurent Redor
Created:
2015-01-27 09:15:45 EST
Size:
8.30 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2015 THALES GLOBAL SERVICES. > * 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: > * Obeo - initial API and implementation > *******************************************************************************/ >package org.eclipse.sirius.tests.unit.common; > >import java.io.File; >import java.io.IOException; >import java.util.ArrayList; >import java.util.Collection; > >import junit.framework.TestCase; > >import org.eclipse.emf.common.util.URI; >import org.eclipse.emf.ecore.EClass; >import org.eclipse.emf.ecore.EPackage; >import org.eclipse.emf.ecore.EReference; >import org.eclipse.emf.ecore.EStructuralFeature; >import org.eclipse.emf.ecore.EcoreFactory; >import org.eclipse.emf.ecore.EcorePackage; >import org.eclipse.emf.ecore.resource.Resource; >import org.eclipse.emf.ecore.resource.ResourceSet; >import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; >import org.eclipse.emf.ecore.util.EcoreUtil; >import org.eclipse.emf.edit.command.AddCommand; >import org.eclipse.emf.edit.command.RemoveCommand; >import org.eclipse.emf.transaction.RecordingCommand; >import org.eclipse.emf.transaction.TransactionalEditingDomain; >import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.FactoryImpl; > >/** > * Class containing some tests to reveal the "problem" with EMF CrossReferencer > * after a unload/reload of fragmented resource. > * > * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> > */ >public class EMFUnloadWithStrangeProxyURITests extends TestCase { > > private TransactionalEditingDomain editingDomain; > > public void testURIAfterUnloadWithoutFragment() { > System.out.println("EMFUnloadWithStrangeProxyURITests.testURIAfterUnloadWithoutFragment()"); > ECrossReferenceAdapter crossRefencer = new ECrossReferenceAdapter(); > Resource reloadedResourceB = init(crossRefencer, false); > EClass reloadedEClassB = (EClass) ((EPackage) reloadedResourceB.getContents().get(0)).getESubpackages().get(0).getESubpackages().get(0).getEClassifier("ClassB"); > assertEquals("We should have one cross reference after unload/reload with cross reference resolution.", 1, getReferencesTo(reloadedEClassB, crossRefencer, true).size()); > > } > > public void testURIAfterUnloadWithFragment() { > System.out.println("EMFUnloadWithStrangeProxyURITests.testURIAfterUnloadWithFragment()"); > /* Create a specific cross referencer */ > ECrossReferenceAdapter crossRefencer = new ECrossReferenceAdapter(); > Resource reloadedResourceB = init(crossRefencer, true); > EClass reloadedEClassB = (EClass) ((EPackage) reloadedResourceB.getContents().get(0)).getESubpackages().get(0).getEClassifier("ClassB"); > assertEquals("We should have one cross reference after unload/reload with cross reference resolution.", 1, getReferencesTo(reloadedEClassB, crossRefencer, true).size()); > } > > protected Resource init(ECrossReferenceAdapter crossRefencer, boolean control) { > /* create a resource set and add the crossRefencer on it. */ > ResourceSet rset = new ResourceSetImpl(); > rset.eAdapters().add(crossRefencer); > /* create an editing domain */ > editingDomain = FactoryImpl.INSTANCE.createEditingDomain(rset); > > /* Initialize the model B */ > final EPackage ePackageB = EcoreFactory.eINSTANCE.createEPackage(); > ePackageB.setName("RootB"); > final EPackage ePackageB1 = EcoreFactory.eINSTANCE.createEPackage(); > ePackageB1.setName("b1"); > ePackageB.getESubpackages().add(ePackageB1); > final EPackage ePackageB2 = EcoreFactory.eINSTANCE.createEPackage(); > ePackageB2.setName("b2"); > ePackageB1.getESubpackages().add(ePackageB2); > final EClass eClassB = EcoreFactory.eINSTANCE.createEClass(); > eClassB.setName("ClassB"); > ePackageB2.getEClassifiers().add(eClassB); > > /* create resource and and add it initialized model */ > final URI fileBUri = URI.createFileURI(new File("B.ecore").getAbsolutePath()); > final Resource rsB = rset.createResource(fileBUri); > editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) { > > @Override > protected void doExecute() { > rsB.getContents().add(ePackageB); > } > > }); > try { > rsB.save(null); > } catch (IOException e) { > e.printStackTrace(); > } > > Resource rsB1 = null; > if (control) { > // Control ePackageB1 > final URI fileB1Uri = URI.createFileURI(new File("B1.ecore").getAbsolutePath()); > rsB1 = rset.createResource(fileB1Uri); > EcoreUtil.resolveAll(rset); > editingDomain.getCommandStack().execute(new RemoveCommand(editingDomain, rsB.getContents(), ePackageB1)); > editingDomain.getCommandStack().execute(new AddCommand(editingDomain, rsB1.getContents(), ePackageB1)); > try { > rsB.save(null); > rsB1.save(null); > } catch (IOException e) { > e.printStackTrace(); > } > } > > /* initialize the model A */ > final EPackage ePackageA = EcoreFactory.eINSTANCE.createEPackage(); > ePackageA.setName("RootA"); > final EClass eClassA = EcoreFactory.eINSTANCE.createEClass(); > eClassA.setName("ClassA"); > final EReference refToB = EcoreFactory.eINSTANCE.createEReference(); > refToB.setName("refToB"); > refToB.setEType(eClassB); > eClassA.getEStructuralFeatures().add(refToB); > ePackageA.getEClassifiers().add(eClassA); > > /* create resource and and add it initialized model */ > final URI fileAUri = URI.createFileURI(new File("A.ecore").getAbsolutePath()); > final Resource rsA = rset.createResource(fileAUri); > editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) { > > @Override > protected void doExecute() { > rsA.getContents().add(ePackageA); > } > > }); > try { > rsA.save(null); > } catch (IOException e) { > e.printStackTrace(); > } > assertEquals("We should have one cross reference before unload/reload.", 1, getReferencesTo(eClassB, crossRefencer, false).size()); > Resource resourceToUnloadAndReload = rsB; > if (control) { > resourceToUnloadAndReload = rsB1; > } > // Unload and reload the resource B > try { > System.out.println("URI of eType of the reference before the unload of resource B: " + EcoreUtil.getURI(refToB.getEType())); > resourceToUnloadAndReload.unload(); > System.out.println("URI of eType of the reference after the unload of resource B: " + EcoreUtil.getURI(refToB.getEType())); > resourceToUnloadAndReload.load(null); > return resourceToUnloadAndReload; > } catch (IOException e) { > fail("Unload/reload of resource B.ecore failed: " + e.getMessage()); > } > return null; > } > > /** > * Get the {@link EReference eReferences} that have <code>type</code> as > * EType. > * > * @param type > * The searched EType > * @param crossReferencer > * The cross referencer to use. > * @param resolve > * Resolve proxy crossReference to this <code>type</code> > * > * @return The list of {@link EReference eReferences} that have > * <code>type</code> as EType. > */ > public Collection<EReference> getReferencesTo(EClass type, ECrossReferenceAdapter crossReferencer, boolean resolve) { > Collection<EReference> crossReferenceResult = new ArrayList<EReference>(); > for (EStructuralFeature.Setting setting : crossReferencer.getInverseReferences(type, resolve)) { > if (EcorePackage.Literals.EREFERENCE.isInstance(setting.getEObject()) && setting.getEStructuralFeature() == EcorePackage.Literals.ETYPED_ELEMENT__ETYPE) { > crossReferenceResult.add((EReference) setting.getEObject()); > } > } > return crossReferenceResult; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 458151
:
250148
|
250189
|
250265
|
250268