Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Bug: SetCommand changes order of elements in collection
Bug: SetCommand changes order of elements in collection [message #422648] Thu, 11 September 2008 17:23 Go to next message
Andreas Voss is currently offline Andreas VossFriend
Messages: 51
Registered: July 2009
Member
Hi all,

I have filed a bug for this too (247048). The test tries to change the
eStructuralFeatures of an EClass instance via the SetCommand. In the
Result, the order of last two EAttributes is swapped, the test fails
with "expected:<[a1, b1, b2, b3, a2]> but was:<[a1, b1, b2, a2, b3]>"


package org.eclipse.bugs;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.EAttributeImpl;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
import org.junit.Before;
import org.junit.Test;

/**
* the following test fails
* expected:<[a1, b1, b2, b3, a2]> but was:<[a1, b1, b2, a2, b3]>
*
* @author av
*
*/
public class SetCommandBug {

private CommandStack commandStack;
private EditingDomain domain;

@Before
public void setUp() {
AdapterFactory adapterFactory = new
ReflectiveItemProviderAdapterFactory();
commandStack = new BasicCommandStack();
domain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);

}

@Test
public void testSetCommand() {
EClass eclass = EcoreFactory.eINSTANCE.createEClass();
EAttribute a1 = createAttribute("a1");
EAttribute a2 = createAttribute("a2");
eclass.getEStructuralFeatures().add(a1);
eclass.getEStructuralFeatures().add(a2);

List<EAttribute> list = new ArrayList<EAttribute>();
list.add(a1);
list.add(createAttribute("b1"));
list.add(createAttribute("b2"));
list.add(createAttribute("b3"));
list.add(a2);

Command command = SetCommand.create(domain, eclass,
EcorePackage.eINSTANCE
.getEClass_EStructuralFeatures(), list);
commandStack.execute(command);

assertEquals(list.toString(), eclass.getEAttributes().toString());
}


private EAttribute createAttribute(String name) {
// just to make toString() more concise
EAttribute attribute = new EAttributeImpl() {
@Override
public String toString() {
return name;
}
};
attribute.setName(name);
return attribute;
}

}
Re: Bug: SetCommand changes order of elements in collection [message #422650 is a reply to message #422648] Thu, 11 September 2008 18:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30810
Registered: July 2009
Senior Member
Andreas,

Thanks so much for the simple test case! Hopefully the patch I've
attached does the trick.



Andreas Voss wrote:
> Hi all,
>
> I have filed a bug for this too (247048). The test tries to change the
> eStructuralFeatures of an EClass instance via the SetCommand. In the
> Result, the order of last two EAttributes is swapped, the test fails
> with "expected:<[a1, b1, b2, b3, a2]> but was:<[a1, b1, b2, a2, b3]>"
>
>
> package org.eclipse.bugs;
>
> import static org.junit.Assert.assertEquals;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.emf.common.command.BasicCommandStack;
> import org.eclipse.emf.common.command.Command;
> import org.eclipse.emf.common.command.CommandStack;
> import org.eclipse.emf.common.notify.AdapterFactory;
> import org.eclipse.emf.ecore.EAttribute;
> import org.eclipse.emf.ecore.EClass;
> import org.eclipse.emf.ecore.EcoreFactory;
> import org.eclipse.emf.ecore.EcorePackage;
> import org.eclipse.emf.ecore.impl.EAttributeImpl;
> import org.eclipse.emf.edit.command.SetCommand;
> import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
> import org.eclipse.emf.edit.domain.EditingDomain;
> import
> org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
> import org.junit.Before;
> import org.junit.Test;
>
> /**
> * the following test fails
> * expected:<[a1, b1, b2, b3, a2]> but was:<[a1, b1, b2, a2, b3]>
> *
> * @author av
> *
> */
> public class SetCommandBug {
>
> private CommandStack commandStack;
> private EditingDomain domain;
>
> @Before
> public void setUp() {
> AdapterFactory adapterFactory = new
> ReflectiveItemProviderAdapterFactory();
> commandStack = new BasicCommandStack();
> domain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack);
>
> }
>
> @Test
> public void testSetCommand() {
> EClass eclass = EcoreFactory.eINSTANCE.createEClass();
> EAttribute a1 = createAttribute("a1");
> EAttribute a2 = createAttribute("a2");
> eclass.getEStructuralFeatures().add(a1);
> eclass.getEStructuralFeatures().add(a2);
>
> List<EAttribute> list = new ArrayList<EAttribute>();
> list.add(a1);
> list.add(createAttribute("b1"));
> list.add(createAttribute("b2"));
> list.add(createAttribute("b3"));
> list.add(a2);
>
> Command command = SetCommand.create(domain, eclass,
> EcorePackage.eINSTANCE
> .getEClass_EStructuralFeatures(), list);
> commandStack.execute(command);
>
> assertEquals(list.toString(), eclass.getEAttributes().toString());
> }
>
>
> private EAttribute createAttribute(String name) {
> // just to make toString() more concise
> EAttribute attribute = new EAttributeImpl() {
> @Override
> public String toString() {
> return name;
> }
> };
> attribute.setName(name);
> return attribute;
> }
>
> }
Previous Topic:How to copy a ResourceSet
Next Topic:Error when using proxy in teneo/hibernate
Goto Forum:
  


Current Time: Tue Jan 21 19:48:58 GMT 2020

Powered by FUDForum. Page generated in 0.01657 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top