diff options
Diffstat (limited to 'jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java')
-rw-r--r-- | jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java | 230 |
1 files changed, 5 insertions, 225 deletions
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java index 992babe3d1..410620c763 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java @@ -19,7 +19,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -36,7 +35,6 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; @@ -107,6 +105,7 @@ public class JPACreateFactory { addPersistenceJarIntoProject(javaProject); int cnt = 0; JpaProject jpaProject = null; + Utils.printlnFormatted("========> Wait a project to appears in the Project Explorer view!"); while ((jpaProject == null) && (cnt < 1000)){ try { Thread.sleep(500); @@ -115,7 +114,10 @@ public class JPACreateFactory { } jpaProject = this.getJpaProject(project); cnt++; + Utils.printlnFormatted("---> Project appears in " + cnt + " seconds..."); } + Utils.printlnFormatted("========> Project appears in the Project Explorer view!"); + jpaProject.setDiscoversAnnotatedClasses(true); // jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject)); return jpaProject; @@ -192,7 +194,7 @@ public class JPACreateFactory { public IJavaProject createJavaProject(IProject project, boolean autoBuild) throws CoreException { facetedProject = createFacetedProject(project); - installFacet(facetedProject, "jst.java", "5.0"); + installFacet(facetedProject, "jst.java", "6.0"); javaProject = JavaCore.create(project); //sourceFolder = javaProject.getPackageFragmentRoot(project.getFolder("src")); return javaProject; @@ -621,226 +623,4 @@ public class JPACreateFactory { IFolder folder = project.getFolder(path); return createFieldAnnotatedEntity(folder, packageName , entityName); } - - /** - * Wait all build and refresh jobs to complete by joining them. - */ - public static void joinBuildAndRerfreshJobs() { - ArrayList<Job> jobs = new ArrayList<Job>(); - Job[] jobsArray; - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH); - jobs.addAll(Arrays.asList(jobsArray)); - Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish..."); - for (int i = 0; i < jobs.size(); i++) { - Job job = jobs.get(i); - int jobState = job.getState(); - if ((jobState == Job.RUNNING) || (jobState == Job.WAITING)) { - try { - job.join(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - /** - * Wait all build and refresh jobs to complete or until 30 seconds timeout - * pass. - */ - public static void waitBuildAndRerfreshJobs() { - Utils.printlnFormatted("Entered into joinBuildAndRerfreshJobs."); - ArrayList<Job> jobs = new ArrayList<Job>(); - Job[] jobsArray; - int timeout = SIDE_JOBS_COMPLETE_TIMEOUT; - - while (timeout > 0) { - jobs.clear(); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_BUILD); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_AUTO_REFRESH); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD); - jobs.addAll(Arrays.asList(jobsArray)); - jobsArray = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_REFRESH); - jobs.addAll(Arrays.asList(jobsArray)); - if (jobs.size() == 0) { - return; - } - Utils.printlnFormatted("Waiting for " + jobs.size() + " Jobs to finish..."); - for (Job job : jobsArray) { - Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job)); - } - timeout -= 1000; - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - - } - } - - private static String jobStateToString(Job job) { - int state = job.getState(); - switch (state) { - case Job.NONE: - return "NONE"; - case Job.RUNNING: - return "RUNNING"; - case Job.SLEEPING: - return "SLEEPING"; - case Job.WAITING: - return "SLEEPING"; - } - return "UNKNOWN"; - } - - - - /** - * Waits a certain time for any non system job to complete and if there is - * still jobs after the certain periord,<br/> - * removes all of them so the test will have a clean environment - * - * @return flag - * @throws InterruptedException - */ - public static boolean waitNonSystemJobs() throws InterruptedException { - Utils.printlnFormatted("Entered into waitNonSystemJobs."); - return waitNonSystemJobs(SIDE_JOBS_COMPLETE_TIMEOUT, true); - } - - /** - * Waits a certain time for any non system job to complete and if there is still jobs after the certain periord,<br/> - * removes all of them so the test will have a clean environment - * - * @param timeout - * time after which the jobs will be canceled. - * @return - * @throws InterruptedException - */ - public static boolean waitNonSystemJobs(int timeout) throws InterruptedException { - return waitNonSystemJobs(timeout, true); - } - - /** - * Waits a certain time for any non system job to complete and if there is - * still jobs after the certain periord,<br/> - * removes all of them so the test will have a clean environment - * - * @param timeout - * time after which the jobs will be canceled. - * @param cancelWaitForBrowser - * will cancel rightaway the wait for browser jobs - * @return - * @throws InterruptedException - */ - public static boolean waitNonSystemJobs(int timeout, boolean cancelWaitForBrowser) throws InterruptedException { - Job[] find = null; - int count = 0; - - while (timeout > 0) { - count = 0; - find = Job.getJobManager().find(null); - for (Job job : find) { - if (!job.isSystem()) { - count++; - if (!DUMPER_JOB_NAME.equals(job.getName())) { - Utils.printlnFormatted("Waiting for job: " + job.getName() + ", which is " + jobStateToString(job)); - } - } - } - if (DEBUG && (count == 1)) { - return true; - } else if (!DEBUG && (count == 0)) { - return true; - } - timeout -= 1000; - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - - } - Utils.println("Cancelling any running job..."); - - find = Job.getJobManager().find(null); - for (Job job : find) { - if (!job.isSystem() && !DUMPER_JOB_NAME.equals(job.getName())) { - printTrace(job); - cancelJob(job); - } - } - - find = Job.getJobManager().find(null); - count = 0; - for (Job job : find) { - if (!job.isSystem()) { - count++; - } - } - if (count == 0) { - Utils.printlnFormatted("All jobs removed"); - return true; - } - - Utils.printlnFormatted("There are still unremoved job. This may cause the test to block."); - return false; - } - - /** - * Cancels all running system jobs. - * - * @return true if no jobs are running at the end. - * @throws InterruptedException - */ - public static boolean cancelAllNonSystemJobs() throws InterruptedException { - waitNonSystemJobs(0); - return waitNonSystemJobs(); - } - - private static void printTrace(Job job) { - Thread thread = job.getThread(); - if (thread == null) { - Utils.println("Null Thread ...."); - return; - } - StackTraceElement[] stackTrace = thread.getStackTrace(); - if (stackTrace != null) { - for (StackTraceElement traceElement : stackTrace) { - if (traceElement != null) { - Utils.println("\tat " + traceElement.toString()); - } - } - } - } - - /** - * Will call cancel job and produce a log - * - * @param job - */ - private static void cancelJob(Job job) { - Utils.printlnFormatted("* [" + job.getName() + "]..."); - job.cancel(); - Utils.printlnFormatted("* [" + job.getName() + "]...cancelled."); - } - - - // used to decide whether to print Job Manager's state - private static boolean DEBUG = false; - - // seconds - private static final String DUMPER_JOB_NAME = "Dumper 1"; - - private static final int SIDE_JOBS_COMPLETE_TIMEOUT = 30 * 1000; // 30 - - } |