Author: dazarov
Date: 2007-10-12 09:11:59 -0400 (Fri, 12 Oct 2007)
New Revision: 4153
Added:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/WebContent/WEB-INF/lib/jboss-ejb3-all.jar
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
Log:
http://jira.jboss.com/jira/browse/EXIN-13
Added:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/WebContent/WEB-INF/lib/jboss-ejb3-all.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/WebContent/WEB-INF/lib/jboss-ejb3-all.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2007-10-12
12:19:52 UTC (rev 4152)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2007-10-12
13:11:59 UTC (rev 4153)
@@ -16,9 +16,12 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.internal.decorators.DecoratorManager;
+import org.eclipse.ui.progress.UIJob;
import org.jboss.tools.common.model.XJob;
import org.jboss.tools.common.test.util.TestProjectProvider;
import org.jboss.tools.seam.core.ISeamProject;
@@ -28,7 +31,7 @@
public class SeamValidatorsTest extends TestCase {
IProject project = null;
- boolean makeCopy = false;
+ boolean makeCopy = true;
public SeamValidatorsTest() {}
@@ -42,29 +45,12 @@
JUnitUtils.fail("Error in refreshing",e);
}
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
+ refreshProject(project);
}
private ISeamProject getSeamProject(IProject project) {
- try {
- XJob.waitForJob();
- } catch (Exception e) {
- JUnitUtils.fail("Interrupted",e);
- }
- try {
- project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
+ refreshProject(project);
+
ISeamProject seamProject = null;
try {
seamProject = (ISeamProject)project.getNature(SeamProject.NATURE_ID);
@@ -90,6 +76,15 @@
IFile statefulComponentFile =
project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
IFile componentsFile = project.getFile("WebContent/WEB-INF/components.xml");
+ int number = getMarkersNumber(bbcComponentFile);
+ assertTrue("Problem marker was found in BbcComponent.java file", number ==
0);
+
+ number = getMarkersNumber(statefulComponentFile);
+ assertTrue("Problem marker was found in StatefulComponent.java file", number
== 0);
+
+ number = getMarkersNumber(componentsFile);
+ assertTrue("Problem marker was found in components.xml file", number == 0);
+
// Duplicate component name
System.out.println("Test - Duplicate component name");
@@ -101,25 +96,13 @@
JUnitUtils.fail("Error in changing 'BbcComponent.java' content to "
+
"'BbcComponent.2'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
- try{
- IMarker[] markers = bbcComponentFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
- }
- }catch(CoreException ex){
- JUnitUtils.fail("Error in getting problem markers", ex);
- }
+ refreshProject(project);
+
+ String message = getMarkersMessage(bbcComponentFile);
+
+ assertTrue("Problem marker 'Duplicate component name' not
found","Duplicate component name: abcComponent".equals(message));
+
// Stateful component does not contain @Remove method
System.out.println("Test - Stateful component does not contain @Remove
method");
@@ -131,25 +114,12 @@
JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to
" +
"'StatefulComponent.2'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
- try{
- IMarker[] markers = statefulComponentFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
- }
- }catch(CoreException ex){
- JUnitUtils.fail("Error in getting problem markers", ex);
- }
+ refreshProject(project);
+
+ message = getMarkersMessage(statefulComponentFile);
+ assertTrue("Problem marker 'Stateful component does not contain @Remove
method' not found", "Stateful component \"statefulComponent\" must
have a method marked @Remove".equals(message));
+
// Stateful component does not contain @Destroy method
System.out.println("Test - Stateful component does not contain @Destroy
method");
@@ -161,25 +131,12 @@
JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to
" +
"'StatefulComponent.3'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
- try{
- IMarker[] markers = statefulComponentFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
- }
- }catch(CoreException ex){
- JUnitUtils.fail("Error in getting problem markers", ex);
- }
+ refreshProject(project);
+
+ message = getMarkersMessage(statefulComponentFile);
+ assertTrue("Problem marker 'Stateful component does not contain @Destroy
method' not found", "Stateful component \"statefulComponent\" must
have a method marked @Destroy".equals(message));
+
// Stateful component has wrong scope
System.out.println("Test - Stateful component has wrong scope");
@@ -191,29 +148,17 @@
JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to
" +
"'StatefulComponent.4'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
- try{
- IMarker[] markers = statefulComponentFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
- }
- }catch(CoreException ex){
- JUnitUtils.fail("Error in getting problem markers", ex);
- }
+ refreshProject(project);
+
+ message = getMarkersMessage(statefulComponentFile);
+ assertTrue("Problem marker 'Stateful component has wrong scope' not
found", "Stateful component \"statefulComponent\" should not have
org.jboss.seam.ScopeType.PAGE, nor
org.jboss.seam.ScopeType.STATELESS".equals(message));
+
// Component class name cannot be resolved to a type
System.out.println("Test - Component class name cannot be resolved to a
type");
IFile componentsFile2 = project.getFile("WebContent/WEB-INF/components.2");
+
try{
componentsFile.setContents(componentsFile2.getContents(), true, false, new
NullProgressMonitor());
componentsFile.touch(new NullProgressMonitor());
@@ -221,29 +166,27 @@
JUnitUtils.fail("Error in changing 'components.xml' content to " +
"'components.2'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
- }
- try{
- IMarker[] markers = componentsFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
- }
- }catch(CoreException ex){
- JUnitUtils.fail("Error in getting problem markers", ex);
- }
+
+ refreshProject(project);
+
+ message = getMarkersMessage(componentsFile);
+ assertTrue("Problem marker 'Component class name cannot be resolved to a
type' not found",
"\"org.domain.SeamWebWarTestProject.session.StateComponent\" cannot be
resolved to a type".equals(message));
// Component class does not contain setter for property
System.out.println("Test - Component class does not contain setter for
property");
+ IFile componentsFile3 = project.getFile("WebContent/WEB-INF/components.3");
+
+ try{
+ componentsFile.setContents(componentsFile3.getContents(), true, false, new
NullProgressMonitor());
+ componentsFile.touch(new NullProgressMonitor());
+ }catch(Exception ex){
+ JUnitUtils.fail("Error in changing 'components.xml' content to " +
+ "'components.3'", ex);
+ }
+
IFile statefulComponentFile5 =
project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.5");
+
try{
statefulComponentFile.setContents(statefulComponentFile5.getContents(), true, false,
new NullProgressMonitor());
statefulComponentFile.touch(new NullProgressMonitor());
@@ -251,25 +194,135 @@
JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to
" +
"'StatefulComponent.5'", ex);
}
- try {
- seamProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
- try {
- XJob.waitForJob();
- } catch (InterruptedException e) {
- JUnitUtils.fail("Interrupted",e);
- }
- } catch (Exception e) {
- JUnitUtils.fail("Cannot build", e);
+
+ refreshProject(project);
+
+ message = getMarkersMessage(componentsFile);
+ assertTrue("Problem marker 'Component class does not contain setter for
property' not found", "Class \"StatefulComponent\" of component
\"statefulComponent\" does not contain setter for property
\"abc\"".equals(message));
+ }
+
+ public void testEntitiesValidator() {
+
+ }
+
+ public void testComponentLifeCycleMethodsValidator() {
+
+ }
+
+ public void testFactoriesValidator() {
+
+ }
+
+ public void testBijectionsValidator() {
+
+ }
+
+ public void testContextVariablesValidator() {
+
+ }
+
+ public void testExpressionLanguageValidator() {
+
+ }
+
+ private int getMarkersNumber(IFile file){
+ try{
+ IMarker[] markers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
+ return markers.length;
+
+ }catch(CoreException ex){
+ JUnitUtils.fail("Error in getting problem markers", ex);
}
+ return -1;
+ }
+
+ private String getMarkersMessage(IFile file){
+ String message="";
try{
- IMarker[] markers = componentsFile.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
+ IMarker[] markers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
+
for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.TEXT,
""));
+ System.out.println("Marker - "+markers[i].getAttribute(IMarker.MESSAGE,
""));
+ message = markers[i].getAttribute(IMarker.MESSAGE, "");
}
}catch(CoreException ex){
JUnitUtils.fail("Error in getting problem markers", ex);
}
-
+ return message;
}
+
+ private void refreshProject(IProject project){
+ long timestamp = project.getModificationStamp();
+ int count = 1;
+ while(true){
+ System.out.println("Refresh project "+count);
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ try {
+ waitForJob();
+ } catch (InterruptedException e) {
+ JUnitUtils.fail(e.getMessage(),e);
+ }
+ } catch (Exception e) {
+ JUnitUtils.fail("Cannot build test Project", e);
+ break;
+ }
+ if(project.getModificationStamp() != timestamp) break;
+ count++;
+ if(count > 1) break;
+ }
+ }
+
+ public static void waitForJob() throws InterruptedException {
+ Object[] o = {
+ XJob.FAMILY_XJOB, ResourcesPlugin.FAMILY_AUTO_REFRESH,
ResourcesPlugin.FAMILY_AUTO_BUILD
+ };
+ while(true) {
+ boolean stop = true;
+ for (int i = 0; i < o.length; i++) {
+ Job[] js = Job.getJobManager().find(o[i]);
+ if(js != null && js.length > 0) {
+ Job.getJobManager().join(o[i], new NullProgressMonitor());
+ stop = false;
+ }
+ }
+ if(stop) {
+ Job running = getJobRunning(10);
+ if(running != null) {
+ running.join();
+ stop = false;
+ }
+ }
+ if(stop) break;
+ }
+ }
+
+ public static Job getJobRunning(int iterationLimit) {
+ Job[] js = Job.getJobManager().find(null);
+ Job dm = null;
+ if(js != null) for (int i = 0; i < js.length; i++) {
+ if(js[i].getState() == Job.RUNNING && js[i].getThread() !=
Thread.currentThread()) {
+ if(js[i] instanceof UIJob) continue;
+ if(js[i].belongsTo(DecoratorManager.FAMILY_DECORATE) ||
js[i].getName().equals("Task List Saver")) {
+ dm = js[i];
+ continue;
+ }
+ //TODO keep watching
+ System.out.println(js[i].getName());
+ return js[i];
+ }
+ }
+ if(dm != null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ if(iterationLimit > 0)
+ return getJobRunning(iterationLimit - 1);
+ }
+ return null;
+
+ }
}