Author: dazarov
Date: 2010-04-27 07:35:12 -0400 (Tue, 27 Apr 2010)
New Revision: 21721
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
Removed:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java.fixme
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/AbstractRefactorTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/ELVariableRefactoringTest.java
Modified:
trunk/common/tests/org.jboss.tools.common.model.ui.test/src/org/jboss/tools/common/model/ui/jarproperties/JarPropertiesTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java
Log:
In order to avoid cyclic dependencies
Copied:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
(from rev 21679,
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java.fixme)
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -0,0 +1,96 @@
+package org.jboss.tools.cdi.core.test.tck;
+
+import java.util.ArrayList;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.internal.core.refactoring.RenameNamedBeanProcessor;
+import org.jboss.tools.tests.AbstractRefactorTest;
+
+public class NamedBeanRefactoringTest extends AbstractRefactorTest {
+ private static final String PROJECT_NAME = "/tests/jbt/refactoring";
+ private static final String FILE_NAME1 =
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/Game.java";
+ private static final String FILE_NAME2 =
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/Generator.java";
+ private static final String FILE_NAME3 = "WebContent/HomePage.xhtml";
+ private static final String FILE_NAME4 = "WebContent/index.jsp";
+ static IProject project;
+
+ public NamedBeanRefactoringTest() {
+ super("Named Bean Refactoring Test");
+ }
+
+ public static Test suite() {
+ return new TestSuite(NamedBeanRefactoringTest.class);
+ }
+
+ public void testNamedBeanRename() throws Exception {
+ IProject project = TCKTest.importPreparedProject(PROJECT_NAME);
+ doTest(project);
+ TCKTest.cleanProject(PROJECT_NAME);
+ }
+
+ public void doTest(IProject project) throws CoreException {
+ final String newName = "abcd";
+ ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
+
+ TestChangeStructure structure = new TestChangeStructure(project
+ .getProject(), FILE_NAME1);
+ TestTextChange change = new TestTextChange(328, 4, newName);
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(project, FILE_NAME2);
+ change = new TestTextChange(526, 4, newName);
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(project, FILE_NAME3);
+ change = new TestTextChange(789, 4, newName);
+ structure.addTextChange(change);
+ change = new TestTextChange(923, 4, newName);
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(project, FILE_NAME4);
+ change = new TestTextChange(293, 4, newName);
+ structure.addTextChange(change);
+ list.add(structure);
+
+ IFile sourceFile = project.getProject().getFile(FILE_NAME1);
+
+ IBean bean = getBean(sourceFile, "game");
+ assertNotNull("Can't get the bean.", bean);
+
+ RenameNamedBeanProcessor processor = new RenameNamedBeanProcessor(bean);
+ processor.setNewName(newName);
+
+ checkRename(processor, list);
+ }
+
+ private IBean getBean(IFile file, String name) {
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
+ assertNotNull("Can't get CDI nature.", cdiNature);
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ assertNotNull("Can't get CDI project.", cdiProject);
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ for (IBean bean : beans) {
+ if (bean.getName() != null && name.equals(bean.getName())) {
+ return bean;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java.fixme
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java.fixme 2010-04-27
11:20:18 UTC (rev 21720)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java.fixme 2010-04-27
11:35:12 UTC (rev 21721)
@@ -1,96 +0,0 @@
-package org.jboss.tools.cdi.core.test.tck;
-
-import java.util.ArrayList;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.jboss.tools.cdi.core.CDICoreNature;
-import org.jboss.tools.cdi.core.CDICorePlugin;
-import org.jboss.tools.cdi.core.IBean;
-import org.jboss.tools.cdi.core.ICDIProject;
-import org.jboss.tools.cdi.internal.core.refactoring.RenameNamedBeanProcessor;
-import org.jboss.tools.tests.AbstractRefactorTest;
-
-public class NamedBeanRefactoringTest extends AbstractRefactorTest {
- private static final String PROJECT_NAME = "/tests/jbt/refactoring";
- private static final String FILE_NAME1 =
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/Game.java";
- private static final String FILE_NAME2 =
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/Generator.java";
- private static final String FILE_NAME3 = "WebContent/HomePage.xhtml";
- private static final String FILE_NAME4 = "WebContent/index.jsp";
- static IProject project;
-
- public NamedBeanRefactoringTest() {
- super("Named Bean Refactoring Test");
- }
-
- public static Test suite() {
- return new TestSuite(NamedBeanRefactoringTest.class);
- }
-
- public void testNamedBeanRename() throws Exception {
- IProject project = TCKTest.importPreparedProject(PROJECT_NAME);
- doTest(project);
- TCKTest.cleanProject(PROJECT_NAME);
- }
-
- public void doTest(IProject project) throws CoreException {
- final String newName = "abcd";
- ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
-
- TestChangeStructure structure = new TestChangeStructure(project
- .getProject(), FILE_NAME1);
- TestTextChange change = new TestTextChange(328, 4, newName);
- structure.addTextChange(change);
- list.add(structure);
-
- structure = new TestChangeStructure(project, FILE_NAME2);
- change = new TestTextChange(526, 4, newName);
- structure.addTextChange(change);
- list.add(structure);
-
- structure = new TestChangeStructure(project, FILE_NAME3);
- change = new TestTextChange(789, 4, newName);
- structure.addTextChange(change);
- change = new TestTextChange(923, 4, newName);
- structure.addTextChange(change);
- list.add(structure);
-
- structure = new TestChangeStructure(project, FILE_NAME4);
- change = new TestTextChange(293, 4, newName);
- structure.addTextChange(change);
- list.add(structure);
-
- IFile sourceFile = project.getProject().getFile(FILE_NAME1);
-
- IBean bean = getBean(sourceFile, "game");
- assertNotNull("Can't get the bean.", bean);
-
- RenameNamedBeanProcessor processor = new RenameNamedBeanProcessor(bean);
- processor.setNewName(newName);
-
- checkRename(processor, list);
- }
-
- private IBean getBean(IFile file, String name) {
- CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
- assertNotNull("Can't get CDI nature.", cdiNature);
-
- ICDIProject cdiProject = cdiNature.getDelegate();
-
- assertNotNull("Can't get CDI project.", cdiProject);
-
- Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
-
- for (IBean bean : beans) {
- if (bean.getName() != null && name.equals(bean.getName())) {
- return bean;
- }
- }
- return null;
- }
-}
\ No newline at end of file
Modified:
trunk/common/tests/org.jboss.tools.common.model.ui.test/src/org/jboss/tools/common/model/ui/jarproperties/JarPropertiesTest.java
===================================================================
---
trunk/common/tests/org.jboss.tools.common.model.ui.test/src/org/jboss/tools/common/model/ui/jarproperties/JarPropertiesTest.java 2010-04-27
11:20:18 UTC (rev 21720)
+++
trunk/common/tests/org.jboss.tools.common.model.ui.test/src/org/jboss/tools/common/model/ui/jarproperties/JarPropertiesTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -17,7 +17,7 @@
import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.propertieseditor.PropertiesCompoundEditor;
-import org.jboss.tools.common.test.util.TestProjectProvider;
+import org.jboss.tools.test.util.TestProjectProvider;
import junit.framework.TestCase;
Added:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -0,0 +1,53 @@
+package org.jboss.tools.jsf.test.refactoring;
+
+import java.util.ArrayList;
+
+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.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
+import org.jboss.tools.test.util.ProjectImportTestSetup;
+import org.jboss.tools.tests.AbstractRefactorTest;
+
+public class ELVariableRefactoringTest extends AbstractRefactorTest {
+ static String projectName = "JSFKickStartOldFormat";
+ static IProject project;
+
+ public ELVariableRefactoringTest(){
+ super("EL Variable Refactoring Test");
+ }
+
+ protected void setUp() throws Exception {
+ project = ProjectImportTestSetup.loadProject(projectName);
+ project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
+
+ public void testELVariableRename() throws CoreException {
+ ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
+
+ TestChangeStructure structure = new TestChangeStructure(project.getProject(),
"/WebContent/pages/hello.jsp");
+ TestTextChange change = new TestTextChange(349, 8, "customer");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(project,
"/WebContent/WEB-INF/faces-config.xml");
+ change = new TestTextChange(1815, 8, "customer");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ structure = new TestChangeStructure(project,
"/WebContent/pages/inputUserName.jsp");
+ change = new TestTextChange(494, 8, "customer");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ IFile sourceFile =
project.getProject().getFile("/WebContent/pages/hello.jsp");
+
+ RenameELVariableProcessor processor = new RenameELVariableProcessor(sourceFile,
"user");
+ processor.setNewName("customer");
+
+ checkRename(processor, list);
+ }
+
+}
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2010-04-27
11:20:18 UTC (rev 21720)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -93,7 +93,7 @@
public static final String SYS_PROP_IS_NOT_DEFINED = "System property {0} is not
defined";
protected File getSeamHomeFolder() {
- String seamHomeFolder = System.getProperty(getSystemPropertyName());
+ String seamHomeFolder =
"C:\\JBoss\\jboss-seam-1.2.1.GA";//System.getProperty(getSystemPropertyName());
if(seamHomeFolder==null) {
throw new IllegalStateException(
MessageFormat.format(SYS_PROP_IS_NOT_DEFINED, getSystemPropertyName())
Deleted:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/AbstractRefactorTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/AbstractRefactorTest.java 2010-04-27
11:20:18 UTC (rev 21720)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/AbstractRefactorTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -1,144 +0,0 @@
-package org.jboss.tools.seam.core.test.refactoring;
-
-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;
- }
- }
-
-}
Deleted:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/ELVariableRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/ELVariableRefactoringTest.java 2010-04-27
11:20:18 UTC (rev 21720)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/ELVariableRefactoringTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -1,52 +0,0 @@
-package org.jboss.tools.seam.core.test.refactoring;
-
-import java.util.ArrayList;
-
-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.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
-import org.jboss.tools.test.util.ProjectImportTestSetup;
-
-public class ELVariableRefactoringTest extends AbstractRefactorTest {
- static String projectName = "JSFKickStartOldFormat";
- static IProject project;
-
- public ELVariableRefactoringTest(){
- super("EL Variable Refactoring Test");
- }
-
- protected void setUp() throws Exception {
- project = ProjectImportTestSetup.loadProject(projectName);
- project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
- }
-
- public void testELVariableRename() throws CoreException {
- ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
-
- TestChangeStructure structure = new TestChangeStructure(project.getProject(),
"/WebContent/pages/hello.jsp");
- TestTextChange change = new TestTextChange(349, 8, "customer");
- structure.addTextChange(change);
- list.add(structure);
-
- structure = new TestChangeStructure(project,
"/WebContent/WEB-INF/faces-config.xml");
- change = new TestTextChange(1815, 8, "customer");
- structure.addTextChange(change);
- list.add(structure);
-
- structure = new TestChangeStructure(project,
"/WebContent/pages/inputUserName.jsp");
- change = new TestTextChange(494, 8, "customer");
- structure.addTextChange(change);
- list.add(structure);
-
- IFile sourceFile =
project.getProject().getFile("/WebContent/pages/hello.jsp");
-
- RenameELVariableProcessor processor = new RenameELVariableProcessor(sourceFile,
"user");
- processor.setNewName("customer");
-
- 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-04-27
11:20:18 UTC (rev 21720)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -12,6 +12,7 @@
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;
public class SeamRefactoringTest extends AbstractRefactorTest {
static String warProjectName = "Test1";
Added:
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java 2010-04-27
11:35:12 UTC (rev 21721)
@@ -0,0 +1,181 @@
+package org.jboss.tools.tests;
+
+import java.io.IOException;
+import java.io.InputStream;
+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.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 = 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 = 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;
+ }
+ }
+
+ public static String readStream(InputStream is) {
+ StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
+ try {
+ byte[] b = new byte[4096];
+ while(true) {
+ int l = is.read(b, 0, b.length);
+ if(l < 0) break;
+ sb.append(new String(b, 0, l));
+ }
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ return sb.toString();
+ }
+
+ public static String readStream(IFile file) throws CoreException {
+ String content = null;
+ InputStream in = null;
+ try {
+ in = file.getContents();
+ content = readStream(in);
+ } finally {
+ if(in!=null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ }
+ return content;
+ }
+
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain