Author: dazarov
Date: 2010-03-26 13:16:07 -0400 (Fri, 26 Mar 2010)
New Revision: 21058
Added:
trunk/tests/tests/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java
trunk/tests/tests/org.jboss.tools.tests/META-INF/MANIFEST.MF
Log:
https://jira.jboss.org/jira/browse/JBIDE-4990
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2010-03-26
16:57:42 UTC (rev 21057)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2010-03-26
17:16:07 UTC (rev 21058)
@@ -19,62 +19,6 @@
super("Seam Context Variable Refactoring Test");
}
- private void renameContextVariable(ISeamProject seamProject, String fileName, String
variableName, String newName, List<TestChangeStructure> changeList) throws
CoreException{
- JobUtils.waitForIdle(2000);
-
- // Test before renaming
- for(TestChangeStructure changeStructure : changeList){
- IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
- String content = null;
- try {
- content = FileUtil.readStream(file);
- } catch (CoreException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- for(TestTextChange change : changeStructure.getTextChanges()){
- assertNotSame(change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
- }
- }
-
- IFile sourceFile = seamProject.getProject().getFile(fileName);
-
- // Rename Seam Context Variable
- RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, variableName);
- processor.setNewName(newName);
- processor.checkInitialConditions(new NullProgressMonitor());
- processor.checkFinalConditions(new NullProgressMonitor(), null);
- CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
-
- assertEquals("There is unexpected number of changes",changeList.size(),
rootChange.getChildren().length);
-
- for(int i = 0; i < rootChange.getChildren().length;i++){
- TextFileChange fileChange = (TextFileChange)rootChange.getChildren()[i];
-
- MultiTextEdit edit = (MultiTextEdit)fileChange.getEdit();
-
- TestChangeStructure change = findChange(changeList, fileChange.getFile());
- if(change != null){
- assertEquals(change.size(), edit.getChildrenSize());
- }
- }
-
- rootChange.perform(new NullProgressMonitor());
- JobUtils.waitForIdle(2000);
-
-
- // Test results
- for(TestChangeStructure changeStructure : changeList){
- IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
- String content = null;
- content = FileUtil.readStream(file);
- for(TestTextChange change : changeStructure.getTextChanges()){
- assertEquals("There is unexpected change in resource -
"+file.getName(),change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
- }
- }
- }
-
public void testSeamContextVariable_Component_Rename() throws CoreException {
ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
@@ -128,8 +72,13 @@
change = new TestTextChange(29, 4, "best");
structure.addTextChange(change);
list.add(structure);
+
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/test.jsp");
+
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "test");
+ processor.setNewName("best");
- renameContextVariable(seamEjbProject, "/WebContent/test.jsp",
"test", "best", list);
+ checkRename(processor, list);
}
public void testSeamContextVariable_Factory1_Rename() throws CoreException {
@@ -145,7 +94,12 @@
structure.addTextChange(change);
list.add(structure);
- renameContextVariable(seamEjbProject, "/WebContent/factory.jsp",
"abc", "bbc", list);
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/factory.jsp");
+
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "abc");
+ processor.setNewName("bbc");
+
+ checkRename(processor, list);
}
public void testSeamContextVariable_Factory2_Rename() throws CoreException {
@@ -161,7 +115,12 @@
structure.addTextChange(change);
list.add(structure);
- renameContextVariable(seamEjbProject, "/WebContent/factory.jsp",
"cba", "ccc", list);
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/factory.jsp");
+
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "cba");
+ processor.setNewName("ccc");
+
+ checkRename(processor, list);
}
public void testSeamContextVariable_Out1_Rename() throws CoreException {
@@ -176,8 +135,13 @@
change = new TestTextChange(227, 3, "bbb");
structure.addTextChange(change);
list.add(structure);
+
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/out.jsp");
- renameContextVariable(seamEjbProject, "/WebContent/out.jsp", "aaa",
"bbb", list);
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "aaa");
+ processor.setNewName("bbb");
+
+ checkRename(processor, list);
}
public void testSeamContextVariable_Out2_Rename() throws CoreException {
@@ -192,8 +156,13 @@
change = new TestTextChange(283, 3, "eee");
structure.addTextChange(change);
list.add(structure);
+
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/out.jsp");
- renameContextVariable(seamEjbProject, "/WebContent/out.jsp", "ddd",
"eee", list);
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "ddd");
+ processor.setNewName("eee");
+
+ checkRename(processor, list);
}
public void testSeamContextVariable_DataModel1_Rename() throws CoreException {
@@ -209,7 +178,12 @@
structure.addTextChange(change);
list.add(structure);
- renameContextVariable(seamEjbProject, "/WebContent/datamodel.jsp",
"data", "dada", list);
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/datamodel.jsp");
+
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "data");
+ processor.setNewName("dada");
+
+ checkRename(processor, list);
}
public void testSeamContextVariable_DataModel2_Rename() throws CoreException {
@@ -225,6 +199,11 @@
structure.addTextChange(change);
list.add(structure);
- renameContextVariable(seamEjbProject, "/WebContent/datamodel.jsp",
"model", "modal", list);
+ IFile sourceFile =
seamEjbProject.getProject().getFile("/WebContent/datamodel.jsp");
+
+ RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(sourceFile, "model");
+ processor.setNewName("modal");
+
+ checkRename(processor, list);
}
}
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java 2010-03-26
16:57:42 UTC (rev 21057)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java 2010-03-26
17:16:07 UTC (rev 21058)
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
@@ -13,10 +12,9 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ProjectImportTestSetup;
+import org.jboss.tools.tests.AbstractRefactorTest;
-import junit.framework.TestCase;
-
-public class SeamRefactoringTest extends TestCase {
+public class SeamRefactoringTest extends AbstractRefactorTest {
static String warProjectName = "Test1";
static String earProjectName = "Test1-ear";
static String ejbProjectName = "Test1-ejb";
@@ -25,6 +23,7 @@
static IProject ejbProject;
static ISeamProject seamWarProject;
static ISeamProject seamEjbProject;
+
public SeamRefactoringTest(String name){
super(name);
}
@@ -57,68 +56,5 @@
return seamProject;
}
- protected TestChangeStructure findChange(List<TestChangeStructure> changeList,
IFile file){
- for(TestChangeStructure tcs : changeList){
- if(tcs.getFileName().equals("/"+file.getFullPath().removeFirstSegments(1).toString()))
- return tcs;
- }
- return null;
- }
- class TestChangeStructure{
- private IProject project;
- private String fileName;
- ArrayList<TestTextChange> textChanges = new ArrayList<TestTextChange>();
-
-
- public TestChangeStructure(IProject project, String fileName){
- this.project = project;
- this.fileName = fileName;
- }
-
- public IProject getProject(){
- return project;
- }
-
- public String getFileName(){
- return fileName;
- }
-
- public ArrayList<TestTextChange> getTextChanges(){
- return textChanges;
- }
-
- public void addTextChange(TestTextChange change){
- textChanges.add(change);
- }
-
- public int size(){
- return textChanges.size();
- }
-
- }
-
- class TestTextChange{
- private int offset;
- private int length;
- private String text;
-
- public TestTextChange(int offset, int length, String text){
- this.offset = offset;
- this.length = length;
- this.text = text;
- }
-
- public int getOffset(){
- return offset;
- }
-
- public int getLength(){
- return length;
- }
-
- public String getText(){
- return text;
- }
- }
}
Modified: trunk/tests/tests/org.jboss.tools.tests/META-INF/MANIFEST.MF
===================================================================
--- trunk/tests/tests/org.jboss.tools.tests/META-INF/MANIFEST.MF 2010-03-26 16:57:42 UTC
(rev 21057)
+++ trunk/tests/tests/org.jboss.tools.tests/META-INF/MANIFEST.MF 2010-03-26 17:16:07 UTC
(rev 21058)
@@ -10,7 +10,11 @@
org.junit,
org.eclipse.ui.ide,
org.jboss.tools.jst.web.kb,
- org.apache.xerces;bundle-version="[2.9.0,3.0.0)"
+ org.apache.xerces;bundle-version="[2.9.0,3.0.0)",
+ org.junit4;bundle-version="4.5.0",
+ org.jboss.tools.common;bundle-version="2.0.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.0",
+ org.eclipse.text;bundle-version="3.5.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.test.util,
org.jboss.tools.test.util.xpl,
Added:
trunk/tests/tests/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
===================================================================
---
trunk/tests/tests/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
(rev 0)
+++
trunk/tests/tests/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java 2010-03-26
17:16:07 UTC (rev 21058)
@@ -0,0 +1,144 @@
+package org.jboss.tools.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.test.util.JobUtils;
+
+public class AbstractRefactorTest extends TestCase{
+
+ public AbstractRefactorTest(String name){
+ super(name);
+ }
+
+ protected void checkRename(RenameProcessor processor, List<TestChangeStructure>
changeList) throws CoreException{
+ JobUtils.waitForIdle(2000);
+
+ // Test before renaming
+ for(TestChangeStructure changeStructure : changeList){
+ IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
+ String content = null;
+ try {
+ content = FileUtil.readStream(file);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ for(TestTextChange change : changeStructure.getTextChanges()){
+ assertNotSame(change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
+ }
+ }
+
+ // Rename
+ processor.checkInitialConditions(new NullProgressMonitor());
+ processor.checkFinalConditions(new NullProgressMonitor(), null);
+ CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
+
+ assertEquals("There is unexpected number of changes",changeList.size(),
rootChange.getChildren().length);
+
+ for(int i = 0; i < rootChange.getChildren().length;i++){
+ TextFileChange fileChange = (TextFileChange)rootChange.getChildren()[i];
+
+ MultiTextEdit edit = (MultiTextEdit)fileChange.getEdit();
+
+ TestChangeStructure change = findChange(changeList, fileChange.getFile());
+ if(change != null){
+ assertEquals(change.size(), edit.getChildrenSize());
+ }
+ }
+
+ rootChange.perform(new NullProgressMonitor());
+ JobUtils.waitForIdle(2000);
+
+
+ // Test results
+ for(TestChangeStructure changeStructure : changeList){
+ IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
+ String content = null;
+ content = FileUtil.readStream(file);
+ for(TestTextChange change : changeStructure.getTextChanges()){
+ assertEquals("There is unexpected change in resource -
"+file.getName(),change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
+ }
+ }
+ }
+
+
+ protected TestChangeStructure findChange(List<TestChangeStructure> changeList,
IFile file){
+ for(TestChangeStructure tcs : changeList){
+ if(tcs.getFileName().equals("/"+file.getFullPath().removeFirstSegments(1).toString()))
+ return tcs;
+ }
+ return null;
+ }
+
+
+ public class TestChangeStructure{
+ private IProject project;
+ private String fileName;
+ ArrayList<TestTextChange> textChanges = new ArrayList<TestTextChange>();
+
+
+ public TestChangeStructure(IProject project, String fileName){
+ this.project = project;
+ this.fileName = fileName;
+ }
+
+ public IProject getProject(){
+ return project;
+ }
+
+ public String getFileName(){
+ return fileName;
+ }
+
+ public ArrayList<TestTextChange> getTextChanges(){
+ return textChanges;
+ }
+
+ public void addTextChange(TestTextChange change){
+ textChanges.add(change);
+ }
+
+ public int size(){
+ return textChanges.size();
+ }
+
+ }
+
+ public class TestTextChange{
+ private int offset;
+ private int length;
+ private String text;
+
+ public TestTextChange(int offset, int length, String text){
+ this.offset = offset;
+ this.length = length;
+ this.text = text;
+ }
+
+ public int getOffset(){
+ return offset;
+ }
+
+ public int getLength(){
+ return length;
+ }
+
+ public String getText(){
+ return text;
+ }
+ }
+
+}
Property changes on:
trunk/tests/tests/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain