Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d367d300ef6b4bb94cbedb55009234df2d270662 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2009, 2015 Borland Software Corporation 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:
 *     Borland Software Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.m2m.tests.qvt.oml.callapi;

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

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.m2m.qvt.oml.BasicModelExtent;
import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
import org.eclipse.m2m.qvt.oml.ModelExtent;
import org.eclipse.m2m.qvt.oml.TransformationExecutor;
import org.junit.Before;
import org.junit.Test;

import junit.framework.TestCase;

/**
 * @author dvorak
 */
public class InvocationExtTest extends TestCase {

	private TransformationExecutor fExecutor;
	private BasicModelExtent fInput;
	private List<EObject> fInitialInputContents;	
	
	private BasicModelExtent fInOut;
	private String fInOutPackageInitialName = "inout"; //$NON-NLS-1$
	
	private ExecutionContextImpl fContext;

	
	public InvocationExtTest(String name) {
		super(name);
	}
	
	@Override
	@Before
	protected void setUp() throws Exception {
		super.setUp();
		
		URI uri = URI.createPlatformPluginURI("org.eclipse.m2m.tests.qvt.oml/deployed/callapi/Ecore2EcoreExt.qvto", false); //$NON-NLS-1$
		fExecutor = new TransformationExecutor(uri);

		fInput = new BasicModelExtent();
		EPackage inObject = EcoreFactory.eINSTANCE.createEPackage();
		inObject.setName("input1"); //$NON-NLS-1$
		fInput.add(inObject);
		
		fInOut = new BasicModelExtent();
		EPackage inOutObject = EcoreFactory.eINSTANCE.createEPackage();
		inOutObject.setName(fInOutPackageInitialName);
		fInOut.add(inOutObject);
		
		fInitialInputContents = new ArrayList<EObject>(fInput.getContents());
				
		fContext = new ExecutionContextImpl();
		
		assertFalse(fInput.getContents().isEmpty());		
		assertFalse(fInOut.getContents().isEmpty());		
	}

	private void assertInOutObject() {
		EPackage inoutObjevt = (EPackage)EcoreUtil.getObjectByType(fInOut.getContents(), EcorePackage.eINSTANCE.getEPackage());
		assertEquals(fInOutPackageInitialName + "_Ecore2EcoreExt", inoutObjevt.getName()); //$NON-NLS-1$
		assertEquals(1, inoutObjevt.getEClassifiers().size());
	}
	
	private void assertOutObject(String key, ModelExtent outModel) {
		assertEquals(1, outModel.getContents().size());
		EPackage result = (EPackage)EcoreUtil.getObjectByType(outModel.getContents(), EcorePackage.eINSTANCE.getEPackage());
		assertEquals(key, result.getName());		
		assertEquals(1, result.getEClassifiers().size());
		
		assertUnchangedInput();
	}
	
	
	private void assertUnchangedInput() {
		// check the input was not changed
		assertEquals(fInitialInputContents, fInput.getContents());
	}
	
	@Test
	public void testInvokeIn_InOut_Out1_Out2() throws Exception {
		BasicModelExtent output1 = new BasicModelExtent();
		BasicModelExtent output2 = new BasicModelExtent();

		final ExecutionDiagnostic  diagnostic = fExecutor.execute(fContext, fInput, fInOut, output1, output2);		
		assertEquals(Diagnostic.OK, diagnostic.getSeverity());
		assertEquals(0, diagnostic.getCode());

		assertOutObject("output1", output1); //$NON-NLS-1$
		assertOutObject("output2", output2); //$NON-NLS-1$
		
		assertInOutObject();
	}
	
	@Test
	public void testInOut() throws Exception {
		URI uri = URI.createPlatformPluginURI("org.eclipse.m2m.tests.qvt.oml/deployed/callapi/InplaceEcore.qvto", false); //$NON-NLS-1$
		fExecutor = new TransformationExecutor(uri);
		
		final ExecutionDiagnostic  diagnostic = fExecutor.execute(fContext, fInOut);		
		assertEquals(Diagnostic.OK, diagnostic.getSeverity());
		assertEquals(0, diagnostic.getCode());
	}
	
}

Back to the top