Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8c0866ea78623bf6c94bc0dd01ba3c8046a16b44 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 * 
 * 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
 * $Id$
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgQueries;
import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaDeleteProcessor;
import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.DeleteRefactoring;
import org.eclipse.objectteams.otdt.core.IMethodMapping;
import org.eclipse.objectteams.otdt.core.IRoleType;
import org.eclipse.objectteams.otdt.core.OTModelManager;
import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup;
import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest;

/**
 * @author brcan
 */
public class OTDeleteTests extends RefactoringTest
{
    private static final String REFACTORING_PATH = "Delete/";
    private static final String CU_NAME = "T";
    private ICompilationUnit _cuT;

    public OTDeleteTests(String name)
    {
        super(name);
    }

    public static Test suite()
    {
        return new MySetup(new TestSuite(OTDeleteTests.class));
    }

    public static Test setUpTest(Test someTest)
    {
        return new MySetup(someTest);
    }

    protected String getRefactoringPath()
    {
        return REFACTORING_PATH;
    }

    private void loadFileSetup() throws Exception
    {
        _cuT = createCUfromTestFile(getPackageP(), CU_NAME);
        assertTrue("T.java does not exist", _cuT.exists());
    }

    private void checkDelete(IJavaElement[] elems, boolean deleteCu)
        throws JavaModelException, Exception
    {
        ICompilationUnit newCuT = null;
        try
        {
            DeleteRefactoring refactoring = createRefactoring(elems);
            assertNotNull(refactoring);
            RefactoringStatus status = performRefactoring(refactoring, true);
            assertEquals("precondition was supposed to pass", null, status);

            newCuT = getPackageP().getCompilationUnit(CU_NAME + ".java");
            assertTrue("T.java does not exist", newCuT.exists() == !deleteCu);
            if (!deleteCu)
            {
                assertEqualLines(
                        "incorrect content of T.java",
                        getFileContents(getOutputTestFileName(CU_NAME)),
                        newCuT.getSource());
            }
        }
        finally
        {
            performDummySearch();
            if (newCuT != null && newCuT.exists())
            {
                newCuT.delete(true, null);
            }
            if (_cuT != null && _cuT.exists())
            {
                _cuT.delete(true, null);
                _cuT = null;
            }
        }
    }

    private DeleteRefactoring createRefactoring(Object[] elements)
        throws CoreException
    {
        JavaDeleteProcessor processor = new JavaDeleteProcessor(elements);
        DeleteRefactoring result = new DeleteRefactoring(processor);
        processor.setQueries(createReorgQueries());
        return result;
    }

    private IReorgQueries createReorgQueries()
    {
        return new MockReorgQueries();
    }

    //---- tests ----    
    public void testDeleteTeamclass() throws Exception
    {
//      ParticipantTesting.reset();
        loadFileSetup();
        IJavaElement aTeam = _cuT.getType("T");
        IJavaElement[] elems = new IJavaElement[] { aTeam };
        checkDelete(elems, true);
//      String[] handles = ParticipantTesting.createHandles(elem0);
//      ParticipantTesting.testDelete(handles);        
    }
    
    public void testDeleteNestedTeamclass() throws Exception
    {
        loadFileSetup();
        IJavaElement nestedTeam = _cuT.getType("T").getType("TR");
        IJavaElement[] elems = new IJavaElement[] { nestedTeam };
        checkDelete(elems, false);
    }

    public void testDeleteRoleclass() throws Exception
    {
    	loadFileSetup();
    	IType type = _cuT.getType("T").getType("R");
    	IRoleType role = (IRoleType)OTModelManager.getOTElement(type); 
    	IJavaElement[] elems = new IJavaElement[] { role };
    	checkDelete(elems, false);
    }

    @SuppressWarnings("restriction")
	public void testGetRoleclassName() throws Exception
    {
    	loadFileSetup();
    	IType type = _cuT.getType("T").getType("R");
    	IRoleType role = (IRoleType)OTModelManager.getOTElement(type); 
    	String message1= ReorgUtils.getName(role);
    	assertEquals("role 'R'", message1);
    }

    public void testDeleteCalloutMapping() throws Exception
    {
    	loadFileSetup();
    	IType type = _cuT.getType("T").getType("R");
    	IRoleType role = (IRoleType)OTModelManager.getOTElement(type); 
    	IMethodMapping[] mappings = role.getMethodMappings(); 
    	IJavaElement[] elems = new IJavaElement[] { mappings[0] };
    	checkDelete(elems, false);
    }

    public void testDeleteCalloutToFieldMapping() throws Exception
    {
    	loadFileSetup();
    	IType type = _cuT.getType("T").getType("R");
    	IRoleType role = (IRoleType)OTModelManager.getOTElement(type); 
    	IMethodMapping[] mappings = role.getMethodMappings(); 
    	IJavaElement[] elems = new IJavaElement[] { mappings[0] };
    	checkDelete(elems, false);
    }

    public void testDeleteCallinMapping() throws Exception
    {
    	loadFileSetup();
    	IType type = _cuT.getType("T").getType("R");
    	IRoleType role = (IRoleType)OTModelManager.getOTElement(type); 
    	IMethodMapping[] mappings = role.getMethodMappings(); 
    	IJavaElement[] elems = new IJavaElement[] { mappings[0] };
    	checkDelete(elems, false);
    }
}

Back to the top