Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 14227f72eba308e95f4d9b85e0c95a7e2dd41f7e (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
package org.eclipse.papyrus.infra.services.edit.tests.commands;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.services.edit.commands.ConfigureFeatureListCommandFactory;
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.services.edit.tests.AbstractTestElementEditService;
import org.junit.Before;
import org.junit.Test;

/**
 * JUnit tests for {@link ConfigureFeatureListCommandFactory} class.
 */
public class TestConfigureFeatureListCommandFactory extends AbstractTestElementEditService {

	IElementEditService ePckgService;

	EPackage ePckg;

	@Override
	@Before
	public void setUp() {
		super.setUp();

		try {
			ePckgService = provider.getEditService(ePackgType);
		} catch (ServiceException e) {
			fail("failed to get the edit service for "+ePackgType);
		}
		ePckg = EcoreFactory.eINSTANCE.createEPackage();
	}

	@Test
	public void testGetEditCommand() throws ServiceException, ExecutionException {
		ICommand correctCommand = ePckgService.getEditCommand(prepareCorrectRequest());

		// Try to execute command and make quick result verification.
		assertTrue("The service command should be executable.", correctCommand.canExecute());
		correctCommand.execute(new NullProgressMonitor(), null);
		assertTrue("The service command result is incorrect.", !ePckg.getESubpackages().isEmpty());
		assertTrue("The service configure command result is incorrect.", "ASpecificName".equals(ePckg.getESubpackages().get(0).getName()));
		assertTrue("The service configure command result is incorrect.", "ASpecificNsURI".equals(ePckg.getESubpackages().get(0).getNsURI()));
	}

	/** Prepare a creation request (create a EPackage in an EPackage) and adds a ConfigureFeatureCommand */
	@SuppressWarnings("unchecked")
	private IEditCommandRequest prepareCorrectRequest() throws ServiceException {
		TransactionalEditingDomain editingDomain = (TransactionalEditingDomain)editor.getAdapter(TransactionalEditingDomain.class);
		IEditCommandRequest request = new CreateElementRequest(editingDomain, ePckg, ePackgType);

		// Create a configure command factory and add it to the request
		Map<EStructuralFeature, Object> featureValueMap = new HashMap<EStructuralFeature, Object>();
		featureValueMap.put(EcorePackage.eINSTANCE.getENamedElement_Name(), "ASpecificName");
		featureValueMap.put(EcorePackage.eINSTANCE.getEPackage_NsURI(), "ASpecificNsURI");

		IConfigureCommandFactory factory = new ConfigureFeatureListCommandFactory(featureValueMap);
		request.getParameters().put(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, factory);

		return request;
	}
}

Back to the top