Author: dazarov
Date: 2009-06-30 12:25:50 -0400 (Tue, 30 Jun 2009)
New Revision: 16299
Added:
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
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java
Log:
Tests for Rename Seam Context Variable
https://jira.jboss.org/jira/browse/JBIDE-1077
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-06-30
15:56:39 UTC (rev 16298)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-06-30
16:25:50 UTC (rev 16299)
@@ -3,67 +3,27 @@
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.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.MultiTextEdit;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.refactoring.RenameComponentProcessor;
import org.jboss.tools.test.util.JobUtils;
-import org.jboss.tools.test.util.ProjectImportTestSetup;
-public class SeamComponentRefactoringTest extends TestCase {
- static String warProjectName = "Test1";
- static String earProjectName = "Test1-ear";
- static String ejbProjectName = "Test1-ejb";
- static IProject warProject;
- static IProject earProject;
- static IProject ejbProject;
- static ISeamProject seamWarProject;
- static ISeamProject seamEjbProject;
+public class SeamComponentRefactoringTest extends SeamRefactoringTest {
+
public SeamComponentRefactoringTest(){
super("Seam Component Refactoring Test");
}
- protected void setUp() throws Exception {
- loadProjects();
- List<IProject> projectList = new ArrayList<IProject>();
- projectList.add(ejbProject);
- projectList.add(warProject);
- J2EEComponentClasspathUpdater.getInstance().forceUpdate(projectList);
- loadProjects();
- }
+
- private void loadProjects() throws Exception {
- earProject = ProjectImportTestSetup.loadProject(earProjectName);
- earProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
- ejbProject = ProjectImportTestSetup.loadProject(ejbProjectName);
- warProject = ProjectImportTestSetup.loadProject(warProjectName);
- seamEjbProject = loadSeamProject(ejbProject);
- seamWarProject = loadSeamProject(warProject);
- }
-
- private ISeamProject loadSeamProject(IProject project) throws CoreException {
- JobUtils.waitForIdle();
-
- //System.out.println("Project - "+project);
- ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
- assertNotNull("Seam project for " + project.getName() + " is null",
seamProject);
-
- return seamProject;
- }
-
public void testSeamComponentRename() throws CoreException {
ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
@@ -189,68 +149,7 @@
}
}
- private 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;
- }
- }
+
}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2009-06-30
16:25:50 UTC (rev 16299)
@@ -0,0 +1,140 @@
+package org.jboss.tools.seam.core.test.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+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.text.edits.MultiTextEdit;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamProject;
+import
org.jboss.tools.seam.core.test.refactoring.SeamRefactoringTest.TestChangeStructure;
+import org.jboss.tools.seam.core.test.refactoring.SeamRefactoringTest.TestTextChange;
+import
org.jboss.tools.seam.internal.core.refactoring.RenameSeamContextVariableProcessor;
+import org.jboss.tools.test.util.JobUtils;
+
+public class SeamContextVariableRefactoringTest extends SeamRefactoringTest {
+ public SeamContextVariableRefactoringTest(){
+ super("Seam Context Variable Refactoring Test");
+ }
+
+ private void renameContextVariable(ISeamProject seamProject, String fileName, String
variableName, String newName, List<TestChangeStructure> changeList, boolean fromJar)
throws CoreException{
+ JobUtils.waitForIdle(2000);
+
+ // Test before renaming
+ ISeamComponent component = seamProject.getComponent(variableName);
+ assertNotNull("Can't load component " + variableName, component);
+ assertNull("There is unexpected component in seam project: " + newName,
seamProject.getComponent(newName));
+ for(TestChangeStructure changeStructure : changeList){
+ IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
+ String content = null;
+ content = FileUtil.readStream(file.getContents());
+ for(TestTextChange change : changeStructure.getTextChanges()){
+ assertNotSame(change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
+ }
+ }
+
+ assertNotNull("Component " + component.getName() + " does not have java
declaration.", component.getJavaDeclaration());
+
+ IFile sourceFile = seamProject.getProject().getFile(fileName);
+
+ // Rename Seam Component
+ 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
+ if(!fromJar)
+ assertNull("There is unexpected component in seam project: " + variableName,
seamProject.getComponent(variableName));
+ assertNotNull("Can't load component " + newName,
seamProject.getComponent(newName));
+ for(TestChangeStructure changeStructure : changeList){
+ IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
+ String content = null;
+ content = FileUtil.readStream(file.getContents());
+ //System.out.println("File - "+file.getName()+" offset -
"+changeStructure.getOffset()+" expected -
["+changeStructure.getText()+"] actual -
["+content.substring(changeStructure.getOffset(),
changeStructure.getOffset()+changeStructure.getLength())+"]");
+ 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>();
+
+ TestChangeStructure structure = new TestChangeStructure(ejbProject.getProject(),
"/ejbModule/org/domain/"+warProjectName+"/session/TestComponent.java");
+ TestTextChange change = new TestTextChange(89, 6, "\"best\"");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(warProject,
"/WebContent/WEB-INF/components.xml");
+ change = new TestTextChange(1106, 4, "best");
+ structure.addTextChange(change);
+
+ change = new TestTextChange(1934, 4, "best");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(ejbProject,
"/ejbModule/org/domain/"+warProjectName+"/session/TestSeamComponent.java");
+ change = new TestTextChange(420, 11, "@In(\"best\")");
+ structure.addTextChange(change);
+
+ change = new TestTextChange(389, 8, "(\"best\")");
+ structure.addTextChange(change);
+
+ change = new TestTextChange(455, 16, "@Factory(\"best\")");
+ structure.addTextChange(change);
+
+ change = new TestTextChange(529, 8, "(\"best\")");
+ structure.addTextChange(change);
+
+ change = new TestTextChange(589, 4, "best");
+ structure.addTextChange(change);
+
+ list.add(structure);
+
+ structure = new TestChangeStructure(ejbProject,
"/ejbModule/seam.properties");
+ change = new TestTextChange(0, 4, "best");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(warProject, "/WebContent/test.xhtml");
+ change = new TestTextChange(1088, 4, "best");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(warProject, "/WebContent/test.jsp");
+ change = new TestTextChange(227, 4, "best");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(warProject, "/src/test.properties");
+ change = new TestTextChange(29, 4, "best");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ renameContextVariable(seamEjbProject, "/WebContent/test.jsp",
"test", "best", list, false);
+ }
+}
Property changes on:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java 2009-06-30
15:56:39 UTC (rev 16298)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java 2009-06-30
16:25:50 UTC (rev 16299)
@@ -26,10 +26,16 @@
"org.jboss.tools.seam.core.test",
new String[]{"projects/RefactoringTestProject-war",
"projects/RefactoringTestProject-ejb",
"projects/RefactoringTestProject-test"},
new String[]{"RefactoringTestProject-war",
"RefactoringTestProject-ejb", "RefactoringTestProject-test"}));
+
suite.addTest(new ProjectImportTestSetup(new
TestSuite(SeamComponentRefactoringTest.class),
"org.jboss.tools.seam.core.test",
new
String[]{"projects/Test1-ear","projects/Test1-ejb","projects/Test1"},
new String[]{"Test1-ear","Test1-ejb","Test1"}));
+
+ suite.addTest(new ProjectImportTestSetup(new
TestSuite(SeamContextVariableRefactoringTest.class),
+ "org.jboss.tools.seam.core.test",
+ new
String[]{"projects/Test1-ear","projects/Test1-ejb","projects/Test1"},
+ new String[]{"Test1-ear","Test1-ejb","Test1"}));
return suite;
}
}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java 2009-06-30
16:25:50 UTC (rev 16299)
@@ -0,0 +1,124 @@
+package org.jboss.tools.seam.core.test.refactoring;
+
+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;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.test.util.ProjectImportTestSetup;
+
+import junit.framework.TestCase;
+
+public class SeamRefactoringTest extends TestCase {
+ static String warProjectName = "Test1";
+ static String earProjectName = "Test1-ear";
+ static String ejbProjectName = "Test1-ejb";
+ static IProject warProject;
+ static IProject earProject;
+ static IProject ejbProject;
+ static ISeamProject seamWarProject;
+ static ISeamProject seamEjbProject;
+ public SeamRefactoringTest(String name){
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ loadProjects();
+ List<IProject> projectList = new ArrayList<IProject>();
+ projectList.add(ejbProject);
+ projectList.add(warProject);
+ J2EEComponentClasspathUpdater.getInstance().forceUpdate(projectList);
+ loadProjects();
+ }
+
+ private void loadProjects() throws Exception {
+ earProject = ProjectImportTestSetup.loadProject(earProjectName);
+ earProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ ejbProject = ProjectImportTestSetup.loadProject(ejbProjectName);
+ warProject = ProjectImportTestSetup.loadProject(warProjectName);
+ seamEjbProject = loadSeamProject(ejbProject);
+ seamWarProject = loadSeamProject(warProject);
+ }
+
+ private ISeamProject loadSeamProject(IProject project) throws CoreException {
+ JobUtils.waitForIdle();
+
+ //System.out.println("Project - "+project);
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ assertNotNull("Seam project for " + project.getName() + " is null",
seamProject);
+
+ 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;
+ }
+ }
+}
Property changes on:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain