blob: a48471f43d6eaf3a428ba7830cf9a058eca355a3 (
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
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
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.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.command.MoveCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import java.text.ParseException;
/**
* @author Christophe Bouhier
*/
public class Bugzilla_408534_Test extends AbstractCDOTest
{
public void testListElementMove() throws Exception
{
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
Resource resource = transaction.getOrCreateResource(getResourcePath("test.model1"));
// Add a company with 3 categories.
Company company = getModel1Factory().createCompany();
addCategory(company);
addCategory(company);
addCategory(company);
resource.getContents().add(company);
transaction.commit();
// Bring the resourceset under an editing domain.
ResourceSet resourceSet = transaction.getResourceSet();
AdapterFactory adapterFactory = new ReflectiveItemProviderAdapterFactory();
CommandStack commandStack = new SaneCommandStack();
EditingDomain domain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);
// Add a notfification adapter.
company.eAdapters().add(new AdapterImpl()
{
@Override
public void notifyChanged(Notification msg)
{
// We expect an object of type Category as the new value.
assertInstanceOf(Category.class, msg.getNewValue());
}
});
// Move the last element to index = 0;
Command moveCommand = new MoveCommand(domain, company.getCategories(), company.getCategories().size() - 1, 0);
commandStack.execute(moveCommand); // Notifier should not throw an exception.
}
private void addCategory(Company company) throws ParseException
{
Category category = getModel1Factory().createCategory();
category.setName("Cat" + (company.getCategories().size() + 1));
company.getCategories().add(category);
}
/**
* @author Caspar De Groot
*/
private static class SaneCommandStack extends BasicCommandStack
{
@Override
protected void handleError(Exception exception)
{
throw new WrappedException(exception);
}
}
}
|